123456789101112131415161718192021 |
- RSpec.describe AST::VariableDeclaration do
- it 'defines a variable' do
- env = Environment.new
- AST::VariableDeclaration.new(AST::Identifier.new('x'), AST::Number.new(5.0))
- .execute(env)
- expect(env.get('x').execute(env)).to eq(5.0)
- end
-
- it 'raises if a variable is already defined' do
- env = Environment.new
- AST::VariableDeclaration.new(AST::Identifier.new('x'), AST::Number.new(5.0))
- .execute(env)
- expect {
- AST::VariableDeclaration.new(
- AST::Identifier.new('x'),
- AST::Number.new(6.0)
- )
- .execute(env)
- }.to raise_error('Invalid declaration of previously declared variable x')
- end
- end
|