1234567891011121314151617181920212223 |
- module Chervil
- RSpec.describe AST::Definition do
- it 'evaluates' do
- env = Env.new
- AST::Definition.new(
- AST::Identifier.new("x"),
- AST::Number.new(5.0)
- ).evaluate(env)
- expect(env.get("x")).to eq(AST::Number.new(5.0))
- end
-
- it 'throws an error if bound to an unbound variable' do
- env = Env.new
- result = AST::Definition.new(
- AST::Identifier.new("x"),
- AST::Identifier.new("y"),
- ).evaluate(env)
- expect(result).to eq(
- ::Chervil::Error.new("unbound variable y")
- )
- end
- end
- end
|