-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Regex Character Class Escape Tests
For each character class escape (\d, \D, \s, \S, \w, \W), check positive cases (the escape matches all characters it's supposed to match) and negative cases (the escape doesn't match any of the characters it should not match). Each of these checks is also done in Unicode mode. This is part of my work at the SYSTEMF lab at EPFL.
- Loading branch information
1 parent
5dc04b7
commit 27b8f1b
Showing
36 changed files
with
628 additions
and
1,656 deletions.
There are no files selected for viewing
64 changes: 0 additions & 64 deletions
64
test/built-ins/RegExp/CharacterClassEscapes/character-class-digit-class-escape-flags-u.js
This file was deleted.
Oops, something went wrong.
64 changes: 0 additions & 64 deletions
64
...egExp/CharacterClassEscapes/character-class-digit-class-escape-plus-quantifier-flags-u.js
This file was deleted.
Oops, something went wrong.
64 changes: 0 additions & 64 deletions
64
...lt-ins/RegExp/CharacterClassEscapes/character-class-digit-class-escape-plus-quantifier.js
This file was deleted.
Oops, something went wrong.
64 changes: 0 additions & 64 deletions
64
test/built-ins/RegExp/CharacterClassEscapes/character-class-digit-class-escape.js
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
test/built-ins/RegExp/CharacterClassEscapes/character-class-digit-negative-cases.js
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,47 @@ | ||
// Copyright (C) 2018 Leo Balter. All rights reserved. | ||
// Copyright (C) 2024 Aurèle Barrière. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: prod-CharacterClassEscape | ||
description: Check that none of the non-digit characters are matched by \d. | ||
info: | | ||
21.2.2.12 CharacterClassEscape | ||
The production CharacterClassEscape :: d evaluates as follows: | ||
Return the ten-element set of characters containing the characters 0 through 9 inclusive. | ||
features: [String.fromCodePoint] | ||
includes: [regExpUtils.js] | ||
---*/ | ||
|
||
const str = buildString({ | ||
loneCodePoints: [], | ||
ranges: [ | ||
[0x000000, 0x00002F], | ||
[0x00003A, 0x10FFFF], | ||
], | ||
}); | ||
|
||
const re = /\d/; | ||
const re_u = /\d/u; | ||
|
||
const regexes = [re, re_u]; | ||
|
||
const errors = []; | ||
|
||
for (const regex of regexes) { | ||
if (regex.test(str)) { | ||
// Error, let's find out where | ||
for (const char of str) { | ||
if (regex.test(char)) { | ||
errors.push('0x' + char.codePointAt(0).toString(16)); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
assert.sameValue( | ||
errors.length, | ||
0, | ||
'Expected no match, but matched: ' + errors.join(',') | ||
); |
46 changes: 46 additions & 0 deletions
46
test/built-ins/RegExp/CharacterClassEscapes/character-class-digit-positive-cases.js
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,46 @@ | ||
// Copyright (C) 2018 Leo Balter. All rights reserved. | ||
// Copyright (C) 2024 Aurèle Barrière. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: prod-CharacterClassEscape | ||
description: Check that all digit characters are matched by \d. | ||
info: | | ||
21.2.2.12 CharacterClassEscape | ||
The production CharacterClassEscape :: d evaluates as follows: | ||
Return the ten-element set of characters containing the characters 0 through 9 inclusive. | ||
features: [String.fromCodePoint] | ||
includes: [regExpUtils.js] | ||
---*/ | ||
|
||
const str = buildString({ | ||
loneCodePoints: [], | ||
ranges: [ | ||
[0x0030, 0x0039], | ||
], | ||
}); | ||
|
||
const re = /^\d+$/; | ||
const re_u = /^\d+$/u; | ||
|
||
const regexes = [re, re_u]; | ||
|
||
const errors = []; | ||
|
||
for (const regex of regexes) { | ||
if (!regex.test(str)) { | ||
// Error, let's find out where | ||
for (const char of str) { | ||
if (!regex.test(char)) { | ||
errors.push('0x' + char.codePointAt(0).toString(16)); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
assert.sameValue( | ||
errors.length, | ||
0, | ||
'Expected full match, but did not match: ' + errors.join(',') | ||
); |
Oops, something went wrong.