@@ -161,6 +161,14 @@ def test_find_on_empty_array
161
161
assert_nil ( @filters . find ( [ ] , 'foo' , 'bar' ) )
162
162
end
163
163
164
+ def test_find_index_on_empty_array
165
+ assert_nil ( @filters . find_index ( [ ] , 'foo' , 'bar' ) )
166
+ end
167
+
168
+ def test_has_on_empty_array
169
+ refute ( @filters . has ( [ ] , 'foo' , 'bar' ) )
170
+ end
171
+
164
172
def test_truncate
165
173
assert_equal ( '1234...' , @filters . truncate ( '1234567890' , 7 ) )
166
174
assert_equal ( '1234567890' , @filters . truncate ( '1234567890' , 20 ) )
@@ -980,6 +988,18 @@ def test_has_when_does_not_have_it
980
988
assert_template_result ( expected_output , "{{ array | has: 'ok', true }}" , { "array" => array } )
981
989
end
982
990
991
+ def test_has_with_empty_arrays
992
+ template = <<~LIQUID
993
+ {%- assign has_product = products | has: 'title.content', 'Not found' -%}
994
+ {%- unless has_product -%}
995
+ Product not found.
996
+ {%- endunless -%}
997
+ LIQUID
998
+ expected_output = "Product not found."
999
+
1000
+ assert_template_result ( expected_output , template , { "products" => [ ] } )
1001
+ end
1002
+
983
1003
def test_has_with_false_value
984
1004
array = [
985
1005
{ "handle" => "alpha" , "ok" => true } ,
@@ -1086,6 +1106,18 @@ def test_find_index_with_deep_enumerables
1086
1106
assert_template_result ( expected_output , template , { "products" => TestDeepEnumerable . new } )
1087
1107
end
1088
1108
1109
+ def test_find_index_with_empty_arrays
1110
+ template = <<~LIQUID
1111
+ {%- assign index = products | find_index: 'title.content', 'Not found' -%}
1112
+ {%- unless index -%}
1113
+ Index not found.
1114
+ {%- endunless -%}
1115
+ LIQUID
1116
+ expected_output = "Index not found."
1117
+
1118
+ assert_template_result ( expected_output , template , { "products" => [ ] } )
1119
+ end
1120
+
1089
1121
def test_where
1090
1122
array = [
1091
1123
{ "handle" => "alpha" , "ok" => true } ,
0 commit comments