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 589B

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