~ubuntu-branches/ubuntu/quantal/nginx/quantal-updates

« back to all changes in this revision

Viewing changes to debian/modules/nginx-lua/t/036-sub.t

  • Committer: Package Import Robot
  • Author(s): Kartik Mistry, Kartik Mistry
  • Date: 2011-09-26 10:17:04 UTC
  • mfrom: (4.2.38 sid)
  • Revision ID: package-import@ubuntu.com-20110926101704-x8pxngiujrmkxnn3
Tags: 1.1.4-2
[Kartik Mistry]
* debian/modules:
  + Updated nginx-upload-progress module, Thanks to upstream for fixing issue
    that FTBFS nginx on kFreeBSD-* archs.
  + Updated nginx-lua module to latest upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim:set ft= ts=4 sw=4 et fdm=marker:
 
2
use lib 'lib';
 
3
use Test::Nginx::Socket;
 
4
 
 
5
#worker_connections(1014);
 
6
#master_on();
 
7
#workers(2);
 
8
#log_level('warn');
 
9
 
 
10
repeat_each(2);
 
11
 
 
12
plan tests => repeat_each() * (blocks() * 2);
 
13
 
 
14
#no_diff();
 
15
no_long_string();
 
16
run_tests();
 
17
 
 
18
__DATA__
 
19
 
 
20
=== TEST 1: matched but w/o variables
 
21
--- config
 
22
    location /re {
 
23
        content_by_lua '
 
24
            local s, n = ngx.re.sub("hello, world", "[a-z]+", "howdy")
 
25
            ngx.say(s)
 
26
            ngx.say(n)
 
27
        ';
 
28
    }
 
29
--- request
 
30
    GET /re
 
31
--- response_body
 
32
howdy, world
 
33
1
 
34
 
 
35
 
 
36
 
 
37
=== TEST 2: not matched
 
38
--- config
 
39
    location /re {
 
40
        content_by_lua '
 
41
            local s, n = ngx.re.sub("hello, world", "[A-Z]+", "howdy")
 
42
            ngx.say(s)
 
43
            ngx.say(n)
 
44
        ';
 
45
    }
 
46
--- request
 
47
    GET /re
 
48
--- response_body
 
49
hello, world
 
50
0
 
51
 
 
52
 
 
53
 
 
54
=== TEST 3: matched and with variables
 
55
--- config
 
56
    location /re {
 
57
        content_by_lua '
 
58
            local s, n = ngx.re.sub("a b c d", "(b) (c)", "[$0] [$1] [$2] [$3] [$134]")
 
59
            ngx.say(s)
 
60
            ngx.say(n)
 
61
        ';
 
62
    }
 
63
--- request
 
64
    GET /re
 
65
--- response_body
 
66
a [b c] [b] [c] [] [] d
 
67
1
 
68
 
 
69
 
 
70
 
 
71
=== TEST 4: matched and with named variables
 
72
--- config
 
73
    location /re {
 
74
        content_by_lua '
 
75
            local rc, s, n = pcall(ngx.re.sub, "a b c d",
 
76
                "(b) (c)", "[$0] [$1] [$2] [$3] [$hello]")
 
77
            ngx.say(rc)
 
78
            ngx.say(s)
 
79
            ngx.say(n)
 
80
        ';
 
81
    }
 
82
--- request
 
83
    GET /re
 
84
--- response_body
 
85
false
 
86
bad template for substitution: "[$0] [$1] [$2] [$3] [$hello]"
 
87
nil
 
88
 
 
89
 
 
90
 
 
91
=== TEST 5: matched and with named variables (bracketed)
 
92
--- config
 
93
    location /re {
 
94
        content_by_lua '
 
95
            local rc, s, n = pcall(ngx.re.sub, "a b c d",
 
96
                "(b) (c)", "[$0] [$1] [$2] [$3] [${hello}]")
 
97
            ngx.say(rc)
 
98
            ngx.say(s)
 
99
            ngx.say(n)
 
100
        ';
 
101
    }
 
102
--- request
 
103
    GET /re
 
104
--- response_body
 
105
false
 
106
bad template for substitution: "[$0] [$1] [$2] [$3] [${hello}]"
 
107
nil
 
108
 
 
109
 
 
110
 
 
111
=== TEST 6: matched and with bracketed variables
 
112
--- config
 
113
    location /re {
 
114
        content_by_lua '
 
115
            local s, n = ngx.re.sub("b c d", "(b) (c)", "[$0] [$1] [${2}] [$3] [${134}]")
 
116
            ngx.say(s)
 
117
            ngx.say(n)
 
118
        ';
 
119
    }
 
120
--- request
 
121
    GET /re
 
122
--- response_body
 
123
[b c] [b] [c] [] [] d
 
124
1
 
125
 
 
126
 
 
127
 
 
128
=== TEST 7: matched and with bracketed variables (unmatched brackets)
 
129
--- config
 
130
    location /re {
 
131
        content_by_lua '
 
132
            local rc, s, n = pcall(ngx.re.sub, "b c d", "(b) (c)", "[$0] [$1] [${2}] [$3] [${134]")
 
133
            ngx.say(rc)
 
134
            ngx.say(s)
 
135
            ngx.say(n)
 
136
        ';
 
137
    }
 
138
--- request
 
139
    GET /re
 
140
--- response_body
 
141
false
 
142
bad template for substitution: "[$0] [$1] [${2}] [$3] [${134]"
 
143
nil
 
144
 
 
145
 
 
146
 
 
147
=== TEST 8: matched and with bracketed variables (unmatched brackets)
 
148
--- config
 
149
    location /re {
 
150
        content_by_lua '
 
151
            local rc, s, n = pcall(ngx.re.sub, "b c d", "(b) (c)", "[$0] [$1] [${2}] [$3] [${134")
 
152
            ngx.say(rc)
 
153
            ngx.say(s)
 
154
            ngx.say(n)
 
155
        ';
 
156
    }
 
157
--- request
 
158
    GET /re
 
159
--- response_body
 
160
false
 
161
bad template for substitution: "[$0] [$1] [${2}] [$3] [${134"
 
162
nil
 
163
 
 
164
 
 
165
 
 
166
=== TEST 9: matched and with bracketed variables (unmatched brackets)
 
167
--- config
 
168
    location /re {
 
169
        content_by_lua '
 
170
            local rc, s, n = pcall(ngx.re.sub, "b c d", "(b) (c)", "[$0] [$1] [${2}] [$3] [${")
 
171
            ngx.say(rc)
 
172
            ngx.say(s)
 
173
            ngx.say(n)
 
174
        ';
 
175
    }
 
176
--- request
 
177
    GET /re
 
178
--- response_body
 
179
false
 
180
bad template for substitution: "[$0] [$1] [${2}] [$3] [${"
 
181
nil
 
182
 
 
183
 
 
184
 
 
185
=== TEST 10: trailing $
 
186
--- config
 
187
    location /re {
 
188
        content_by_lua '
 
189
            local rc, s, n = pcall(ngx.re.sub, "b c d", "(b) (c)", "[$0] [$1] [${2}] [$3] [$")
 
190
            ngx.say(rc)
 
191
            ngx.say(s)
 
192
            ngx.say(n)
 
193
        ';
 
194
    }
 
195
--- request
 
196
    GET /re
 
197
--- response_body
 
198
false
 
199
bad template for substitution: "[$0] [$1] [${2}] [$3] [$"
 
200
nil
 
201
 
 
202
 
 
203
 
 
204
=== TEST 11: matched but w/o variables and with literal $
 
205
--- config
 
206
    location /re {
 
207
        content_by_lua '
 
208
            local s, n = ngx.re.sub("hello, world", "[a-z]+", "ho$$wdy")
 
209
            ngx.say(s)
 
210
            ngx.say(n)
 
211
        ';
 
212
    }
 
213
--- request
 
214
    GET /re
 
215
--- response_body
 
216
ho$wdy, world
 
217
1
 
218
 
 
219
 
 
220
 
 
221
=== TEST 12: non-anchored match
 
222
--- config
 
223
    location /re {
 
224
        content_by_lua '
 
225
            local s, n = ngx.re.sub("hello, 1234", "[0-9]", "x")
 
226
            ngx.say(s)
 
227
            ngx.say(n)
 
228
        ';
 
229
    }
 
