@@ -59,6 +59,17 @@ var filterTests = []struct {
5959 {`dup_ints | uniq | join` , "1 2 3" },
6060 {`dup_strings | uniq | join` , "one two three" },
6161 {`dup_maps | uniq | map: "name" | join` , "m1 m2 m3" },
62+ // where
63+ {`products | where: "available" | map: "title" | join: ", "` , "Shirt, Pants" },
64+ {`products | where: "type", "Shirt" | map: "title" | join: ", "` , "Shirt" },
65+ {`products | where: "price", 10.0 | map: "title" | join: ", "` , "Shirt" },
66+ {`products | where: "price", 10 | map: "title" | join: ", "` , "Shirt" },
67+ {`products | where: "price", nil | map: "title" | join: ", "` , "Hat" },
68+ // sum
69+ {`"1,2,3" | split: "," | sum` , 6.0 },
70+ {`prices | sum` , int64 (30 )},
71+ {`products | sum: "price"` , 30.0 },
72+
6273 {`mixed_case_array | sort_natural | join` , "a B c" },
6374 {`mixed_case_hash_values | sort_natural: 'key' | map: 'key' | join` , "a B c" },
6475
@@ -97,6 +108,22 @@ var filterTests = []struct {
97108 {`"Straße" | size` , 6 },
98109
99110 // string filters
111+ // pluralize
112+ {`1 | pluralize: "item", "items"` , "item" },
113+ {`2 | pluralize: "item", "items"` , "items" },
114+ {`0 | pluralize: "item", "items"` , "items" },
115+ {`1.0 | pluralize: "item", "items"` , "item" },
116+ {`1.5 | pluralize: "item", "items"` , "items" },
117+ {`"1" | pluralize: "item", "items"` , "item" },
118+ {`"2" | pluralize: "item", "items"` , "items" },
119+
120+ // handleize / handle
121+ {`"100% M & Ms!!!" | handleize` , "100-m-ms" },
122+ {`"Hello World" | handleize` , "hello-world" },
123+ {`"" | handleize` , "" },
124+ {`"---already---" | handleize` , "already" },
125+ {`"Hello World" | handle` , "hello-world" },
126+
100127 {`"Take my protein pills and put my helmet on" | replace: "my", "your"` , "Take your protein pills and put your helmet on" },
101128 {`"Take my protein pills and put my helmet on" | replace_first: "my", "your"` , "Take your protein pills and put my helmet on" },
102129 {`"/my/fancy/url" | append: ".html"` , "/my/fancy/url.html" },
@@ -112,6 +139,10 @@ var filterTests = []struct {
112139 {`"apples, oranges, and bananas" | prepend: "Some fruit: "` , "Some fruit: apples, oranges, and bananas" },
113140 {`"I strained to see the train through the rain" | remove: "rain"` , "I sted to see the t through the " },
114141 {`"I strained to see the train through the rain" | remove_first: "rain"` , "I sted to see the train through the rain" },
142+ {`"Hello Hello Hello" | remove_last: "Hello"` , "Hello Hello " },
143+ {`"Hello" | remove_last: "xyz"` , "Hello" },
144+ {`"Hello Hello Hello" | replace_last: "Hello", "Goodbye"` , "Hello Hello Goodbye" },
145+ {`"Hello" | replace_last: "xyz", "abc"` , "Hello" },
115146
116147 {`"Liquid" | slice: 0` , "L" },
117148 {`"Liquid
@@ -236,6 +267,12 @@ Liquid" | slice: 2, 4`, "quid"},
236267 {`str_int | plus: 1` , 11.0 },
237268 {`str_float | plus: 1.0` , 4.5 },
238269
270+ // at_least / at_most
271+ {`4 | at_least: 5` , int64 (5 )},
272+ {`6 | at_least: 5` , int64 (6 )},
273+ {`4 | at_most: 5` , int64 (4 )},
274+ {`6 | at_most: 5` , int64 (5 )},
275+
239276 {`3 | modulo: 2` , 1.0 },
240277 {`24 | modulo: 7` , 3.0 },
241278 // {`183.357 | modulo: 12 | `, 3.357}, // TODO test suit use inexact
@@ -290,6 +327,12 @@ var filterTestBindings = map[string]any{
290327 {"weight" : 3 },
291328 {"weight" : nil },
292329 },
330+ "products" : []map [string ]any {
331+ {"title" : "Shirt" , "type" : "Shirt" , "price" : 10.0 , "available" : true },
332+ {"title" : "Pants" , "type" : "Pants" , "price" : 20.0 , "available" : true },
333+ {"title" : "Hat" , "type" : "Hat" , "price" : nil , "available" : false },
334+ },
335+ "prices" : []any {10 , 20 },
293336 "string_with_newlines" : "\n Hello\n there\n " ,
294337 "dup_ints" : []int {1 , 2 , 1 , 3 },
295338 "dup_strings" : []string {"one" , "two" , "one" , "three" },
0 commit comments