A toy dynamic programming language written in Ruby
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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