wrong 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/README.markdown +114 -25
  2. data/lib/predicated/Gemfile +15 -0
  3. data/lib/predicated/LICENSE +20 -0
  4. data/lib/predicated/README.markdown +191 -0
  5. data/lib/predicated/Rakefile +51 -0
  6. data/lib/predicated/lib/predicated.rb +4 -0
  7. data/lib/predicated/lib/predicated/autogen_call.rb +37 -0
  8. data/lib/predicated/lib/predicated/constrain.rb +66 -0
  9. data/lib/predicated/lib/predicated/evaluate.rb +94 -0
  10. data/lib/predicated/lib/predicated/from/callable_object.rb +108 -0
  11. data/lib/predicated/lib/predicated/from/json.rb +59 -0
  12. data/lib/predicated/lib/predicated/from/ruby_code_string.rb +73 -0
  13. data/lib/predicated/lib/predicated/from/url_part.rb +104 -0
  14. data/lib/predicated/lib/predicated/from/xml.rb +61 -0
  15. data/lib/predicated/lib/predicated/gem_check.rb +34 -0
  16. data/lib/predicated/lib/predicated/predicate.rb +111 -0
  17. data/lib/predicated/lib/predicated/print.rb +62 -0
  18. data/lib/predicated/lib/predicated/selectable.rb +102 -0
  19. data/lib/predicated/lib/predicated/simple_templated_predicate.rb +79 -0
  20. data/lib/predicated/lib/predicated/string_utils.rb +20 -0
  21. data/lib/predicated/lib/predicated/to/arel.rb +41 -0
  22. data/lib/predicated/lib/predicated/to/json.rb +48 -0
  23. data/lib/predicated/lib/predicated/to/sentence.rb +94 -0
  24. data/lib/predicated/lib/predicated/to/solr.rb +15 -0
  25. data/lib/predicated/lib/predicated/to/xml.rb +67 -0
  26. data/lib/predicated/lib/predicated/version.rb +3 -0
  27. data/lib/predicated/predicated.gemspec +22 -0
  28. data/lib/predicated/test/autogen_call_test.rb +40 -0
  29. data/lib/predicated/test/canonical_transform_cases.rb +63 -0
  30. data/lib/predicated/test/constrain_test.rb +86 -0
  31. data/lib/predicated/test/enumerable_test.rb +32 -0
  32. data/lib/predicated/test/equality_test.rb +32 -0
  33. data/lib/predicated/test/evaluate_test.rb +149 -0
  34. data/lib/predicated/test/from/callable_object_canonical_test.rb +43 -0
  35. data/lib/predicated/test/from/callable_object_test.rb +78 -0
  36. data/lib/predicated/test/from/json_test.rb +83 -0
  37. data/lib/predicated/test/from/ruby_code_string_canonical_test.rb +37 -0
  38. data/lib/predicated/test/from/ruby_code_string_test.rb +103 -0
  39. data/lib/predicated/test/from/url_part_parser_test.rb +123 -0
  40. data/lib/predicated/test/from/url_part_test.rb +48 -0
  41. data/lib/predicated/test/from/xml_test.rb +57 -0
  42. data/lib/predicated/test/json_conversion_test.rb +33 -0
  43. data/lib/predicated/test/print_test.rb +66 -0
  44. data/lib/predicated/test/selectable_test.rb +123 -0
  45. data/lib/predicated/test/simple_templated_predicate_test.rb +39 -0
  46. data/lib/predicated/test/suite.rb +2 -0
  47. data/lib/predicated/test/test_helper.rb +64 -0
  48. data/lib/predicated/test/test_helper_with_wrong.rb +6 -0
  49. data/lib/predicated/test/to/arel_test.rb +85 -0
  50. data/lib/predicated/test/to/json_test.rb +74 -0
  51. data/lib/predicated/test/to/sentence_test.rb +90 -0
  52. data/lib/predicated/test/to/solr_test.rb +39 -0
  53. data/lib/predicated/test/to/xml_test.rb +72 -0
  54. data/lib/predicated/test/xml_conversion_test.rb +34 -0
  55. data/lib/predicated/test_integration/arel_integration_test.rb +52 -0
  56. data/lib/predicated/test_integration/canonical_integration_cases.rb +66 -0
  57. data/lib/predicated/test_integration/schema.xml +83 -0
  58. data/lib/predicated/test_integration/solr_integration_test.rb +71 -0
  59. data/lib/predicated/test_integration/sqlite_db +0 -0
  60. data/lib/predicated/test_integration/suite.rb +2 -0
  61. data/lib/predicated/test_integration/usage_test.rb +252 -0
  62. data/lib/wrong.rb +3 -1
  63. data/lib/wrong/adapters/test_unit.rb +1 -3
  64. data/lib/wrong/assert.rb +81 -24
  65. data/lib/wrong/chunk.rb +145 -0
  66. data/lib/wrong/message/string_diff.rb +2 -4
  67. data/lib/wrong/message/test_context.rb +2 -2
  68. data/lib/wrong/version.rb +2 -2
  69. data/test/adapters/minitest_test.rb +16 -9
  70. data/test/adapters/test_unit_test.rb +1 -1
  71. data/test/assert_test.rb +90 -0
  72. data/test/catch_raise_test.rb +2 -2
  73. data/test/chunk_test.rb +236 -0
  74. data/test/failures_test.rb +109 -74
  75. data/test/message/array_diff_test.rb +35 -19
  76. data/test/message/string_diff_test.rb +39 -15
  77. data/test/message/test_context_text.rb +2 -2
  78. data/test/test_helper.rb +25 -7
  79. metadata +86 -33
  80. data/test/basic_assert_test.rb +0 -38
