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.

function_spec.rb 601B

1234567891011121314151617181920212223242526
  1. module Chervil
  2. RSpec.describe AST::Definition do
  3. it 'evaluates its body with its arguments when called' do
  4. expect(
  5. AST::Function.new(
  6. AST::Identifier.new("square"),
  7. [
  8. AST::Identifier.new("x")
  9. ],
  10. [
  11. AST::Application.new(
  12. AST::Identifier.new("*"),
  13. [
  14. AST::Identifier.new("x"),
  15. AST::Identifier.new("x")
  16. ]
  17. )
  18. ],
  19. ).call(
  20. [AST::Number.new(5.0)],
  21. Env.new
  22. )
  23. ).to eq(25.0)
  24. end
  25. end
  26. end