Test array filters added in Shopify/Liquid v5.7.2 #6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds test cases for the following filters as they appear in version 5.7.2 of Shopify/Liquid.
Note that these filters do not currently support arguments for testing/selecting child properties at arbitrary depths.
See Shopify/liquid#1906 and harttle/liquidjs#799
Some observations that hold true for all array filters (as of v5.7.2).
Optional argument
The second argument,
target_value
, is optional and it does not need to be a string, contrary to what the doc comments say.Explicit nil
Explicitly testing for null/nil/None is not supported. Shopify/Liquid does not distinguish between the default value of
nil
and an explicit nil/null. For example, all templates are equivalent.Left values
Inputs are intended/assumed to be arrays of objects/hashes. If the input is an object/hash or primitive value (int, float, string, bool), it gets coerced to a single element array with the input value being the only item. With context data
Both of these templates are equivalent.
Arrays of strings
In Ruby, subscripting a string with another will return a substring if the first string contains the second. This leads to the following two templates resulting in
true
. There's at least one test case covering this behaviour in Shopify/Liquid, so this is known.And some odd results when filtering arrays of string values.
Early termination
If the input array contains a nil/null/None before a successful match, the result is nil/null/None. This example renders nothing when
a
is equal to["x", nil, "z"]
.Note that the
where
filter prior to version 5.7 behaved the same way.Problematic integers
An exception is raised if the input array contains an integer and
target_value
is a string. And testing an input array of integers against an integer gives some as yet unexplained results.