PageRenderTime 49ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/t/053-gsub-jit.t

http://github.com/chaoslawful/lua-nginx-module
Unknown | 139 lines | 117 code | 22 blank | 0 comment | 0 complexity | 209326415f8906c0de675a7e5b33406a MD5 | raw file
  1. # vim:set ft= ts=4 sw=4 et fdm=marker:
  2. use lib 'lib';
  3. use Test::Nginx::Socket;
  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 + 4);
  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 rc, s, n = pcall(ngx.re.gsub, "hello\\nworld", "(abc", "world", "j")
  91. if rc then
  92. ngx.say(s, ": ", n)
  93. else
  94. ngx.say("error: ", s)
  95. end
  96. ';
  97. }
  98. --- request
  99. GET /re
  100. --- response_body
  101. error: bad argument #2 to '?' (failed to compile regex "(abc": pcre_compile() failed: missing ) in "(abc")
  102. === TEST 6: bad pattern + o
  103. --- config
  104. location /re {
  105. content_by_lua '
  106. local rc, s, n = pcall(ngx.re.gsub, "hello\\nworld", "(abc", "world", "jo")
  107. if rc then
  108. ngx.say(s, ": ", n)
  109. else
  110. ngx.say("error: ", s)
  111. end
  112. ';
  113. }
  114. --- request
  115. GET /re
  116. --- response_body
  117. error: bad argument #2 to '?' (failed to compile regex "(abc": pcre_compile() failed: missing ) in "(abc")