PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/test-nginx/cases/lua-tests/054-gsub-dfa.t

https://github.com/liyao0409/tengine
Unknown | 134 lines | 111 code | 23 blank | 0 comment | 0 complexity | 140ed76226dd85afde16f19061b53b1a MD5 | raw file
Possible License(s): BSD-3-Clause
  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 + 1);
  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: failed to compile regex "(abc": 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: failed to compile regex "(abc": pcre_compile() failed: missing ) in "(abc"
  110. --- no_error_log
  111. [error]