unicode_restricted_identity_escape_alpha.js (2674B)
1 // Copyright (C) 2015 André Bargull. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 description: B.1.4 is not applied for Unicode RegExp - Identity escape with basic latin letters 6 info: | 7 The compatibility extensions defined in B.1.4 Regular Expressions Patterns 8 are not applied for Unicode RegExps. 9 Tested extension: "IdentityEscape[U] :: [~U] SourceCharacter but not c" 10 11 Forbidden extension (16.1): 12 The RegExp pattern grammars in 21.2.1 and B.1.4 must not be extended to recognize any of the 13 source characters A-Z or a-z as IdentityEscape[U] when the U grammar parameter is present. 14 es6id: 21.1.2 15 ---*/ 16 17 function isValidAlphaEscapeInAtom(s) { 18 switch (s) { 19 // Assertion [U] :: \b 20 case "b": 21 // Assertion [U] :: \B 22 case "B": 23 // ControlEscape :: one of f n r t v 24 case "f": 25 case "n": 26 case "r": 27 case "t": 28 case "v": 29 // CharacterClassEscape :: one of d D s S w W 30 case "d": 31 case "D": 32 case "s": 33 case "S": 34 case "w": 35 case "W": 36 return true; 37 default: 38 return false; 39 } 40 } 41 42 function isValidAlphaEscapeInClass(s) { 43 switch (s) { 44 // ClassEscape[U] :: b 45 case "b": 46 // ControlEscape :: one of f n r t v 47 case "f": 48 case "n": 49 case "r": 50 case "t": 51 case "v": 52 // CharacterClassEscape :: one of d D s S w W 53 case "d": 54 case "D": 55 case "s": 56 case "S": 57 case "w": 58 case "W": 59 return true; 60 default: 61 return false; 62 } 63 } 64 65 // IdentityEscape in AtomEscape 66 for (var cu = 0x41 /* A */; cu <= 0x5a /* Z */; ++cu) { 67 var s = String.fromCharCode(cu); 68 if (!isValidAlphaEscapeInAtom(s)) { 69 assert.throws(SyntaxError, function() { 70 RegExp("\\" + s, "u"); 71 }, "IdentityEscape in AtomEscape: '" + s + "'"); 72 } 73 } 74 for (var cu = 0x61 /* a */; cu <= 0x7a /* z */; ++cu) { 75 var s = String.fromCharCode(cu); 76 if (!isValidAlphaEscapeInAtom(s)) { 77 assert.throws(SyntaxError, function() { 78 RegExp("\\" + s, "u"); 79 }, "IdentityEscape in AtomEscape: '" + s + "'"); 80 } 81 } 82 83 84 // IdentityEscape in ClassEscape 85 for (var cu = 0x41 /* A */; cu <= 0x5a /* Z */; ++cu) { 86 var s = String.fromCharCode(cu); 87 if (!isValidAlphaEscapeInClass(s)) { 88 assert.throws(SyntaxError, function() { 89 RegExp("[\\" + s + "]", "u"); 90 }, "IdentityEscape in ClassEscape: '" + s + "'"); 91 } 92 } 93 for (var cu = 0x61 /* a */; cu <= 0x7a /* z */; ++cu) { 94 var s = String.fromCharCode(cu); 95 if (!isValidAlphaEscapeInClass(s)) { 96 assert.throws(SyntaxError, function() { 97 RegExp("[\\" + s + "]", "u"); 98 }, "IdentityEscape in ClassEscape: '" + s + "'"); 99 } 100 } 101 102 reportCompare(0, 0);