PageRenderTime 360ms CodeModel.GetById 41ms RepoModel.GetById 19ms app.codeStats 0ms

/bundle/ngx_lua-0.9.2/t/053-gsub-jit.t

https://github.com/dome/lixen_app
Unknown | 143 lines | 121 code | 22 blank | 0 comment | 0 complexity | 8b91c38ade92b62088408324333e3116 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 + 6);
  10. #no_diff();
  11. no_long_string();
  12. run_tests();
  13. __DATA__
  14. === TEST 1: matched with j
  15. --- config
  16. location /re {
  17. content_by_lua '
  18. local s, n = ngx.re.gsub("hello, 1234 5678", "([0-9]+)", "world", "j")
  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, world world: 2
  30. --- error_log
  31. pcre JIT compiling result: 1
  32. === TEST 2: not matched with j
  33. --- config
  34. location /re {
  35. content_by_lua '
  36. local s, n = ngx.re.gsub("hello, world", "[0-9]+", "hiya", "j")
  37. if n then
  38. ngx.say(s, ": ", n)
  39. else
  40. ngx.say(s)
  41. end
  42. ';
  43. }
  44. --- request
  45. GET /re
  46. --- response_body
  47. hello, world: 0
  48. --- error_log
  49. pcre JIT compiling result: 1
  50. === TEST 3: matched with jo
  51. --- config
  52. location /re {
  53. content_by_lua '
  54. local s, n = ngx.re.gsub("hello, 1234 5678", "([0-9]+)", "world", "jo")
  55. if n then
  56. ngx.say(s, ": ", n)
  57. else
  58. ngx.say(s)
  59. end
  60. ';
  61. }
  62. --- request
  63. GET /re
  64. --- response_body
  65. hello, world world: 2
  66. --- error_log
  67. pcre JIT compiling result: 1
  68. === TEST 4: not matched with jo
  69. --- config
  70. location /re {
  71. content_by_lua '
  72. local s, n = ngx.re.gsub("hello, world", "[0-9]+", "hiya", "jo")
  73. if n then
  74. ngx.say(s, ": ", n)
  75. else
  76. ngx.say(s)
  77. end
  78. ';
  79. }
  80. --- request
  81. GET /re
  82. --- response_body
  83. hello, world: 0
  84. --- error_log
  85. pcre JIT compiling result: 1
  86. === TEST 5: bad pattern
  87. --- config
  88. location /re {
  89. content_by_lua '
  90. local s, n, err = ngx.re.gsub("hello\\nworld", "(abc", "world", "j")
  91. if s then
  92. ngx.say(s, ": ", n)
  93. else
  94. ngx.say("error: ", err)
  95. end
  96. ';
  97. }
  98. --- request
  99. GET /re
  100. --- response_body
  101. error: pcre_compile() failed: missing ) in "(abc"
  102. --- no_error_log
  103. [error]
  104. === TEST 6: bad pattern + o
  105. --- config
  106. location /re {
  107. content_by_lua '
  108. local s, n, err = ngx.re.gsub("hello\\nworld", "(abc", "world", "jo")
  109. if s then
  110. ngx.say(s, ": ", n)
  111. else
  112. ngx.say("error: ", err)
  113. end
  114. ';
  115. }
  116. --- request
  117. GET /re
  118. --- response_body
  119. error: pcre_compile() failed: missing ) in "(abc"
  120. --- no_error_log
  121. [error]