stickyflag.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. /*
  6. Below test cases verifies the combination of sticky+multiline flag when used.
  7. */
  8. var testCount = 0;
  9. function test(re, str, lastIndex, loopCount)
  10. {
  11. var formattedStr = str.replace('\n', '\\n');
  12. WScript.Echo('********** Test #' + ++testCount + " **********");
  13. re.lastIndex = lastIndex;
  14. for(var i = 0; i < loopCount; i++) {
  15. WScript.Echo(' *** Iteration#' + (i+1))
  16. WScript.Echo(' var re=' + re);
  17. WScript.Echo(' var str=\'' + formattedStr + '\'');
  18. WScript.Echo(' re.lastIndex = '+re.lastIndex);
  19. WScript.Echo(' Result = ' + re.exec(str));
  20. WScript.Echo(' re.lastIndex = ' + re.lastIndex);
  21. }
  22. }
  23. // no-^, /y
  24. test(/b12/y, "b12asd\nb12", 1, 4);
  25. test(/b12/y, "ab12asd\nb12", 1, 4);
  26. test(/b/y, "ab", 1, 4);
  27. test(/abc/y, "abcabcababc", 3, 4);
  28. // no-^, /my
  29. test(/b12/my, "ab12asd\nb12", 0, 4);
  30. test(/b12/my, "ab12asd\nb12", 1, 4);
  31. test(/b12/my, "b12asd\nb12", 1, 4);
  32. // ^, /y
  33. test(/^b12/y, "b12asd\nb12", 1, 4);
  34. test(/^b12/y, "ab12asd\nb12", 0, 4);
  35. test(/^b12/y, "ab12asd\nb12", 1, 4);
  36. test(/^b12/y, "b12b12", 3, 4);
  37. test(/a|^b/gy, "baba", 0, 4);
  38. // ^, /my
  39. test(/^b12/my, "b12asd\nb12", 0, 4);
  40. test(/^b12/my, "b12asd\nb12", 1, 4);
  41. test(/^b12/my, "b12asd\nb12", 7, 4);
  42. test(/^b12/my, "asdsa123asd\nb12", 1, 4);
  43. test(/^b12/my, "ab12asd\nb12", 1, 4);
  44. test(/^b12/my, "ab12asd\nb12", 0, 4);
  45. test(/^b/my, "a\nb", 2, 4);
  46. WScript.Echo("abc\ndef\nghi\njkl\nmno\npqr\nstu\nvwx\nyz".match(/^.*\n/myg));
  47. // BOILiteral2
  48. test(/^ba/my, "ba\nba", 0, 4);
  49. test(/^ba/my, "ba\nba", 1, 4);
  50. // BoundedWordTag
  51. test(/\b\w+\b/y, "( ab )", 0, 4);
  52. test(/\b\w+\b/y, "( ab )", 2, 4);
  53. // SingleCharTag
  54. test(/b/my, "ba\nb", 0, 4);
  55. test(/b/my, "ba\nb", 1, 4);
  56. test(/b/y, "ba\nb", 0, 4);
  57. test(/b/y, "ba\nb", 1, 4);
  58. test(/b/y, "a\nb", 0, 4);
  59. test(/b/my, "a\nb", 0, 4);
  60. //LeadingTrailingSpacesTag (already taken care because of trailing ^)
  61. var re = /^\s*|\s*$/;
  62. test(/^\s*|\s*$/y, " ab", 1, 1);