unicode_regex_surrogate_atoms.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. Object.defineProperty(Object.getPrototypeOf({}), "echo", { value: function () { WScript.Echo(this); } });
  6. function AssertEqual(actual, expected, msg) { ((actual === expected ? "Passed! " : "Failed (actual: " + actual + ", expected: " + expected + "). Message: ") + msg).echo(); };
  7. Object.defineProperty(Object.getPrototypeOf({}), "equalTo", { value: function (other, msg) { AssertEqual(this.constructor(this), other, msg); } });
  8. //Basic test, true
  9. /a\u{20BB7}*b/u.test("a\uD842\uDFB7\uD842\uDFB7b").echo();
  10. //Should be true
  11. /a\u{20BB7}*\uD800\uDC00*b/u.test("a\uD842\uDFB7\u{20BB7}\uD800\uDC00\uD800\uDC00b").echo();
  12. //Should be error(no unicode option)
  13. try {
  14. eval("/a\\u{20BB7}*\\uD800\\uDC00*b/").test("a\uD842\uDFB7\u{DFB7}\uD800\uDC00\uDC00b").echo();
  15. } catch (ex) {
  16. ex.echo();
  17. }
  18. //The case where a lookback is incorrect due to a group being added.
  19. /a\uD800\uDC00*(\u{20BB7})\1b/u.test("a\u{20BB7}\u{20BB7}b").echo();
  20. //These are interesting, they shouldn't combine, but without quantifier should be true
  21. /a\uD800(\uDC00)b/u.test("a\uD800\uDC00b").echo();
  22. /a\uD800[\uDC00]b/u.test("a\uD800\uDC00b").echo();
  23. //Reverse of above, with a quantifier should be true
  24. /a\uD800(\uDC00)*b/u.test("a\uD800\uDC00\uDC00b").echo();
  25. /a\uD800[\uDC00]*b/u.test("a\uD800\uDC00\uDC00b").echo();
  26. //True for ranges
  27. /a[\u{20BB7}]b/u.test("a\uD842\uDFB7b").echo();
  28. /a[\u0000 - \u{20BB7}]b/u.test("a\uD842\uDFB7b").echo();
  29. /a[\u0000-\u{20BB7}]b/u.test("a\uFFFFb").echo();
  30. /a[\u0000-\u{20BB7}]b/u.test("a\uD900b").echo();
  31. /a[\u0000-\u{20BB7}]b/u.test("a\u{10000}b").echo();
  32. /a[\u0000-\u{20BB7}]b/u.test("a\u{20BB7}b").echo();
  33. /a[\u0000-\u{20400}]b/u.test("a\u{20400}b").echo();
  34. /a[\u0000-\u{203FF}]b/u.test("a\u{203FF}b").echo();
  35. /a[\u0000-\u{20BB7}]b/u.test("a\u{0000}b").echo();
  36. /a.b/u.test("a\uD900b").echo();
  37. //False for ranges
  38. /a[\u0000-\u{20BB7}]b/u.test("a\u{20BB8}b").echo();
  39. /a[\u1000-\u{20BB7}]b/u.test("a\u{0000}b").echo();