230
--- request
 
231
    GET /re
 
232
--- response_body
 
233
hello, x234
 
234
1
 
235
 
 
236
 
 
237
 
 
238
=== TEST 13: anchored match
 
239
--- config
 
240
    location /re {
 
241
        content_by_lua '
 
242
            local s, n = ngx.re.sub("hello, 1234", "[0-9]", "x", "a")
 
243
            ngx.say(s)
 
244
            ngx.say(n)
 
245
        ';
 
246
    }
 
247
--- request
 
248
    GET /re
 
249
--- response_body
 
250
hello, 1234
 
251
0
 
252
 
 
253
 
 
254
 
 
255
=== TEST 14: function replace
 
256
--- config
 
257
    location /re {
 
258
        content_by_lua '
 
259
            local repl = function (m)
 
260
                return "[" .. m[0] .. "] [" .. m[1] .. "]"
 
261
            end
 
262
 
 
263
            local s, n = ngx.re.sub("hello, 34", "([0-9])", repl)
 
264
            ngx.say(s)
 
265
            ngx.say(n)
 
266
        ';
 
267
    }
 
268
--- request
 
269
    GET /re
 
270
--- response_body
 
271
hello, [3] [3]4
 
272
1
 
273
 
 
274
 
 
275
 
 
276
=== TEST 15: function replace (failed)
 
277
--- config
 
278
    location /re {
 
279
        content_by_lua '
 
280
            local repl = function (m)
 
281
                return "[" .. m[0] .. "] [" .. m[1] .. "]"
 
282
            end
 
283
 
 
284
            local s, n = ngx.re.sub("hello, 34", "([A-Z])", repl)
 
285
            ngx.say(s)
 
286
            ngx.say(n)
 
287
        ';
 
288
    }
 
289
--- request
 
290
    GET /re
 
291
--- response_body
 
292
hello, 34
 
293
0
 
294
 
 
295
 
 
296
 
 
297
=== TEST 16: bad repl arg type
 
298
--- config
 
299
    location /re {
 
300
        content_by_lua '
 
301
            local rc, s, n = pcall(ngx.re.sub, "hello, 34", "([A-Z])", true)
 
302
            ngx.say(rc)
 
303
            ngx.say(s)
 
304
            ngx.say(n)
 
305
        ';
 
306
    }
 
307
--- request
 
308
    GET /re
 
309
--- response_body
 
310
false
 
311
bad argument #3 to '?' (string, number, or function expected, got boolean)
 
312
nil
 
313
 
 
314
 
 
315
 
 
316
=== TEST 17: use number to replace
 
317
--- config
 
318
    location /re {
 
319
        content_by_lua '
 
320
            local rc, s, n = pcall(ngx.re.sub, "hello, 34", "([0-9])", 72)
 
321
            ngx.say(rc)
 
322
            ngx.say(s)
 
323
            ngx.say(n)
 
324
        ';
 
325
    }
 
326
--- request
 
327
    GET /re
 
328
--- response_body
 
329
true
 
330
hello, 724
 
331
1
 
332
 
 
333
 
 
334
 
 
335
=== TEST 18: bad function return value type
 
336
--- config
 
337
    location /re {
 
338
        content_by_lua '
 
339
            local f = function (m) end
 
340
            local rc, s, n = pcall(ngx.re.sub, "hello, 34", "([0-9])", f)
 
341
            ngx.say(rc)
 
342
            ngx.say(s)
 
343
            ngx.say(n)
 
344
        ';
 
345
    }
 
346
--- request
 
347
    GET /re
 
348
--- response_body
 
349
false
 
350
bad argument #3 to '?' (string or number expected to be returned by the replace function, got nil)
 
351
nil
 
352
 
 
353
 
 
354
 
 
355
=== TEST 19: matched but w/o variables (set_by_lua)
 
356
--- config
 
357
    location /re {
 
358
        set_by_lua $res '
 
359
            local s, n = ngx.re.sub("hello, world", "[a-z]+", "howdy")
 
360
            return s
 
361
        ';
 
362
        echo $res;
 
363
    }
 
364
--- request
 
365
    GET /re
 
366
--- response_body
 
367
howdy, world
 
368