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

/t/054-gsub-dfa.t

http://github.com/chaoslawful/lua-nginx-module
Unknown | 123 lines | 101 code | 22 blank | 0 comment | 0 complexity | f6b038b17a68c738dce7c9d89af26737 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);
  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. rc, m = pcall(ngx.re.gsub, "hello\\nworld", "(abc", "world", "j")
  83. ngx.say(rc, ": ", m)
  84. ';
  85. }
  86. --- request
  87. GET /re
  88. --- response_body
  89. false: bad argument #2 to '?' (failed to compile regex "(abc": pcre_compile() failed: missing ) in "(abc")
  90. === TEST 6: bad pattern + o
  91. --- config
  92. location /re {
  93. content_by_lua '
  94. rc, m = pcall(ngx.re.gsub, "hello\\nworld", "(abc", "world", "jo")
  95. ngx.say(rc, ": ", m)
  96. ';
  97. }
  98. --- request
  99. GET /re
  100. --- response_body
  101. false: bad argument #2 to '?' (failed to compile regex "(abc": pcre_compile() failed: missing ) in "(abc")