regex_deviations.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. if (this.WScript && this.WScript.LoadScriptFile) {
  6. this.WScript.LoadScriptFile('..\\UnitTestFramework\\UnitTestFramework.js');
  7. }
  8. var tests = [
  9. {
  10. name: '"\\c" should be treated as "\\\\c" outside the character set',
  11. assertions: [
  12. [/^\c$/, '\\c'],
  13. ]
  14. },
  15. {
  16. name: '"\\c" should be treated as "c" inside the character set',
  17. assertions: [
  18. [/[\c]/, 'c'],
  19. [/[\c-]/, 'c']
  20. ]
  21. },
  22. {
  23. name: 'A non-letter character after "\\c" inside the character set should be the letter\'s mathematical value mod 32',
  24. assertions: [
  25. [/[\c1]/, '\x11']
  26. ]
  27. },
  28. {
  29. name: 'A non-letter character after "\\c" outside the character set should not be treated differently',
  30. assertions: [
  31. [/\c1/, '\\c1']
  32. ]
  33. },
  34. {
  35. name: '"]" should be allowed on its own',
  36. assertions: [
  37. [/]/, ']']
  38. ]
  39. }
  40. ];
  41. var testsForRunner = tests.map(function (test) {
  42. return {
  43. name: test.name,
  44. body: function () {
  45. test.assertions.forEach(function (assertion) {
  46. var re = assertion[0];
  47. var inputString = assertion[1];
  48. assert.isTrue(re.test(inputString), re.source);
  49. });
  50. }
  51. }
  52. });
  53. testRunner.runTests(testsForRunner, { verbose: WScript.Arguments[0] != 'summary' });