summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/RegExp/unicode_restricted_identity_escape_c.js
blob: 416bce486d7bf9f3c980a5e89f298e37e0f3c164 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (C) 2015 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: B.1.4 is not applied for Unicode RegExp - Invalid control escape sequences
info: |
    The compatibility extensions defined in B.1.4 Regular Expressions Patterns
    are not applied for Unicode RegExp.
    Tested extension: "IdentityEscape[U] :: [~U] SourceCharacter but not c"
es6id: 21.1.2
---*/

function isAlpha(c) {
  return ("A" <= c && c <= "Z") || ("a" <= c && c <= "z");
}


// "c ControlLetter" sequence in AtomEscape.
//
// AtomEscape[U] :: CharacterEscape[?U]
// CharacterEscape[U] :: c ControlLetter
assert.throws(SyntaxError, function() { RegExp("\\c", "u"); });
for (var cu = 0x00; cu <= 0x7f; ++cu) {
  var s = String.fromCharCode(cu);
  if (!isAlpha(s)) {
    assert.throws(SyntaxError, function() {
      RegExp("\\c" + s, "u");
    }, "ControlLetter escape in AtomEscape: '" + s + "'");
  }
}


// "c ControlLetter" sequence in ClassEscape.
//
// ClassEscape[U] :: CharacterEscape[?U]
// CharacterEscape[U] :: c ControlLetter
assert.throws(SyntaxError, function() { RegExp("[\\c]", "u"); });
for (var cu = 0x00; cu <= 0x7f; ++cu) {
  var s = String.fromCharCode(cu);
  if (!isAlpha(s)) {
    assert.throws(SyntaxError, function() {
      RegExp("[\\c" + s + "]", "u");
    }, "ControlLetter escape in ClassEscape: '" + s + "'");
  }
}

reportCompare(0, 0);