|
| 1 | +use Test::Nginx::Socket::Lua; |
| 2 | +use Cwd qw(cwd); |
| 3 | + |
| 4 | +plan tests => repeat_each() * (3 * blocks()); |
| 5 | + |
| 6 | +my $pwd = cwd(); |
| 7 | + |
| 8 | +our $HttpConfig = qq{ |
| 9 | + lua_package_path "$pwd/lib/?.lua;;;"; |
| 10 | + lua_package_cpath "/usr/local/openresty/lualib/?.so;;"; |
| 11 | +}; |
| 12 | + |
| 13 | +no_long_string(); |
| 14 | +run_tests(); |
| 15 | + |
| 16 | +__DATA__ |
| 17 | +
|
| 18 | +=== TEST 1: 'contains' operator. |
| 19 | +--- http_config eval: $::HttpConfig |
| 20 | +--- config |
| 21 | + location /t { |
| 22 | + content_by_lua_block { |
| 23 | + local Liquid = require 'liquid' |
| 24 | + local Lexer = Liquid.Lexer |
| 25 | + local Parser = Liquid.Parser |
| 26 | + local Interpreter = Liquid.Interpreter |
| 27 | + local document = "{% if 'abc' contains 'def' %}yes{% else %}no {% endif %}".. |
| 28 | + "{% if 'abcd' contains 'bc' %}yes {% else %}no{% endif %}".. |
| 29 | + "{% assign var = 'abc afooa ghi' | split: ' ' %}{% if var contains 'foo' %}yes{% else %}no {% endif %}".. |
| 30 | + "{% assign var = 'abc def ghi' | split: ' ' %}{% if var contains 'def' %}yes {% else %}no{% endif %}" |
| 31 | + local lexer = Lexer:new(document) |
| 32 | + local parser = Parser:new(lexer) |
| 33 | + local interpreter = Interpreter:new(parser) |
| 34 | + ngx.say(interpreter:interpret()) |
| 35 | + } |
| 36 | + } |
| 37 | +--- request |
| 38 | +GET /t |
| 39 | +--- response_body |
| 40 | +no yes no yes |
| 41 | +--- no_error_log |
| 42 | +[error] |
| 43 | +
|
| 44 | +=== TEST 2: '==' operator. |
| 45 | +--- http_config eval: $::HttpConfig |
| 46 | +--- config |
| 47 | + location /t { |
| 48 | + content_by_lua_block { |
| 49 | + local Liquid = require 'liquid' |
| 50 | + local Lexer = Liquid.Lexer |
| 51 | + local Parser = Liquid.Parser |
| 52 | + local Interpreter = Liquid.Interpreter |
| 53 | + local document = "{% if 'abc' == 'def' %}yes{% else %}no {% endif %}".. |
| 54 | + "{% if 'abcd' == 'abcd' %}yes {% else %}no{% endif %}".. |
| 55 | + "{% assign var = 'abc def' | split: ' ' %}".. |
| 56 | + "{% assign var2 = 'abc def ghi' | split: ' ' %}".. |
| 57 | + "{% if var == var2 %}yes{% else %}no {% endif %}".. |
| 58 | + "{% assign var = 'abc def ghi' | split: ' ' %}".. |
| 59 | + "{% assign var2 = 'abc def ghi' | split: ' ' %}".. |
| 60 | + "{% if var == var2 %}yes {% else %}no{% endif %}" |
| 61 | + local lexer = Lexer:new(document) |
| 62 | + local parser = Parser:new(lexer) |
| 63 | + local interpreter = Interpreter:new(parser) |
| 64 | + ngx.say(interpreter:interpret()) |
| 65 | + } |
| 66 | + } |
| 67 | +--- request |
| 68 | +GET /t |
| 69 | +--- response_body |
| 70 | +no yes no yes |
| 71 | +--- no_error_log |
| 72 | +[error] |
| 73 | +
|
| 74 | +=== TEST 3: '!=' operator. |
| 75 | +--- http_config eval: $::HttpConfig |
| 76 | +--- config |
| 77 | + location /t { |
| 78 | + content_by_lua_block { |
| 79 | + local Liquid = require 'liquid' |
| 80 | + local Lexer = Liquid.Lexer |
| 81 | + local Parser = Liquid.Parser |
| 82 | + local Interpreter = Liquid.Interpreter |
| 83 | + local document = "{% if 'abc' != 'def' %}yes {% else %}no{% endif %}".. |
| 84 | + "{% if 'abcd' != 'abcd' %}yes{% else %}no {% endif %}".. |
| 85 | + "{% assign var = 'abc def' | split: ' ' %}".. |
| 86 | + "{% assign var2 = 'abc def ghi' | split: ' ' %}".. |
| 87 | + "{% if var != var2 %}yes {% else %}no{% endif %}".. |
| 88 | + "{% assign var = 'abc def ghi' | split: ' ' %}".. |
| 89 | + "{% assign var2 = 'abc def ghi' | split: ' ' %}".. |
| 90 | + "{% if var != var2 %}yes{% else %}no {% endif %}" |
| 91 | + local lexer = Lexer:new(document) |
| 92 | + local parser = Parser:new(lexer) |
| 93 | + local interpreter = Interpreter:new(parser) |
| 94 | + ngx.say(interpreter:interpret()) |
| 95 | + } |
| 96 | + } |
| 97 | +--- request |
| 98 | +GET /t |
| 99 | +--- response_body |
| 100 | +yes no yes no |
| 101 | +--- no_error_log |
| 102 | +[error] |
0 commit comments