@@ -0,0 +1,37 @@
1
+ require "./test/test_helper_with_wrong"
2
+ require "./test/canonical_transform_cases"
3
+
4
+ require "predicated/from/ruby_code_string"
5
+ include Predicated
6
+
7
+ regarding "ruby code string - canoical transform cases" do
8
+ include CanonicalTransformCases
9
+
10
+ @expectations = {
11
+ "simple operations" => {
12
+ "eq" => Predicate.from_ruby_code_string("'a'==3"),
13
+ "gt" => Predicate.from_ruby_code_string("'a'>3"),
14
+ "lt" => Predicate.from_ruby_code_string("'a'<3"),
15
+ "gte" => Predicate.from_ruby_code_string("'a'>=3"),
16
+ "lte" => Predicate.from_ruby_code_string("'a'<=3")
17
+ },
18
+ "primitive types" => {
19
+ "false" => Predicate.from_ruby_code_string("'a'==false"),
20
+ "true" => Predicate.from_ruby_code_string("'a'==true"),
21
+ "string" => Predicate.from_ruby_code_string("'a'=='yyy'"),
22
+ },
23
+ "not" => {
24
+ "simple" => Predicate.from_ruby_code_string("!('a'==true)")
25
+ },
26
+ "simple and / or" => {
27
+ #parens are necessary around AND's in solr in order to force precedence
28
+ "and" => Predicate.from_ruby_code_string("'a'==1 && 'b'==2"),
29
+ "or" => Predicate.from_ruby_code_string("'a'==1 || 'b'==2")
30
+ },
31
+ "complex and / or" => {
32
+ "or and" => Predicate.from_ruby_code_string("'a'==1 && 'b'==2 || 'c'==3")
33
+ }
34
+ }
35
+
36
+ create_canonical_tests(@expectations)
37
+ end
@@ -0,0 +1,103 @@
1
+ require "./test/test_helper"
2
+
3
+ require "predicated/from/ruby_code_string"
4
+ include Predicated
5
+
6
+ regarding "parse a ruby predicate string" do
7
+
8
+ regarding "basic operations" do
9
+
10
+ #'Wrong'-style asserts are specifically avoided here.
11
+ #the circularity between the two projects will make you crazy if you're not careful
12
+
13
+ test "word and" do
14
+ assert_equal Predicate.from_ruby_code_string("1==1 and 2==2"), Predicate{ And(Eq(1,1),Eq(2,2)) }
15
+ end
16
+
17
+ test "substitute in from the binding" do
18
+ a = 1
19
+ b = "1"
20
+ c = "c"
21
+ d = Color.new("purple")
22
+
23
+ assert_equal Predicate.from_ruby_code_string("a==1", binding()), Predicate{ Eq(1,1) }
24
+ assert_equal Predicate.from_ruby_code_string("b==1", binding()), Predicate{ Eq("1",1) }
25
+ assert_equal Predicate.from_ruby_code_string("c==b", binding()), Predicate{ Eq("c","1") }
26
+ assert_equal Predicate.from_ruby_code_string("d==d", binding()), Predicate{ Eq(Color.new("purple"),
27
+ Color.new("purple")) }
28
+ assert_equal Predicate.from_ruby_code_string("d==d", binding()).left, d
29
+
30
+ assert_equal Predicate.from_ruby_code_string("a==b && b==c", binding()),
31
+ Predicate{ And(Eq(1,"1"),Eq("1","c")) }
32
+ end
33
+
34
+
35
+ test "parens change precedence" do
36
+ assert_equal Predicate.from_ruby_code_string("1==1 || 2==2 && 3==3"),
37
+ Predicate{ Or( Eq(1,1), And(Eq(2,2),Eq(3,3)) ) }
38
+
39
+ assert_equal Predicate.from_ruby_code_string("(1==1 || 2==2) && 3==3"),
40
+ Predicate{ And( Or(Eq(1,1),Eq(2,2)), Eq(3,3) ) }
41
+ end
42
+
43
+ regarding "only pay attention to the final line" do
44
+ #might hate myself one day for this. but what else does it make sense to do?
45
+
46
+ test "simple" do
47
+ assert_equal Predicate.from_ruby_code_string("z=2\nb=5\n1==1"), Predicate{ Eq(1,1) }
48
+ end
49
+
50
+ test "can make use of variables defined earlier in the block" do
51
+ #might hate myself one day for this. but what else does it make sense to do?
52
+ assert_equal Predicate.from_ruby_code_string("z=2\nb=5\nz==1"), Predicate{ Eq(2,1) }
53
+ end
54
+ end
55
+
56
+ test "a call that returns a boolean result" do
57
+ assert_equal Predicate.from_ruby_code_string("'abc'.include?('bc')"),
58
+ Predicate{ Call("abc", :include?, "bc") }
59
+
60
+ color = Color.new("purple")
61
+ assert_equal Predicate.from_ruby_code_string("color.name.include?('rp')", binding()),
62
+ Predicate{ Call("purple", :include?, "rp") }
63
+
64
+ assert_equal Predicate.from_ruby_code_string("'abc'.nil?"),
65
+ Predicate{ Call("abc", :nil?, nil) }
66
+ end
67
+
68
+ test "use of instance variables" do
69
+ @a = 1
70
+
71
+ assert_equal Predicate.from_ruby_code_string("@a==1", binding()), Predicate{ Eq(1,1) }
72
+ end
73
+
74
+ test "use of inline assignments" do
75
+ assert_equal Predicate.from_ruby_code_string("(a=2)==1 && a==1"),
76
+ Predicate{ And(Eq(2,1), Eq(2,1)) }
77
+ end
78
+
79
+ test "use of inline expressions" do
80
+ assert_equal Predicate.from_ruby_code_string("(2*1)==1"),
81
+ Predicate{ Eq(2,1) }
82
+
83
+ assert_equal Predicate.from_ruby_code_string("[2,1].first==1"),
84
+ Predicate{ Eq(2,1) }
85
+ end
86
+
87
+
88
+ end
89
+
90
+ regarding "errors" do
91
+ test "can't parse" do
92
+ assert_raises(Racc::ParseError) do
93
+ Predicate.from_ruby_code_string("bad ruby @@@@@****()(((")
94
+ end
95
+ end
96
+
97
+ test "predicates only" do
98
+ assert_raises(Predicated::Predicate::DontKnowWhatToDoWithThisSexpError) do
99
+ Predicate.from_ruby_code_string("a=1")
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,123 @@
1
+ require "./test/test_helper_with_wrong"
2
+
3
+ require "predicated/predicate"
4
+ require "predicated/from/url_part"
5
+ include Predicated
6
+
7
+ regarding "parse a url part, the result is a parse tree" do
8
+
9
+ before do
10
+ @parser = TreetopUrlPartParser.new
11
+ end
12
+
13
+ regarding "simple operations" do
14
+
15
+ test "parse" do
16
+ tree = @parser.parse("a=1")
17
+
18
+ assert{ tree.is_a?(Predicated::TreetopUrlPart::OperationNode) }
19
+ assert{ [tree.left_text, tree.sign_text, tree.right_text] == ["a", "=", "1"] }
20
+
21
+ tree = @parser.parse("a>1")
22
+ assert{ [tree.left_text, tree.sign_text, tree.right_text] == ["a", ">", "1"] }
23
+
24
+ tree = @parser.parse("a<1")
25
+ assert{ [tree.left_text, tree.sign_text, tree.right_text] == ["a", "<", "1"] }
26
+
27
+ tree = @parser.parse("a>=1")
28
+ assert{ [tree.left_text, tree.sign_text, tree.right_text] == ["a", ">=", "1"] }
29
+
30
+ tree = @parser.parse("a<=1")
31
+ assert{ [tree.left_text, tree.sign_text, tree.right_text] == ["a", "<=", "1"] }
32
+ end
33
+
34
+ test "...to predicate" do
35
+ assert{ @parser.parse("a=1").to_predicate == Predicate{Eq("a", "1")} }
36
+ assert{ @parser.parse("a>1").to_predicate == Predicate{Gt("a", "1")} }
37
+ assert{ @parser.parse("a<1").to_predicate == Predicate{Lt("a", "1")} }
38
+ assert{ @parser.parse("a>=1").to_predicate == Predicate{Gte("a", "1")} }
39
+ assert{ @parser.parse("a<=1").to_predicate == Predicate{Lte("a", "1")} }
40
+ end
41
+
42
+ end
43
+
44
+ regarding "simple and" do
45
+ test "parse" do
46
+ tree = @parser.parse("a=1&b=2")
47
+
48
+ assert{ tree.is_a?(Predicated::TreetopUrlPart::AndNode) }
49
+ assert{ [[tree.left.left_text, tree.left.sign_text, tree.left.right_text],
50
+ [tree.right.left_text, tree.right.sign_text, tree.right.right_text]] ==
51
+ [["a", "=", "1"], ["b", "=", "2"]] }
52
+ end
53
+
54
+ test "...to predicate" do
55
+ assert{ @parser.parse("a=1&b=2").to_predicate == Predicate{ And( Eq("a", "1"),Eq("b", "2") ) } }
56
+ end
57
+ end
58
+
59
+ regarding "simple or" do
60
+ test "parse" do
61
+ tree = @parser.parse("a=1|b=2")
62
+
63
+ assert{ tree.is_a?(Predicated::TreetopUrlPart::OrNode) }
64
+ assert{ [[tree.left.left_text, tree.left.sign_text, tree.left.right_text],
65
+ [tree.right.left_text, tree.right.sign_text, tree.right.right_text]] ==
66
+ [["a", "=", "1"], ["b", "=", "2"]] }
67
+ end
68
+
69
+ test "...to predicate" do
70
+ assert{ @parser.parse("a=1|b=2").to_predicate == Predicate{ Or( Eq("a", "1"),Eq("b", "2") ) } }
71
+ end
72
+ end
73
+
74
+ regarding "complex and/or" do
75
+ test "many or's" do
76
+ assert{ @parser.parse("a=1|b=2|c=3").to_predicate ==
77
+ Predicate{ Or( Eq("a", "1"), Or(Eq("b", "2"),Eq("c", "3")) ) } }
78
+ end
79
+
80
+ test "many and's" do
81
+ assert{ @parser.parse("a=1&b=2&c=3").to_predicate ==
82
+ Predicate{ And( Eq("a", "1"), And(Eq("b", "2"),Eq("c", "3")) ) } }
83
+ end
84
+
85
+ test "mixed and/or" do
86
+ assert{ @parser.parse("a=1|b=2&c=3").to_predicate ==
87
+ Predicate{ Or( Eq("a", "1"), And(Eq("b", "2"),Eq("c", "3")) ) } }
88
+
89
+ assert{ @parser.parse("a=1&b=2|c=3").to_predicate ==
90
+ Predicate{ Or( And(Eq("a", "1"),Eq("b", "2")), Eq("c", "3") ) } }
91
+ end
92
+ end
93
+
94
+ regarding "parens (force higher precedence)" do
95
+ test "no effect" do
96
+ str = "(a=1|b=2)|c=3"
97
+ assert{ @parser.parse(str).to_predicate ==
98
+ Predicate{ Or( Or(Eq("a", "1"),Eq("b", "2")), Eq("c", "3") ) } }
99
+
100
+ str = "((a=1|b=2))|c=3"
101
+ assert{ @parser.parse(str).to_predicate ==
102
+ Predicate{ Or( Or(Eq("a", "1"),Eq("b", "2")), Eq("c", "3") ) } }
103
+ end
104
+
105
+ test "force precedence" do
106
+ #before
107
+ assert{ @parser.parse("a=1|b=2&c=3").to_predicate ==
108
+ Predicate{ Or( Eq("a", "1"), And(Eq("b", "2"),Eq("c", "3")) ) } }
109
+
110
+ #after
111
+ assert{ @parser.parse("(a=1|b=2)&c=3").to_predicate ==
112
+ Predicate{ And( Or(Eq("a", "1"),Eq("b", "2")), Eq("c", "3") ) } }
113
+ end
114
+ end
115
+
116
+ regarding "not" do
117
+ test "force precedence" do
118
+ assert{ @parser.parse("!(a=1)").to_predicate ==
119
+ Predicate{ Not(Eq("a", "1")) } }
120
+ end
121
+ end
122
+
123
+ end
@@ -0,0 +1,48 @@
1
+ require "./test/test_helper_with_wrong"
2
+
3
+ require "predicated/from/url_part"
4
+ require "./test/canonical_transform_cases"
5
+ include Predicated
6
+
7
+ regarding "parse url parts and convert them into predicates" do
8
+ include CanonicalTransformCases
9
+
10
+ @expectations = {
11
+ "simple operations" => {
12
+ "eq" => Predicate.from_url_part("a=3"),
13
+ "gt" => Predicate.from_url_part("a>3"),
14
+ "lt" => Predicate.from_url_part("a<3"),
15
+ "gte" => Predicate.from_url_part("a>=3"),
16
+ "lte" => Predicate.from_url_part("a<=3")
17
+ },
18
+ "primitive types" => {
19
+ "false" => Predicate.from_url_part("a=false"),
20
+ "true" => Predicate.from_url_part("a=true"),
21
+ "string" => Predicate.from_url_part("a=yyy"),
22
+ },
23
+ "not" => {
24
+ "simple" => Predicate.from_url_part("!(a=true)")
25
+ },
26
+ "simple and / or" => {
27
+ #parens are necessary around AND's in solr in order to force precedence
28
+ "and" => Predicate.from_url_part("a=1&b=2"),
29
+ "or" => Predicate.from_url_part("a=1|b=2")
30
+ },
31
+ "complex and / or" => {
32
+ "or and" => Predicate.from_url_part("a=1&b=2|c=3")
33
+ }
34
+ }
35
+
36
+ create_canonical_tests(@expectations, proper_typing=false)
37
+
38
+
39
+
40
+ test "parens change precedence" do
41
+ assert { Predicate.from_url_part("a=1|b=2&c=3") ==
42
+ Predicate{ Or( Eq("a","1"), And(Eq("b","2"),Eq("c","3")) ) } }
43
+
44
+ assert { Predicate.from_url_part("(a=1|b=2)&c=3") ==
45
+ Predicate{ And( Or(Eq("a","1"),Eq("b","2")), Eq("c","3") ) } }
46
+ end
47
+
48
+ end
@@ -0,0 +1,57 @@
1
+ require "./test/test_helper_with_wrong"
2
+ require "./test/canonical_transform_cases"
3
+
4
+ require "predicated/from/xml"
5
+ include Predicated
6
+
7
+ regarding "convert an xml string to a predicate" do
8
+ include CanonicalTransformCases
9
+
10
+ @expectations = {
11
+ "simple operations" => {
12
+ "eq" => Predicate.from_xml("<equal><left>a</left><right>3</right></equal>"),
13
+ "gt" => Predicate.from_xml("<greaterThan><left>a</left><right>3</right></greaterThan>"),
14
+ "lt" => Predicate.from_xml("<lessThan><left>a</left><right>3</right></lessThan>"),
15
+ "gte" =>
16
+ Predicate.from_xml("<greaterThanOrEqualTo><left>a</left><right>3</right></greaterThanOrEqualTo>"),
17
+ "lte" =>
18
+ Predicate.from_xml("<lessThanOrEqualTo><left>a</left><right>3</right></lessThanOrEqualTo>")
19
+ },
20
+ "primitive types" => {
21
+ "false" => Predicate.from_xml("<equal><left>a</left><right>false</right></equal>"),
22
+ "true" => Predicate.from_xml("<equal><left>a</left><right>true</right></equal>"),
23
+ "string" => Predicate.from_xml("<equal><left>a</left><right>yyy</right></equal>"),
24
+ },
25
+ "not" => {
26
+ "simple" => Predicate.from_xml("<not><equal><left>a</left><right>true</right></equal></not>")
27
+ },
28
+ "simple and / or" => {
29
+ #parens are necessary around AND's in solr in order to force precedence
30
+ "and" => Predicate.from_xml(%{
31
+ <and>
32
+ <equal><left>a</left><right>1</right></equal>
33
+ <equal><left>b</left><right>2</right></equal>
34
+ </and>
35
+ }),
36
+ "or" => Predicate.from_xml(%{
37
+ <or>
38
+ <equal><left>a</left><right>1</right></equal>
39
+ <equal><left>b</left><right>2</right></equal>
40
+ </or>
41
+ })
42
+ },
43
+ "complex and / or" => {
44
+ "or and" => Predicate.from_xml(%{
45
+ <or>
46
+ <and>
47
+ <equal><left>a</left><right>1</right></equal>
48
+ <equal><left>b</left><right>2</right></equal>
49
+ </and>
50
+ <equal><left>c</left><right>3</right></equal>
51
+ </or>
52
+ })
53
+ }
54
+ }
55
+
56
+ create_canonical_tests(@expectations, proper_typing=false)
57
+ end
@@ -0,0 +1,33 @@
1
+ require "./test/test_helper_with_wrong"
2
+
3
+ require "predicated/from/json"
4
+ require "predicated/to/json"
5
+ include Predicated
6
+
7
+ regarding "convert json back and forth" do
8
+
9
+ test "string to predicate to string" do
10
+ assert{ Predicate.from_json_str(%{["a","==",3]}).to_json_str ==
11
+ JSON.pretty_generate(JSON.parse(%{["a","==",3]})) }
12
+
13
+ complex_json_str = %{
14
+ {
15
+ "or":[
16
+ {"and":[["a","==",1],["b","==",2]]},
17
+ ["c","==",3]
18
+ ]
19
+ }
20
+ }
21
+
22
+ assert{ Predicate.from_json_str(complex_json_str).to_json_str ==
23
+ JSON.pretty_generate(JSON.parse(complex_json_str)) }
24
+ end
25
+
26
+ test "predicate to string to predicate" do
27
+ assert{ Predicate.from_json_str(Predicate{ Eq("a",3) }.to_json_str) == Predicate{ Eq("a",3) } }
28
+
29
+ assert{ Predicate.from_json_str(Predicate{ Or(And(Eq("a",1),Eq("b",2)), Eq("c",3)) }.to_json_str) ==
30
+ Predicate{ Or(And(Eq("a",1),Eq("b",2)), Eq("c",3)) } }
31
+ end
32
+
33
+ end
@@ -0,0 +1,66 @@
1
+ require "./test/test_helper_with_wrong"
2
+
3
+ require "predicated/predicate"
4
+ include Predicated
5
+
6
+ regarding "a predicate looks nice with you to_s it" do
7
+ test "numbers" do
8
+ assert { Predicate { Eq(1, 1) }.to_s == "Eq(1,1)" }
9
+ assert { Predicate { Lt(1, 2) }.to_s == "Lt(1,2)" }
10
+ end
11
+
12
+ test "booleans" do
13
+ assert { Predicate { Eq(false, true) }.to_s == "Eq(false,true)" }
14
+ end
15
+
16
+ test "strings" do
17
+ assert { Predicate { Eq("foo", "bar") }.to_s == "Eq('foo','bar')" }
18
+ end
19
+
20
+ test "nil" do
21
+ assert { Predicate { Eq("foo", nil) }.to_s == "Eq('foo',nil)" }
22
+ end
23
+
24
+ test "objects" do
25
+ assert {
26
+ Predicate {
27
+ Eq(Color.new("red"), Color.new("blue"))
28
+ }.to_s == "Eq(Color{'name:red'},Color{'name:blue'})"
29
+ }
30
+ end
31
+
32
+ test "and, or" do
33
+ assert { Predicate { And(true, false) }.to_s == "And(true,false)" }
34
+ assert { Predicate { Or(true, false) }.to_s == "Or(true,false)" }
35
+
36
+ assert { Predicate { And(Eq(1, 1) , Eq(2, 2)) }.to_s == "And(Eq(1,1),Eq(2,2))" }
37
+
38
+ assert { Predicate { And(Eq(1, 1), Or(Eq(2, 2), Eq(3, 3))) }.to_s == "And(Eq(1,1),Or(Eq(2,2),Eq(3,3)))" }
39
+ end
40
+
41
+ test "not" do
42
+ assert { Predicate { Not(Eq(1, 1)) }.to_s == "Not(Eq(1,1))" }
43
+ end
44
+
45
+ end
46
+
47
+ regarding "inspect is like to_s except it's multiline, so you see the tree structure" do
48
+
49
+ test "an uncomplicated predicate prints on one line" do
50
+ assert { Predicate { Eq(1, 1) }.inspect == "Eq(1,1)" }
51
+ end
52
+
53
+ test "complex" do
54
+ assert {
55
+ Predicate { And(Eq(1, 1), Or(Eq(2, 2), Eq(3, 3))) }.inspect ==
56
+ %{And(
57
+ Eq(1,1),
58
+ Or(
59
+ Eq(2,2),
60
+ Eq(3,3)
61
+ )
62
+ )
63
+ }
64
+ }
65
+ end
66
+ end