Skip to content
Browse files

More closure specs.

  • Loading branch information...
1 parent 822f1df commit 337d31bf9a9fe8b07f3654f5bf6095613c73b329 @brixen committed Nov 20, 2010
Showing with 65 additions and 6 deletions.
  1. +3 −4 lib/poison/bootstrap/syntax/closure.rb
  2. +62 −2 spec/compiler/closure_spec.rb
View
7 lib/poison/bootstrap/syntax/closure.rb
@@ -9,10 +9,9 @@ def initialize(table, statements)
end
def to_sexp
- body = [@table ? @table.to_sexp : nil]
- body.concat @statements.map { |s| s.to_sexp }
-
- [:closure, body]
+ [:closure,
+ table ? @table.to_sexp : nil
+ ].concat @statements.map { |s| s.to_sexp }
end
end
end
View
64 spec/compiler/closure_spec.rb
@@ -3,13 +3,73 @@
describe "The Closure node" do
relates ": ." do
parse do
- [:expr, [:closure, [nil, [nil, nil, nil]]]]
+ [:expr, [:closure, nil, [nil, nil, nil]]]
end
end
relates ": 1." do
parse do
- [:expr, [:closure, [nil, [:expr, [:value, [1, nil, nil]]]]]]
+ [:expr, [:closure, nil, [:expr, [:value, [1, nil, nil]]]]]
+ end
+ end
+
+ relates ": (a) ." do
+ parse do
+ [:expr, [:closure,
+ [:table, [:expr, [:message, ["a", nil, nil]]]],
+ [nil, nil, nil]]]
+ end
+ end
+
+ relates ": (a) 1." do
+ parse do
+ [:expr, [:closure,
+ [:table, [:expr, [:message, ["a", nil, nil]]]],
+ [:expr, [:value, [1, nil, nil]]]]]
+ end
+ end
+
+ relates ": (a, b) ." do
+ parse do
+ [:expr, [:closure,
+ [:table,
+ [:expr, [:message, ["a", nil, nil]]],
+ [:expr, [:message, ["b", nil, nil]]]],
+ [nil, nil, nil]]]
+ end
+ end
+
+ relates ": (a, b) 1." do
+ parse do
+ [:expr, [:closure,
+ [:table,
+ [:expr, [:message, ["a", nil, nil]]],
+ [:expr, [:message, ["b", nil, nil]]]],
+ [:expr, [:value, [1, nil, nil]]]]]
+ end
+ end
+
+ relates ": (a, b) 1, 2." do
+ parse do
+ [:expr, [:closure,
+ [:table,
+ [:expr, [:message, ["a", nil, nil]]],
+ [:expr, [:message, ["b", nil, nil]]]],
+ [:expr, [:value, [1, nil, nil]]],
+ [:expr, [:value, [2, nil, nil]]]]]
+ end
+ end
+
+ relates ": (a, b) (1, 2)." do
+ parse do
+ [:expr, [:closure,
+ [:table,
+ [:expr, [:message, ["a", nil, nil]]],
+ [:expr, [:message, ["b", nil, nil]]]],
+ [:expr,
+ [:table,
+ [:expr, [:value, [1, nil, nil]]],
+ [:expr, [:value, [2, nil, nil]]]]]]]
end
end
end

0 comments on commit 337d31b

Please sign in to comment.
Something went wrong with that request. Please try again.