A fork of Crisp for HARP
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

45 行
1.2 KiB

9 年前
9 年前
9 年前
9 年前
9 年前
  1. require "../helper"
  2. describe "Crisp::Interpreter" do
  3. describe "#initialize" do
  4. it "takes arguments as string value" do
  5. i = Crisp::Interpreter.new %w(foo bar baz)
  6. result = i.eval_string("*ARGV*")
  7. result.should be_a(Crisp::Expr)
  8. unwrapped = result.unwrap
  9. unwrapped.should be_a(Crisp::List)
  10. if unwrapped.is_a? Crisp::List
  11. unwrapped.size.should eq(3)
  12. a0 = unwrapped[0].unwrap
  13. a1 = unwrapped[1].unwrap
  14. a2 = unwrapped[2].unwrap
  15. a0.should be_a(String)
  16. a1.should be_a(String)
  17. a2.should be_a(String)
  18. a0.should eq("foo")
  19. a1.should eq("bar")
  20. a2.should eq("baz")
  21. end
  22. end
  23. end
  24. describe "#eval_string" do
  25. it "evaluates string of Crisp expression" do
  26. i = Crisp::Interpreter.new
  27. result = i.eval_string "(+ 1 2)"
  28. result.should be_a(Crisp::Expr)
  29. unwrapped = result.unwrap
  30. unwrapped.should be_a(Int32)
  31. unwrapped.should eq(3)
  32. end
  33. end
  34. describe "#run" do
  35. it "raises eval error with file which doesn't exist" do
  36. i = Crisp::Interpreter.new
  37. expect_raises Crisp::EvalException do
  38. i.run "/non/existent/file"
  39. end
  40. end
  41. end
  42. end