1
# vim:set ft= ts=4 sw=4 et fdm=marker:
3
use Test::Nginx::Socket::Lua;
5
#worker_connections(1014);
12
plan tests => repeat_each() * (blocks() * 2 + 5);
20
=== TEST 1: matched with j
24
m = ngx.re.match("hello, 1234", "([0-9]+)", "j")
28
ngx.say("not matched!")
37
pcre JIT compiling result: 1
41
=== TEST 2: not matched with j
45
m = ngx.re.match("hello, world", "([0-9]+)", "j")
49
ngx.say("not matched!")
58
pcre JIT compiling result: 1
62
=== TEST 3: matched with jo
66
m = ngx.re.match("hello, 1234", "([0-9]+)", "jo")
70
ngx.say("not matched!")
79
--- grep_error_log eval
80
qr/pcre JIT compiling result: \d+/
82
--- grep_error_log_out eval
83
["pcre JIT compiling result: 1\n", ""]
87
=== TEST 4: not matched with jo
91
m = ngx.re.match("hello, world", "([0-9]+)", "jo")
95
ngx.say("not matched!")
104
--- grep_error_log eval
105
qr/pcre JIT compiling result: \d+/
107
--- grep_error_log_out eval
108
["pcre JIT compiling result: 1\n", ""]
112
=== TEST 5: bad pattern
116
local m, err = ngx.re.match("hello\\nworld", "(abc", "j")
122
ngx.say("error: ", err)
125
ngx.say("not matched: ", m)
133
error: pcre_compile() failed: missing ) in "(abc"
139
=== TEST 6: just hit match limit
141
lua_regex_match_limit 2940;
144
content_by_lua_file html/a.lua;
149
local re = [==[(?i:([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:=|<=>|r?like|sounds\s+like|regexp)([\s'\"`´’‘\(\)]*)?\2|([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:!=|<=|>=|<>|<|>|\^|is\s+not|not\s+like|not\s+regexp)([\s'\"`´’‘\(\)]*)?(?!\6)([\d\w]+))]==]
151
s = string.rep([[ABCDEFG]], 21)
153
local start = ngx.now()
155
local res, err = ngx.re.match(s, re, "jo")
159
local elapsed = ngx.now() - start
160
ngx.say(elapsed, " sec elapsed.")
165
ngx.say("error: ", err)
168
ngx.say("failed to match")
175
error: pcre_exec() failed: -8
179
=== TEST 7: just not hit match limit
181
lua_regex_match_limit 2950;
184
content_by_lua_file html/a.lua;
189
local re = [==[(?i:([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:=|<=>|r?like|sounds\s+like|regexp)([\s'\"`´’‘\(\)]*)?\2|([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:!=|<=|>=|<>|<|>|\^|is\s+not|not\s+like|not\s+regexp)([\s'\"`´’‘\(\)]*)?(?!\6)([\d\w]+))]==]
191
s = string.rep([[ABCDEFG]], 21)
193
local start = ngx.now()
195
local res, err = ngx.re.match(s, re, "jo")
199
local elapsed = ngx.now() - start
200
ngx.say(elapsed, " sec elapsed.")
205
ngx.say("error: ", err)
208
ngx.say("failed to match")