predicated 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +183 -1
- data/lib/predicated.rb +1 -3
- data/lib/predicated/constrain.rb +2 -0
- data/lib/predicated/evaluate.rb +25 -6
- data/lib/predicated/from/callable_object.rb +7 -8
- data/lib/predicated/from/json.rb +59 -0
- data/lib/predicated/from/{ruby_string.rb → ruby_code_string.rb} +13 -5
- data/lib/predicated/from/{url_fragment.rb → url_part.rb} +17 -10
- data/lib/predicated/from/xml.rb +61 -0
- data/lib/predicated/predicate.rb +62 -43
- data/lib/predicated/print.rb +28 -16
- data/lib/predicated/selectable.rb +102 -0
- data/lib/predicated/simple_templated_predicate.rb +79 -0
- data/lib/predicated/string_utils.rb +20 -0
- data/lib/predicated/to/arel.rb +28 -22
- data/lib/predicated/to/json.rb +48 -0
- data/lib/predicated/to/sentence.rb +17 -14
- data/lib/predicated/to/solr.rb +15 -0
- data/lib/predicated/to/xml.rb +67 -0
- data/lib/predicated/version.rb +2 -2
- data/test/canonical_transform_cases.rb +67 -0
- data/test/constrain_test.rb +20 -11
- data/test/enumerable_test.rb +6 -34
- data/test/equality_test.rb +15 -4
- data/test/evaluate_test.rb +31 -26
- data/test/from/callable_object_canonical_test.rb +43 -0
- data/test/from/callable_object_test.rb +16 -40
- data/test/from/json_test.rb +83 -0
- data/test/from/ruby_code_string_canonical_test.rb +37 -0
- data/test/from/ruby_code_string_test.rb +103 -0
- data/test/from/{url_fragment_parser_test.rb → url_part_parser_test.rb} +20 -13
- data/test/from/url_part_test.rb +48 -0
- data/test/from/xml_test.rb +57 -0
- data/test/json_conversion_test.rb +33 -0
- data/test/print_test.rb +26 -25
- data/test/selectable_test.rb +123 -0
- data/test/simple_templated_predicate_test.rb +39 -0
- data/test/suite.rb +2 -4
- data/test/test_helper.rb +26 -4
- data/test/test_helper_with_wrong.rb +3 -2
- data/test/to/arel_test.rb +71 -31
- data/test/to/json_test.rb +74 -0
- data/test/to/sentence_test.rb +41 -34
- data/test/to/solr_test.rb +39 -0
- data/test/to/xml_test.rb +72 -0
- data/test/xml_conversion_test.rb +34 -0
- metadata +44 -16
- data/lib/predicated/selector.rb +0 -55
- data/test/from/ruby_string_test.rb +0 -135
- data/test/from/url_fragment_test.rb +0 -37
- data/test/selector_test.rb +0 -82
data/test/suite.rb
CHANGED
@@ -1,4 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
puts "suite " + (result ? "passed" : "FAILED")
|
4
|
-
exit(result ? 0 : 1)
|
1
|
+
require "./test/test_helper"
|
2
|
+
run_suite("test/**/*_test.rb")
|
data/test/test_helper.rb
CHANGED
@@ -8,6 +8,28 @@ require "pp"
|
|
8
8
|
#DO NOT REQUIRE WRONG IN HERE
|
9
9
|
#The circularity between projects will cause certain tests to not work.
|
10
10
|
|
11
|
+
class Color
|
12
|
+
attr_reader :name
|
13
|
+
def initialize(name)
|
14
|
+
@name = name
|
15
|
+
end
|
16
|
+
|
17
|
+
def ==(other)
|
18
|
+
other.is_a?(Color) && @name == other.name
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
"name:#{@name}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def run_suite(wildcard)
|
27
|
+
#simple way to make sure requires are isolated
|
28
|
+
result = Dir[wildcard].collect{|test_file| system("ruby #{test_file}") }.uniq == [true]
|
29
|
+
puts "suite " + (result ? "passed" : "FAILED")
|
30
|
+
exit(result ? 0 : 1)
|
31
|
+
end
|
32
|
+
|
11
33
|
class MiniTest::Unit::TestCase
|
12
34
|
|
13
35
|
def assert_raise(exception_info_regex)
|
@@ -21,10 +43,10 @@ class MiniTest::Unit::TestCase
|
|
21
43
|
end
|
22
44
|
|
23
45
|
module Kernel
|
24
|
-
alias_method :
|
46
|
+
alias_method :regarding, :describe
|
25
47
|
|
26
|
-
def
|
27
|
-
puts "x'd out '
|
48
|
+
def xregarding(str)
|
49
|
+
puts "x'd out 'regarding \"#{str}\"'"
|
28
50
|
end
|
29
51
|
end
|
30
52
|
|
@@ -39,4 +61,4 @@ class MiniTest::Spec
|
|
39
61
|
end
|
40
62
|
end
|
41
63
|
|
42
|
-
MiniTest::Unit.autorun
|
64
|
+
MiniTest::Unit.autorun
|
data/test/to/arel_test.rb
CHANGED
@@ -1,43 +1,83 @@
|
|
1
|
-
require "test/test_helper_with_wrong"
|
1
|
+
require "./test/test_helper_with_wrong"
|
2
|
+
require "./test/canonical_transform_cases"
|
2
3
|
|
3
4
|
unless RUBY_VERSION=="1.8.6"
|
4
5
|
|
5
6
|
require "predicated/to/arel"
|
6
7
|
include Predicated
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
regarding "convert a predicate to an arel where clause" do
|
10
|
+
include CanonicalTransformCases
|
11
|
+
|
12
|
+
class FakeEngine
|
13
|
+
def connection
|
14
|
+
end
|
15
|
+
|
16
|
+
def table_exists?(name)
|
17
|
+
true
|
18
|
+
end
|
16
19
|
end
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
Arel::Predicates::Equality.new("b", 2)
|
29
|
-
) }
|
20
|
+
|
21
|
+
class FakeColumn
|
22
|
+
attr_reader :name, :type
|
23
|
+
def initialize(name, type)
|
24
|
+
@name = name
|
25
|
+
@type = type
|
26
|
+
end
|
27
|
+
|
28
|
+
def type_cast(value)
|
29
|
+
value
|
30
|
+
end
|
30
31
|
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
33
|
+
@table = Arel::Table.new(:widget, :engine => FakeEngine.new)
|
34
|
+
Arel::Table.tables = [@table]
|
35
|
+
@table.instance_variable_set("@columns".to_sym, [
|
36
|
+
FakeColumn.new("a", :integer),
|
37
|
+
FakeColumn.new("b", :integer),
|
38
|
+
FakeColumn.new("c", :integer)
|
39
|
+
])
|
40
|
+
|
41
|
+
|
42
|
+
@to_expectations = {
|
43
|
+
"simple operations" => {
|
44
|
+
"eq" => Arel::Predicates::Equality.new(@table.attributes["a"], 3),
|
45
|
+
"gt" => Arel::Predicates::GreaterThan.new(@table.attributes["a"], 3),
|
46
|
+
"lt" => Arel::Predicates::LessThan.new(@table.attributes["a"], 3),
|
47
|
+
"gte" => Arel::Predicates::GreaterThanOrEqualTo.new(@table.attributes["a"], 3),
|
48
|
+
"lte" => Arel::Predicates::LessThanOrEqualTo.new(@table.attributes["a"], 3)
|
49
|
+
},
|
50
|
+
"primitive types" => {
|
51
|
+
"false" => Arel::Predicates::Equality.new(@table.attributes["a"], false),
|
52
|
+
"true" => Arel::Predicates::Equality.new(@table.attributes["a"], true),
|
53
|
+
"string" => Arel::Predicates::Equality.new(@table.attributes["a"], "yyy")
|
54
|
+
},
|
55
|
+
"not" => {
|
56
|
+
"simple" => Arel::Predicates::Not.new(Arel::Predicates::Equality.new(@table.attributes["a"], true))
|
57
|
+
},
|
58
|
+
"simple and / or" => {
|
59
|
+
"and" => Arel::Predicates::And.new(
|
60
|
+
Arel::Predicates::Equality.new(@table.attributes["a"], 1),
|
61
|
+
Arel::Predicates::Equality.new(@table.attributes["b"], 2)
|
62
|
+
),
|
63
|
+
"or" => Arel::Predicates::Or.new(
|
64
|
+
Arel::Predicates::Equality.new(@table.attributes["a"], 1),
|
65
|
+
Arel::Predicates::Equality.new(@table.attributes["b"], 2)
|
66
|
+
)
|
67
|
+
},
|
68
|
+
"complex and / or" => {
|
69
|
+
"or and" => Arel::Predicates::Or.new(
|
70
|
+
Arel::Predicates::And.new(
|
71
|
+
Arel::Predicates::Equality.new(@table.attributes["a"], 1),
|
72
|
+
Arel::Predicates::Equality.new(@table.attributes["b"], 2)
|
73
|
+
),
|
74
|
+
Arel::Predicates::Equality.new(@table.attributes["c"], 3)
|
75
|
+
)
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
create_canonical_tests(@to_expectations) do |predicate|
|
80
|
+
predicate.to_arel(@table)
|
41
81
|
end
|
42
82
|
|
43
83
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require "./test/test_helper_with_wrong"
|
2
|
+
require "./test/canonical_transform_cases"
|
3
|
+
|
4
|
+
require "predicated/to/json"
|
5
|
+
include Predicated
|
6
|
+
|
7
|
+
regarding "convert a predicate to a json structure" do
|
8
|
+
include CanonicalTransformCases
|
9
|
+
|
10
|
+
@to_expectations = {
|
11
|
+
"simple operations" => {
|
12
|
+
"eq" => ["a", "==", 3],
|
13
|
+
"gt" => ["a", ">", 3],
|
14
|
+
"lt" => ["a", "<", 3],
|
15
|
+
"gte" => ["a", ">=", 3],
|
16
|
+
"lte" => ["a", "<=", 3]
|
17
|
+
},
|
18
|
+
"primitive types" => {
|
19
|
+
"false" => ["a", "==", false],
|
20
|
+
"true" => ["a", "==", true],
|
21
|
+
"string" => ["a", "==", "yyy"]
|
22
|
+
},
|
23
|
+
"not" => {
|
24
|
+
"simple" => {"not" => ["a", "==", true]}
|
25
|
+
},
|
26
|
+
"simple and / or" => {
|
27
|
+
"and" => {"and" => [["a", "==", 1], ["b", "==", 2]] },
|
28
|
+
"or" => {"or" => [["a", "==", 1], ["b", "==", 2]] }
|
29
|
+
},
|
30
|
+
"complex and / or" => {
|
31
|
+
"or and" => {"or" => [
|
32
|
+
{"and" => [["a", "==", 1], ["b", "==", 2]]},
|
33
|
+
["c", "==", 3]
|
34
|
+
]}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
create_canonical_tests(@to_expectations) do |predicate|
|
39
|
+
predicate.to_json_struct
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
regarding "convert a predicate to a json string" do
|
44
|
+
include CanonicalTransformCases
|
45
|
+
|
46
|
+
@to_expectations = {
|
47
|
+
"simple operations" => {
|
48
|
+
"eq" => %{["a","==",3]},
|
49
|
+
"gt" => %{["a",">",3]},
|
50
|
+
"lt" => %{["a","<",3]},
|
51
|
+
"gte" => %{["a",">=",3]},
|
52
|
+
"lte" => %{["a","<=",3]}
|
53
|
+
},
|
54
|
+
"primitive types" => {
|
55
|
+
"false" => %{["a","==",false]},
|
56
|
+
"true" => %{["a","==",true]},
|
57
|
+
"string" => %{["a","==","yyy"]}
|
58
|
+
},
|
59
|
+
"not" => {
|
60
|
+
"simple" => %{{"not":["a","==",true]}}
|
61
|
+
},
|
62
|
+
"simple and / or" => {
|
63
|
+
"and" => %{{"and":[["a","==",1],["b","==",2]]}},
|
64
|
+
"or" => %{{"or":[["a","==",1],["b","==",2]]}}
|
65
|
+
},
|
66
|
+
"complex and / or" => {
|
67
|
+
"or and" => %{{"or":[{"and":[["a","==",1],["b","==",2]]},["c","==",3]]}}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
create_canonical_tests(@to_expectations) do |predicate|
|
72
|
+
predicate.to_json_str.gsub("\n", "").gsub(" ", "")
|
73
|
+
end
|
74
|
+
end
|
data/test/to/sentence_test.rb
CHANGED
@@ -1,83 +1,90 @@
|
|
1
|
-
require "test/test_helper_with_wrong"
|
1
|
+
require "./test/test_helper_with_wrong"
|
2
2
|
|
3
3
|
require "predicated/to/sentence"
|
4
4
|
include Predicated
|
5
5
|
|
6
|
-
|
6
|
+
regarding "convert a predicate to an english sentence" do
|
7
7
|
|
8
8
|
after do
|
9
9
|
Operation.reset_verb_phrases
|
10
10
|
end
|
11
11
|
|
12
12
|
test "operations" do
|
13
|
-
assert { Predicate{ Eq("a",1) }.to_sentence == "
|
14
|
-
assert { Predicate{ Gt("a",1) }.to_sentence == "
|
15
|
-
assert { Predicate{ Lt("a",1) }.to_sentence == "
|
16
|
-
assert { Predicate{ Gte("a",1) }.to_sentence == "
|
17
|
-
assert { Predicate{ Lte("a",1) }.to_sentence == "
|
13
|
+
assert { Predicate{ Eq("a",1) }.to_sentence == '"a" is equal to 1' }
|
14
|
+
assert { Predicate{ Gt("a",1) }.to_sentence == '"a" is greater than 1' }
|
15
|
+
assert { Predicate{ Lt("a",1) }.to_sentence == '"a" is less than 1' }
|
16
|
+
assert { Predicate{ Gte("a",1) }.to_sentence == '"a" is greater than or equal to 1' }
|
17
|
+
assert { Predicate{ Lte("a",1) }.to_sentence == '"a" is less than or equal to 1' }
|
18
18
|
|
19
|
-
assert { Predicate{ Eq("a",1) }.to_negative_sentence == "
|
20
|
-
assert { Predicate{ Gt("a",1) }.to_negative_sentence == "
|
21
|
-
assert { Predicate{ Lt("a",1) }.to_negative_sentence == "
|
22
|
-
assert { Predicate{ Gte("a",1) }.to_negative_sentence == "
|
23
|
-
assert { Predicate{ Lte("a",1) } .to_negative_sentence == "
|
19
|
+
assert { Predicate{ Eq("a",1) }.to_negative_sentence == '"a" is not equal to 1' }
|
20
|
+
assert { Predicate{ Gt("a",1) }.to_negative_sentence == '"a" is not greater than 1' }
|
21
|
+
assert { Predicate{ Lt("a",1) }.to_negative_sentence == '"a" is not less than 1' }
|
22
|
+
assert { Predicate{ Gte("a",1) }.to_negative_sentence == '"a" is not greater than or equal to 1' }
|
23
|
+
assert { Predicate{ Lte("a",1) } .to_negative_sentence == '"a" is not less than or equal to 1' }
|
24
24
|
end
|
25
25
|
|
26
26
|
test "primitive types" do
|
27
|
-
assert { Predicate{ Eq("a",1) }.to_sentence == "
|
28
|
-
assert { Predicate{ Eq("a",nil) }.to_sentence == "
|
29
|
-
assert { Predicate{ Eq("a",true) }.to_sentence == "
|
27
|
+
assert { Predicate{ Eq("a",1) }.to_sentence == '"a" is equal to 1' }
|
28
|
+
assert { Predicate{ Eq("a",nil) }.to_sentence == '"a" is equal to nil' }
|
29
|
+
assert { Predicate{ Eq("a",true) }.to_sentence == '"a" is equal to true' }
|
30
|
+
assert { Predicate{ Eq("a",3.14) }.to_sentence == '"a" is equal to 3.14' }
|
31
|
+
end
|
32
|
+
|
33
|
+
test "not" do
|
34
|
+
assert { Predicate{ Not(Eq("a",1)) }.to_sentence == '"a" is not equal to 1' }
|
35
|
+
assert { Predicate{ Not(Eq("a",1)) }.to_negative_sentence == '"a" is equal to 1' }
|
30
36
|
end
|
31
37
|
|
32
38
|
test "complex types" do
|
33
|
-
assert { Predicate{ Eq([1,2],{3=>4}) }.to_sentence == "
|
39
|
+
assert { Predicate{ Eq([1,2],{3=>4}) }.to_sentence == "[1, 2] is equal to {3=>4}" }
|
34
40
|
end
|
35
41
|
|
36
42
|
test "default verb phrases for unknown methods (which are awkward/ESL-ish)" do
|
37
43
|
assert { Predicate{ Call("abc", :exclude?, "bc") }.to_sentence ==
|
38
|
-
"
|
44
|
+
'"abc" is exclude "bc"' }
|
39
45
|
|
40
46
|
assert { Predicate{ Call("abc", :exclude?, "bc") }.to_negative_sentence ==
|
41
|
-
"
|
47
|
+
'"abc" is not exclude "bc"' }
|
42
48
|
|
43
49
|
assert { Predicate{ Call("abc", :friends_with?, "bc") }.to_sentence ==
|
44
|
-
"
|
50
|
+
'"abc" is friends with "bc"' }
|
45
51
|
end
|
46
52
|
|
47
53
|
test "register methods and their verb phrases" do
|
48
|
-
Operation.register_verb_phrase(:exclude?, "
|
54
|
+
Operation.register_verb_phrase(:exclude?, "excludes", "does not exclude")
|
49
55
|
assert { Predicate{ Call("abc", :exclude?, "bc") }.to_sentence ==
|
50
|
-
"
|
56
|
+
'"abc" excludes "bc"' }
|
51
57
|
|
52
58
|
assert { Predicate{ Call("abc", :exclude?, "bc") }.to_negative_sentence ==
|
53
|
-
"
|
59
|
+
'"abc" does not exclude "bc"' }
|
54
60
|
end
|
55
61
|
|
56
62
|
test "some other common methods have sensible verb phrases by default" do
|
57
|
-
assert { Predicate{ Call("abc", :include?, 'bc') }.to_sentence == "
|
58
|
-
assert { Predicate{ Call("abc", :include?, 'bc') }.to_negative_sentence == "
|
59
|
-
|
60
|
-
|
61
|
-
assert {
|
63
|
+
assert { Predicate{ Call("abc", :include?, 'bc') }.to_sentence == '"abc" includes "bc"' }
|
64
|
+
assert { Predicate{ Call("abc", :include?, 'bc') }.to_negative_sentence == '"abc" does not include "bc"' }
|
65
|
+
|
66
|
+
s = Predicate{ Call("abc", :is_a?, String) }.to_sentence
|
67
|
+
assert { s == '"abc" is a String' }
|
68
|
+
assert { Predicate{ Call("abc", :is_a?, String) }.to_negative_sentence == '"abc" is not a String' }
|
62
69
|
end
|
63
70
|
|
64
71
|
test "nothing on the far side" do
|
65
|
-
assert { Predicate{ Call("abc", :nil?) }.to_sentence == "
|
66
|
-
assert { Predicate{ Call("abc", :nil?) }.to_negative_sentence == "
|
72
|
+
assert { Predicate{ Call("abc", :nil?) }.to_sentence == '"abc" is nil' }
|
73
|
+
assert { Predicate{ Call("abc", :nil?) }.to_negative_sentence == '"abc" is not nil' }
|
67
74
|
end
|
68
75
|
|
69
76
|
test "simple and + or" do
|
70
77
|
assert { Predicate{ And(Eq("a", 1),Eq("b", 2)) }.to_sentence ==
|
71
|
-
"
|
78
|
+
'"a" is equal to 1 and "b" is equal to 2' }
|
72
79
|
|
73
80
|
assert { Predicate{ Or(Eq("a", 1),Eq("b", 2)) }.to_sentence ==
|
74
|
-
"
|
81
|
+
'"a" is equal to 1 or "b" is equal to 2' }
|
75
82
|
|
76
83
|
assert { Predicate{ And(Eq("a", 1),Eq("b", 2)) }.to_negative_sentence ==
|
77
|
-
|
84
|
+
'This is not true: "a" is equal to 1 and "b" is equal to 2' }
|
78
85
|
|
79
86
|
assert { Predicate{ Or(Eq("a", 1),Eq("b", 2)) }.to_negative_sentence ==
|
80
|
-
|
87
|
+
'This is not true: "a" is equal to 1 or "b" is equal to 2' }
|
81
88
|
end
|
82
89
|
|
83
|
-
end
|
90
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "./test/test_helper_with_wrong"
|
2
|
+
require "./test/canonical_transform_cases"
|
3
|
+
|
4
|
+
require "predicated/to/solr"
|
5
|
+
include Predicated
|
6
|
+
|
7
|
+
regarding "convert a predicate to a solr query" do
|
8
|
+
include CanonicalTransformCases
|
9
|
+
|
10
|
+
@to_expectations = {
|
11
|
+
"simple operations" => {
|
12
|
+
"eq" => "a:3",
|
13
|
+
"gt" => "a:[4 TO *]",
|
14
|
+
"lt" => "a:[* TO 2]",
|
15
|
+
"gte" => "a:[3 TO *]",
|
16
|
+
"lte" => "a:[* TO 3]"
|
17
|
+
},
|
18
|
+
"primitive types" => {
|
19
|
+
"false" => "a:false",
|
20
|
+
"true" => "a:true",
|
21
|
+
"string" => "a:yyy"
|
22
|
+
},
|
23
|
+
"not" => {
|
24
|
+
"simple" => "NOT(a:true)"
|
25
|
+
},
|
26
|
+
"simple and / or" => {
|
27
|
+
"and" => "(a:1 AND b:2)", #parens are necessary around AND's in solr in order to force precedence
|
28
|
+
"or" => "(a:1 OR b:2)",
|
29
|
+
},
|
30
|
+
"complex and / or" => {
|
31
|
+
"or and" => "((a:1 AND b:2) OR c:3)"
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
create_canonical_tests(@to_expectations) do |predicate|
|
36
|
+
predicate.to_solr
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
data/test/to/xml_test.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require "./test/test_helper_with_wrong"
|
2
|
+
require "./test/canonical_transform_cases"
|
3
|
+
|
4
|
+
require "predicated/to/xml"
|
5
|
+
include Predicated
|
6
|
+
|
7
|
+
regarding "convert a predicate to an xml string" do
|
8
|
+
include CanonicalTransformCases
|
9
|
+
|
10
|
+
@to_expectations = {
|
11
|
+
"simple operations" => {
|
12
|
+
"eq" => "<equal><left>a</left><right>3</right></equal>",
|
13
|
+
"gt" => "<greaterThan><left>a</left><right>3</right></greaterThan>",
|
14
|
+
"lt" => "<lessThan><left>a</left><right>3</right></lessThan>",
|
15
|
+
"gte" => "<greaterThanOrEqualTo><left>a</left><right>3</right></greaterThanOrEqualTo>",
|
16
|
+
"lte" => "<lessThanOrEqualTo><left>a</left><right>3</right></lessThanOrEqualTo>"
|
17
|
+
},
|
18
|
+
"primitive types" => {
|
19
|
+
"false" => "<equal><left>a</left><right>false</right></equal>",
|
20
|
+
"true" => "<equal><left>a</left><right>true</right></equal>",
|
21
|
+
"string" => "<equal><left>a</left><right>yyy</right></equal>"
|
22
|
+
},
|
23
|
+
"not" => {
|
24
|
+
"simple" => "<not><equal><left>a</left><right>true</right></equal></not>"
|
25
|
+
},
|
26
|
+
"simple and / or" => {
|
27
|
+
"and" => %{<and>
|
28
|
+
<equal><left>a</left><right>1</right></equal>
|
29
|
+
<equal><left>b</left><right>2</right></equal>
|
30
|
+
</and>}.gsub("\n", "").gsub(" ", ""),
|
31
|
+
"or" => %{<or>
|
32
|
+
<equal><left>a</left><right>1</right></equal>
|
33
|
+
<equal><left>b</left><right>2</right></equal>
|
34
|
+
</or>}.gsub("\n", "").gsub(" ", "")
|
35
|
+
},
|
36
|
+
"complex and / or" => {
|
37
|
+
"or and" => %{<or>
|
38
|
+
<and>
|
39
|
+
<equal><left>a</left><right>1</right></equal>
|
40
|
+
<equal><left>b</left><right>2</right></equal>
|
41
|
+
</and>
|
42
|
+
<equal><left>c</left><right>3</right></equal>
|
43
|
+
</or>}.gsub("\n", "").gsub(" ", "")
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
create_canonical_tests(@to_expectations) do |predicate|
|
48
|
+
predicate.to_xml.gsub("\n", "").gsub(" ", "")
|
49
|
+
end
|
50
|
+
|
51
|
+
test "pretty printing" do
|
52
|
+
assert{
|
53
|
+
Predicate{ Or(And(Eq("a", 1),Eq("b", 2)), Not(Eq("c",3))) }.to_xml ==
|
54
|
+
%{<or>
|
55
|
+
<and>
|
56
|
+
<equal><left>a</left><right>1</right></equal>
|
57
|
+
<equal><left>b</left><right>2</right></equal>
|
58
|
+
</and>
|
59
|
+
<not>
|
60
|
+
<equal><left>c</left><right>3</right></equal>
|
61
|
+
</not>
|
62
|
+
</or>}
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
test "characters that need to be encoded" do
|
67
|
+
assert{
|
68
|
+
Predicate{ Eq(%{'"&<>}, %{'"&<>}) }.to_xml ==
|
69
|
+
%{<equal><left>'"&<></left><right>'"&<></right></equal>}
|
70
|
+
}
|
71
|
+
end
|
72
|
+
end
|