@@ -95,10 +95,58 @@ def test_boolean_assignment_shorthand
95
95
assert_equal ( "true" , template . render ( "media_position" => 2 ) )
96
96
end
97
97
98
- def test_equality_operators
99
- assert_parity ( "1 == 1" , "true" )
100
- assert_parity ( "1 != 2" , "true" )
101
- assert_parity_todo! ( "'hello' == 'hello'" , "true" )
98
+ def test_equality_operators_with_integer_literals
99
+ assert_expression ( "1" , "1" )
100
+ assert_expression ( "1 == 1" , "true" )
101
+ assert_expression ( "1 != 1" , "false" )
102
+ assert_expression ( "1 == 2" , "false" )
103
+ assert_expression ( "1 != 2" , "true" )
104
+ end
105
+
106
+ def test_equality_operators_with_stirng_literals
107
+ assert_expression ( "'hello'" , "hello" )
108
+ assert_expression ( "'hello' == 'hello'" , "true" )
109
+ assert_expression ( "'hello' != 'hello'" , "false" )
110
+ assert_expression ( "'hello' == 'world'" , "false" )
111
+ assert_expression ( "'hello' != 'world'" , "true" )
112
+ end
113
+
114
+ def test_equality_operators_with_float_literals
115
+ assert_expression ( "1.5" , "1.5" )
116
+ assert_expression ( "1.5 == 1.5" , "true" )
117
+ assert_expression ( "1.5 != 1.5" , "false" )
118
+ assert_expression ( "1.5 == 2.5" , "false" )
119
+ assert_expression ( "1.5 != 2.5" , "true" )
120
+ end
121
+
122
+ def test_equality_operators_with_nil_literals
123
+ assert_expression ( "nil" , "" )
124
+ assert_expression ( "nil == nil" , "true" )
125
+ assert_expression ( "nil != nil" , "false" )
126
+ assert_expression ( "null == nil" , "true" )
127
+ assert_expression ( "null != nil" , "false" )
128
+ end
129
+
130
+ def test_equality_operators_with_boolean_literals
131
+ assert_expression ( "true" , "true" )
132
+ assert_expression ( "false" , "false" )
133
+ assert_expression ( "true == true" , "true" )
134
+ assert_expression ( "true != true" , "false" )
135
+ assert_expression ( "false == false" , "true" )
136
+ assert_expression ( "false != false" , "false" )
137
+ assert_expression ( "true == false" , "false" )
138
+ assert_expression ( "true != false" , "true" )
139
+ end
140
+
141
+ def test_equality_operators_with_empty_literals
142
+ assert_expression ( "empty" , "" )
143
+ assert_expression ( "empty == ''" , "true" )
144
+ assert_expression ( "empty == empty" , "true" )
145
+ assert_expression ( "empty != empty" , "false" )
146
+ assert_expression ( "blank == blank" , "true" )
147
+ assert_expression ( "blank != blank" , "false" )
148
+ assert_expression ( "empty == blank" , "true" )
149
+ assert_expression ( "empty != blank" , "false" )
102
150
end
103
151
104
152
def test_nil_renders_as_empty_string
@@ -122,18 +170,41 @@ def test_if_with_variables
122
170
end
123
171
124
172
def test_nil_variable_in_and_expression
125
- assert_parity ( "x and true" , "false" , { "x" => nil } )
126
- assert_parity ( "true and x" , "false" , { "x" => nil } )
173
+ assert_condition ( "x and true" , "false" , { "x" => nil } )
174
+ assert_condition ( "true and x" , "false" , { "x" => nil } )
175
+
176
+ assert_expression ( "x and true" , "" , { "x" => nil } )
177
+ assert_expression ( "true and x" , "" , { "x" => nil } )
127
178
end
128
179
129
180
def test_boolean_variable_in_and_expression
130
181
assert_parity ( "true and x" , "false" , { "x" => false } )
131
182
assert_parity ( "x and true" , "false" , { "x" => false } )
183
+
184
+ assert_parity ( "true and x" , "true" , { "x" => true } )
185
+ assert_parity ( "x and true" , "true" , { "x" => true } )
186
+
187
+ assert_parity ( "true or x" , "true" , { "x" => false } )
188
+ assert_parity ( "x or true" , "true" , { "x" => false } )
189
+
190
+ assert_parity ( "true or x" , "true" , { "x" => true } )
191
+ assert_parity ( "x or true" , "true" , { "x" => true } )
132
192
end
133
193
134
194
def test_multi_variable_boolean_nil_and_expression
135
- assert_parity ( "x and y" , "false" , { "x" => nil , "y" => true } )
136
- assert_parity ( "y and x" , "false" , { "x" => true , "y" => nil } )
195
+ assert_condition ( "x and y" , "false" , { "x" => nil , "y" => true } )
196
+ assert_condition ( "y and x" , "false" , { "x" => true , "y" => nil } )
197
+
198
+ assert_expression ( "x and y" , "" , { "x" => nil , "y" => true } )
199
+ assert_expression ( "y and x" , "" , { "x" => true , "y" => nil } )
200
+ end
201
+
202
+ def test_multi_truthy_variables_and_expressions
203
+ assert_condition ( "x or y" , "true" , { "x" => nil , "y" => "hello" } )
204
+ assert_condition ( "y or x" , "true" , { "x" => "hello" , "y" => nil } )
205
+
206
+ assert_expression ( "x or y" , "hello" , { "x" => nil , "y" => "hello" } )
207
+ assert_expression ( "y or x" , "hello" , { "x" => "hello" , "y" => nil } )
137
208
end
138
209
139
210
def test_multi_variable_boolean_nil_or_expression
0 commit comments