PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/bundle/ngx_lua-0.9.2/t/054-gsub-dfa.t

https://github.com/dome/lixen_app
Unknown | 202 lines | 167 code | 35 blank | 0 comment | 0 complexity | c1d3c75db77bf11ab0abfe287209a9b5 MD5 | raw file
Possible License(s): BSD-2-Clause, BSD-3-Clause
  1. # vim:set ft= ts=4 sw=4 et fdm=marker:
  2. use lib 'lib';
  3. use t::TestNginxLua;
  4. #worker_connections(1014);
  5. #master_on();
  6. #workers(2);
  7. #log_level('warn');
  8. repeat_each(2);
  9. plan tests => repeat_each() * (blocks() * 2 + 5);
  10. #no_diff();
  11. no_long_string();
  12. run_tests();
  13. __DATA__
  14. === TEST 1: matched with d
  15. --- config
  16. location /re {
  17. content_by_lua '
  18. local s, n = ngx.re.gsub("hello, 1234 5678", "[0-9]|[0-9][0-9]", "world", "d")
  19. if n then
  20. ngx.say(s, ": ", n)
  21. else
  22. ngx.say(s)
  23. end
  24. ';
  25. }
  26. --- request
  27. GET /re
  28. --- response_body
  29. hello, worldworld worldworld: 4
  30. === TEST 2: not matched with d
  31. --- config
  32. location /re {
  33. content_by_lua '
  34. local s, n = ngx.re.gsub("hello, world", "[0-9]+", "hiya", "d")
  35. if n then
  36. ngx.say(s, ": ", n)
  37. else
  38. ngx.say(s)
  39. end
  40. ';
  41. }
  42. --- request
  43. GET /re
  44. --- response_body
  45. hello, world: 0
  46. === TEST 3: matched with do
  47. --- config
  48. location /re {
  49. content_by_lua '
  50. local s, n = ngx.re.gsub("hello, 1234 5678", "[0-9]|[0-9][0-9]", "world", "do")
  51. if n then
  52. ngx.say(s, ": ", n)
  53. else
  54. ngx.say(s)
  55. end
  56. ';
  57. }
  58. --- request
  59. GET /re
  60. --- response_body
  61. hello, worldworld worldworld: 4
  62. === TEST 4: not matched with do
  63. --- config
  64. location /re {
  65. content_by_lua '
  66. local s, n = ngx.re.gsub("hello, world", "[0-9]+", "hiya", "do")
  67. if n then
  68. ngx.say(s, ": ", n)
  69. else
  70. ngx.say(s)
  71. end
  72. ';
  73. }
  74. --- request
  75. GET /re
  76. --- response_body
  77. hello, world: 0
  78. === TEST 5: bad pattern
  79. --- config
  80. location /re {
  81. content_by_lua '
  82. local s, n, err = ngx.re.gsub("hello\\nworld", "(abc", "world", "j")
  83. if s then
  84. ngx.say("gsub: ", n)
  85. else
  86. ngx.say("error: ", err)
  87. end
  88. ';
  89. }
  90. --- request
  91. GET /re
  92. --- response_body
  93. error: pcre_compile() failed: missing ) in "(abc"
  94. === TEST 6: bad pattern + o
  95. --- config
  96. location /re {
  97. content_by_lua '
  98. local s, n, err = ngx.re.gsub("hello\\nworld", "(abc", "world", "jo")
  99. if s then
  100. ngx.say("gsub: ", n)
  101. else
  102. ngx.say("error: ", err)
  103. end
  104. ';
  105. }
  106. --- request
  107. GET /re
  108. --- response_body
  109. error: pcre_compile() failed: missing ) in "(abc"
  110. --- no_error_log
  111. [error]
  112. === TEST 7: UTF-8 mode without UTF-8 sequence checks
  113. --- config
  114. location /re {
  115. content_by_lua '
  116. local s, n, err = ngx.re.gsub("你好", ".", "a", "Ud")
  117. if s then
  118. ngx.say("s: ", s)
  119. end
  120. ';
  121. }
  122. --- stap
  123. probe process("$LIBPCRE_PATH").function("pcre_compile") {
  124. printf("compile opts: %x\n", $options)
  125. }
  126. probe process("$LIBPCRE_PATH").function("pcre_dfa_exec") {
  127. printf("exec opts: %x\n", $options)
  128. }
  129. --- stap_out
  130. compile opts: 800
  131. exec opts: 2000
  132. exec opts: 2000
  133. exec opts: 2000
  134. --- request
  135. GET /re
  136. --- response_body
  137. s: aa
  138. --- no_error_log
  139. [error]
  140. === TEST 8: UTF-8 mode with UTF-8 sequence checks
  141. --- config
  142. location /re {
  143. content_by_lua '
  144. local s, n, err = ngx.re.gsub("你好", ".", "a", "ud")
  145. if s then
  146. ngx.say("s: ", s)
  147. end
  148. ';
  149. }
  150. --- stap
  151. probe process("$LIBPCRE_PATH").function("pcre_compile") {
  152. printf("compile opts: %x\n", $options)
  153. }
  154. probe process("$LIBPCRE_PATH").function("pcre_dfa_exec") {
  155. printf("exec opts: %x\n", $options)
  156. }
  157. --- stap_out
  158. compile opts: 800
  159. exec opts: 0
  160. exec opts: 0
  161. exec opts: 0
  162. --- request
  163. GET /re
  164. --- response_body
  165. s: aa
  166. --- no_error_log
  167. [error]