-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add exhaustive tests for RegExp Unicode property escapes (#971)
Proposal: https://github.com/tc39/proposal-regexp-unicode-property-escapes These tests have been generated by the script at https://github.com/mathiasbynens/unicode-property-escapes-tests. They check all the properties and values that should be supported by implementations against the symbols they’re supposed to match. False positives are detected as well. Ref. #950. Ref. tc39/proposal-regexp-unicode-property-escapes#4.
- Loading branch information
1 parent
89e15ce
commit 44b40e0
Showing
367 changed files
with
62,809 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
function buildString({ loneCodePoints, ranges }) { | ||
const CHUNK_SIZE = 10000; | ||
let result = String.fromCodePoint(...loneCodePoints); | ||
for (const [start, end] of ranges) { | ||
const codePoints = []; | ||
for (let length = 0, codePoint = start; codePoint <= end; codePoint++) { | ||
codePoints[length++] = codePoint; | ||
if (length === CHUNK_SIZE) { | ||
result += String.fromCodePoint(...codePoints); | ||
codePoints.length = length = 0; | ||
} | ||
} | ||
result += String.fromCodePoint(...codePoints); | ||
} | ||
return result; | ||
} | ||
|
||
function testPropertyEscapes(regex, string, expression) { | ||
if (!regex.test(string)) { | ||
for (const symbol of string) { | ||
const hex = symbol | ||
.codePointAt(0) | ||
.toString(16) | ||
.toUpperCase() | ||
.padStart(6, "0"); | ||
assert( | ||
regex.test(symbol), | ||
`\`${ expression }\` should match U+${ hex } (\`${ symbol }\`)` | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2017 Mathias Bynens. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
author: Mathias Bynens | ||
description: > | ||
Unicode property escapes for `ASCII` | ||
info: | | ||
Generated by https://github.com/mathiasbynens/unicode-property-escapes-tests | ||
Unicode v9.0.0 | ||
esid: sec-static-semantics-unicodematchproperty-p | ||
features: [regexp-unicode-property-escapes] | ||
includes: [regExpUtils.js] | ||
---*/ | ||
|
||
const matchSymbols = buildString({ | ||
loneCodePoints: [], | ||
ranges: [ | ||
[0x000000, 0x00007F] | ||
] | ||
}); | ||
testPropertyEscapes( | ||
/^\p{ASCII}+$/u, | ||
matchSymbols, | ||
"\\p{ASCII}" | ||
); | ||
|
||
const nonMatchSymbols = buildString({ | ||
loneCodePoints: [], | ||
ranges: [ | ||
[0x00DC00, 0x00DFFF], | ||
[0x000080, 0x00DBFF], | ||
[0x00E000, 0x10FFFF] | ||
] | ||
}); | ||
testPropertyEscapes( | ||
/^\P{ASCII}+$/u, | ||
nonMatchSymbols, | ||
"\\P{ASCII}" | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2017 Mathias Bynens. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
author: Mathias Bynens | ||
description: > | ||
Unicode property escapes for `ASCII_Hex_Digit` | ||
info: | | ||
Generated by https://github.com/mathiasbynens/unicode-property-escapes-tests | ||
Unicode v9.0.0 | ||
esid: sec-static-semantics-unicodematchproperty-p | ||
features: [regexp-unicode-property-escapes] | ||
includes: [regExpUtils.js] | ||
---*/ | ||
|
||
const matchSymbols = buildString({ | ||
loneCodePoints: [], | ||
ranges: [ | ||
[0x000030, 0x000039], | ||
[0x000041, 0x000046], | ||
[0x000061, 0x000066] | ||
] | ||
}); | ||
testPropertyEscapes( | ||
/^\p{ASCII_Hex_Digit}+$/u, | ||
matchSymbols, | ||
"\\p{ASCII_Hex_Digit}" | ||
); | ||
testPropertyEscapes( | ||
/^\p{AHex}+$/u, | ||
matchSymbols, | ||
"\\p{AHex}" | ||
); | ||
|
||
const nonMatchSymbols = buildString({ | ||
loneCodePoints: [], | ||
ranges: [ | ||
[0x00DC00, 0x00DFFF], | ||
[0x000000, 0x00002F], | ||
[0x00003A, 0x000040], | ||
[0x000047, 0x000060], | ||
[0x000067, 0x00DBFF], | ||
[0x00E000, 0x10FFFF] | ||
] | ||
}); | ||
testPropertyEscapes( | ||
/^\P{ASCII_Hex_Digit}+$/u, | ||
nonMatchSymbols, | ||
"\\P{ASCII_Hex_Digit}" | ||
); | ||
testPropertyEscapes( | ||
/^\P{AHex}+$/u, | ||
nonMatchSymbols, | ||
"\\P{AHex}" | ||
); |
Oops, something went wrong.