Chervil is a toy Lisp interpreter written in Ruby
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

application_spec.rb 833B

12345678910111213141516171819202122232425262728293031323334
  1. module Chervil
  2. RSpec.describe AST::Application 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