A toy dynamic programming language written in Ruby
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

assignment_spec.rb 625B

12345678910111213141516171819202122232425
  1. RSpec.describe AST::Assignment do
  2. it 'reassigns an existing variable' do
  3. env = Environment.new
  4. AST::VariableDeclaration.new(
  5. AST::Identifier.new('x'),
  6. AST::Number.new(5.0),
  7. ).execute(env)
  8. AST::Assignment.new(
  9. AST::Identifier.new('x'),
  10. AST::Number.new(6.0),
  11. ).execute(env)
  12. expect(env.get('x').execute(env)).to eq(6.0)
  13. end
  14. it 'raises for an undeclared variable' do
  15. env = Environment.new
  16. expect {
  17. AST::Assignment.new(
  18. AST::Identifier.new('x'),
  19. AST::Number.new(6.0),
  20. ).execute(env)
  21. }.to raise_error("Undefined variable x")
  22. end
  23. end