bug_OS14763260.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
  6. var tests = [
  7. {
  8. name: "Verify last match invalidated as expected",
  9. body: function () {
  10. const r1 = /(abc)/;
  11. const r2 = /(def)/;
  12. const s1 = "abc";
  13. const s2 = " def";
  14. r1.test(s1);
  15. assert.areEqual("abc", RegExp.input, "RegExp.input property calculated correctly");
  16. assert.areEqual("abc", RegExp['$_'], "RegExp.$_ property calculated correctly");
  17. assert.areEqual("abc", RegExp.lastMatch, "RegExp.lastMatch property calculated correctly");
  18. assert.areEqual("abc", RegExp['$&'], "RegExp.$& property calculated correctly");
  19. assert.areEqual("abc", RegExp.$1, "RegExp.$1 property calculated correctly");
  20. assert.areEqual(0, RegExp.index, "RegExp.index property calculated correctly");
  21. r2.test(s2);
  22. assert.areEqual(" def", RegExp.input, "RegExp.input property calculated correctly");
  23. assert.areEqual(" def", RegExp['$_'], "RegExp.$_ property calculated correctly");
  24. assert.areEqual("def", RegExp.lastMatch, "RegExp.lastMatch property calculated correctly");
  25. assert.areEqual("def", RegExp['$&'], "RegExp.$& property calculated correctly");
  26. assert.areEqual("def", RegExp.$1, "RegExp.$1 property calculated correctly");
  27. assert.areEqual(1, RegExp.index, "RegExp.index property calculated correctly");
  28. r1.test(s1);
  29. assert.areEqual("abc", RegExp.input, "Stale RegExp.input property should be invalidated by second r1.test(s1)");
  30. assert.areEqual("abc", RegExp['$_'], "Stale RegExp.$_ property should be invalidated by second r1.test(s1)");
  31. assert.areEqual("abc", RegExp.lastMatch, "Stale RegExp.lastMatch should be invalidated by second r1.test(s1)");
  32. assert.areEqual("abc", RegExp['$&'], "Stale RegExp.$& property should be invalidated by second r1.test(s1)");
  33. assert.areEqual("abc", RegExp.$1, "Stale RegExp.$1 should be invalidated by second r1.test(s1)");
  34. assert.areEqual(0, RegExp.index, "Stale RegExp.index property should be invalidated by second r1.test(s1)");
  35. }
  36. },
  37. ];
  38. testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });