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.

application_spec.rb 832B

12345678910111213141516171819202122232425262728293031323334
  1. module Chervil
  2. RSpec.describe AST::Definition do
  3. it 'evaluates addition' do
  4. env = Env.new
  5. expect(
  6. AST::Application.new(
  7. AST::Identifier.new('+'),
  8. [AST::Number.new(1.0), AST::Number.new(2.0)]
  9. )
  10. .evaluate(env)
  11. ).to eq(3.0)
  12. end
  13. it 'evaluates nested arithmetic' do
  14. env = Env.new
  15. expect(
  16. AST::Application.new(
  17. AST::Identifier.new('+'),
  18. [
  19. AST::Application.new(
  20. AST::Identifier.new('+'),
  21. [AST::Number.new(1.0), AST::Number.new(2.0)]
  22. ),
  23. AST::Application.new(
  24. AST::Identifier.new('+'),
  25. [AST::Number.new(3.0), AST::Number.new(4.0)]
  26. )
  27. ]
  28. )
  29. .evaluate(env)
  30. ).to eq(10.0)
  31. end
  32. end
  33. end