Chervil is a toy Lisp interpreter 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.

definition_spec.rb 580B

1234567891011121314151617181920212223
  1. module Chervil
  2. RSpec.describe AST::Definition do
  3. it 'evaluates' do
  4. env = Env.new
  5. AST::Definition.new(
  6. AST::Identifier.new("x"),
  7. AST::Number.new(5.0)
  8. ).evaluate(env)
  9. expect(env.get("x")).to eq(AST::Number.new(5.0))
  10. end
  11. it 'throws an error if bound to an unbound variable' do
  12. env = Env.new
  13. result = AST::Definition.new(
  14. AST::Identifier.new("x"),
  15. AST::Identifier.new("y"),
  16. ).evaluate(env)
  17. expect(result).to eq(
  18. ::Chervil::Error.new("unbound variable y")
  19. )
  20. end
  21. end
  22. end