mirror of https://github.com/tc39/test262.git
Add tests for invalid \c in character class
This patch implements tests for https://github.com/tc39/ecma262/pull/864
This commit is contained in:
parent
ce217fffad
commit
b82be14e26
|
@ -0,0 +1,53 @@
|
|||
// Copyright 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: prod-annexB-ClassEscape
|
||||
description: >
|
||||
Character classes containing an invalid control escape behave like [\\c]
|
||||
info: >
|
||||
ClassEscape :: [~U] `c`
|
||||
|
||||
The production ClassEscape :: `c` evaluates as follows:
|
||||
1. Return the CharSet containing the characters `\` and `c`.
|
||||
---*/
|
||||
|
||||
function* invalidControls() {
|
||||
// Check ASCII characters which are not in the extended range or syntax
|
||||
// characters
|
||||
for (let alpha = 0x00; alpha <= 0x7F; alpha++) {
|
||||
let letter = String.fromCharCode(alpha);
|
||||
if (!letter.match(/[0-9A-Za-z_\$(|)\[\]\/\\^]/)) {
|
||||
yield letter;
|
||||
}
|
||||
}
|
||||
yield "";
|
||||
}
|
||||
|
||||
for (let letter of invalidControls()) {
|
||||
var source = "[\\c" + letter + "]";
|
||||
var re = new RegExp(source);
|
||||
|
||||
if (letter.length > 0) {
|
||||
var char = letter.charCodeAt(0);
|
||||
var str = String.fromCharCode(char % 32);
|
||||
var arr = re.exec(str);
|
||||
if (str !== letter && arr !== null) {
|
||||
$ERROR(`Character ${letter} unreasonably wrapped around as a control character`);
|
||||
}
|
||||
|
||||
arr = re.exec(letter);
|
||||
if (arr === null) {
|
||||
$ERROR(`Character ${letter} missing from character class ${source}`);
|
||||
}
|
||||
}
|
||||
arr = re.exec("\\")
|
||||
if (arr === null) {
|
||||
$ERROR(`Character \\ missing from character class ${source}`);
|
||||
}
|
||||
arr = re.exec("c")
|
||||
if (arr === null) {
|
||||
$ERROR(`Character c missing from character class ${source}`);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue