@@ -7,10 +7,11 @@ plan tests => repeat_each() * (3 * blocks());
77
88my $ pwd = cwd();
99
10- our $ HttpConfig = qq {
10+ our $ HttpConfig = qq |
1111 lua_package_path "$pwd/lib/?.lua;;;";
1212 lua_package_cpath "/usr/local/openresty/lualib/?.so;;";
13- } ;
13+ init_by_lua_block { Liquid = require 'liquid' }
14+ | ;
1415
1516
1617no_long_string();
@@ -264,3 +265,170 @@ GET /t
264265--- no_error_log
265266[error]
266267
268+
269+
270+ === TEST 11: 'join' filter works on strings
271+ --- http_config eval: $::HttpConfig
272+ --- config
273+ location /t {
274+ content_by_lua_block {
275+ ngx. say ( Liquid. Template: parse([[
276+ {{- str | join : ' - ' -}}
277+ ]]): render(Liquid. InterpreterContext: new({ str = " string" })) )
278+ }
279+ }
280+ --- request
281+ GET /t
282+ --- response_body
283+ string
284+ --- no_error_log
285+ [error]
286+
287+ === TEST 12: 'first' filter works strings
288+ --- http_config eval: $::HttpConfig
289+ --- config
290+ location /t {
291+ content_by_lua_block {
292+ ngx. say ( Liquid. Template: parse([[
293+ {{- str | first -}}
294+ ]]): render(Liquid. InterpreterContext: new({ str = " string" })) )
295+ }
296+ }
297+ --- request
298+ GET /t
299+ --- response_body
300+ string
301+ --- no_error_log
302+ [error]
303+
304+
305+
306+ === TEST 13: 'last' filter works on strings
307+ --- http_config eval: $::HttpConfig
308+ --- config
309+ location /t {
310+ content_by_lua_block {
311+ ngx. say ( Liquid. Template: parse([[
312+ {{- str | last -}}
313+ ]]): render( Liquid. InterpreterContext: new({ str = " string" })) )
314+ }
315+ }
316+ --- request
317+ GET /t
318+ --- response_body
319+ string
320+ --- no_error_log
321+ [error]
322+
323+ === TEST 14: 'concat' filter works on strings
324+ --- http_config eval: $::HttpConfig
325+ --- config
326+ location /t {
327+ content_by_lua_block {
328+ ngx. say ( Liquid. Template: parse([[
329+ {% - assign a = " string" | concat: (1 .. 3 ) -% }
330+ {% - assign b = " string" | concat: " another" -% }
331+ {% - for k in a % } {{k}} {% - endfor -% }
332+ {% - for k in b % } {{k}} {% - endfor -% }
333+ ]]): render())
334+ }
335+ }
336+ --- request
337+ GET /t
338+ --- response_body
339+ string 1 2 3 string another
340+ --- no_error_log
341+ [error]
342+
343+ === TEST 5: 'index' filter works on strings
344+ --- http_config eval: $::HttpConfig
345+ --- config
346+ location /t {
347+ content_by_lua_block {
348+ ngx. say ( Liquid. Template: parse([[
349+ {{- " string" | index : 0 -}}
350+ ]]): render() )
351+ }
352+ }
353+ --- request
354+ GET /t
355+ --- response_body
356+ string
357+ --- no_error_log
358+ [error]
359+
360+
361+ === TEST 16: 'reverse' filter works on strings
362+ --- http_config eval: $::HttpConfig
363+ --- config
364+ location /t {
365+ content_by_lua_block {
366+ ngx. say ( Liquid. Template: parse([[
367+ {{- " string" | reverse | join -}}
368+ ]]): render() )
369+ }
370+ }
371+ --- request
372+ GET /t
373+ --- response_body
374+ string
375+ --- no_error_log
376+ [error]
377+
378+
379+
380+ === TEST 17: 'size' filter works on strings
381+ --- http_config eval: $::HttpConfig
382+ --- config
383+ location /t {
384+ content_by_lua_block {
385+ ngx. say ( Liquid. Template: parse([[
386+ {{- " string" | size -}}
387+ ]]): render() )
388+ }
389+ }
390+ --- request
391+ GET /t
392+ --- response_body
393+ 1
394+ --- no_error_log
395+ [error]
396+
397+
398+
399+ === TEST 18: 'sort' filter works on strings
400+ --- http_config eval: $::HttpConfig
401+ --- config
402+ location /t {
403+ content_by_lua_block {
404+ ngx. say ( Liquid. Template: parse([[
405+ {{- " string" | sort | join -}}
406+ ]]): render() )
407+ }
408+ }
409+ --- request
410+ GET /t
411+ --- response_body
412+ string
413+
414+ --- no_error_log
415+ [error]
416+
417+
418+
419+ === TEST 19: 'uniq' filter works on strings
420+ --- http_config eval: $::HttpConfig
421+ --- config
422+ location /t {
423+ content_by_lua_block {
424+ ngx. say ( Liquid. Template: parse([[
425+ {{- " string" | uniq | join -}}
426+ ]]): render() )
427+ }
428+ }
429+ --- request
430+ GET /t
431+ --- response_body
432+ string
433+ --- no_error_log
434+ [error]
0 commit comments