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.

variable_declaration_spec.rb 662B

123456789101112131415161718192021
  1. RSpec.describe AST::VariableDeclaration do
  2. it 'defines a variable' do
  3. env = Environment.new
  4. AST::VariableDeclaration.new(AST::Identifier.new('x'), AST::Number.new(5.0))
  5. .execute(env)
  6. expect(env.get('x').execute(env)).to eq(5.0)
  7. end
  8. it 'raises if a variable is already defined' do
  9. env = Environment.new
  10. AST::VariableDeclaration.new(AST::Identifier.new('x'), AST::Number.new(5.0))
  11. .execute(env)
  12. expect {
  13. AST::VariableDeclaration.new(
  14. AST::Identifier.new('x'),
  15. AST::Number.new(6.0)
  16. )
  17. .execute(env)
  18. }.to raise_error('Invalid declaration of previously declared variable x')
  19. end
  20. end