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 582B

12345678910111213141516171819202122232425
  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. )
  22. ).to eq(25.0)
  23. end
  24. end
  25. end