Skip to content

Commit 1f60c56

Browse files
Aurele-Barriereptomato
authored andcommitted
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 and with the v flag. This uses regenerate.js from the unicode-property-escapes-tests repo to generate strings that contain exactly the characters that are supposed to be matched or not matched for each escape. Comparison is done with regex test instead of regex replace to optimize the tests. This is part of my work at the SYSTEMF lab at EPFL.
1 parent 84f8202 commit 1f60c56

File tree

35 files changed

+939
-1730
lines changed

35 files changed

+939
-1730
lines changed

test/built-ins/RegExp/CharacterClassEscapes/character-class-digit-class-escape.js test/built-ins/RegExp/CharacterClassEscapes/character-class-digit-class-escape-negative-cases.js

+25-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// Copyright (C) 2018 Leo Balter. All rights reserved.
2+
// Copyright (C) 2024 Aurèle Barrière. All rights reserved.
23
// This code is governed by the BSD license found in the LICENSE file.
34

45
/*---
56
esid: prod-CharacterClassEscape
67
description: >
7-
Compare range for digit class escape \d with flags g
8+
Check negative cases of digit class escape \d.
89
info: |
910
This is a generated test. Please check out
1011
https://github.com/tc39/test262/tree/main/tools/regexp-generator/
@@ -45,28 +46,38 @@ includes: [regExpUtils.js]
4546
flags: [generated]
4647
---*/
4748

48-
const str = buildString({
49-
loneCodePoints: [],
50-
ranges: [
51-
[0x000030, 0x000039],
52-
],
53-
});
49+
const str = buildString(
50+
{
51+
loneCodePoints: [],
52+
ranges: [
53+
[0x00DC00, 0x00DFFF],
54+
[0x000000, 0x00002F],
55+
[0x00003A, 0x00DBFF],
56+
[0x00E000, 0x10FFFF]
57+
]
58+
}
59+
);
5460

55-
const re = /\d/g;
61+
const standard = /\d/;
62+
const unicode = /\d/u;
63+
const vflag = /\d/v;
64+
const regexes = [standard,unicode,vflag];
5665

5766
const errors = [];
5867

59-
if (!re.test(str)) {
60-
// Error, let's find out where
61-
for (const char of str) {
62-
if (!re.test(char)) {
63-
errors.push('0x' + char.codePointAt(0).toString(16));
68+
for (const regex of regexes) {
69+
if (regex.test(str)) {
70+
// Error, let's find out where
71+
for (const char of str) {
72+
if (regex.test(char)) {
73+
errors.push('0x' + char.codePointAt(0).toString(16));
74+
}
6475
}
6576
}
6677
}
6778

6879
assert.sameValue(
6980
errors.length,
7081
0,
71-
'Expected matching code points, but received: ' + errors.join(',')
82+
'Expected no match, but matched: ' + errors.join(',')
7283
);

test/built-ins/RegExp/CharacterClassEscapes/character-class-digit-class-escape-plus-quantifier-flags-u.js test/built-ins/RegExp/CharacterClassEscapes/character-class-digit-class-escape-positive-cases.js

+22-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// Copyright (C) 2018 Leo Balter. All rights reserved.
2+
// Copyright (C) 2024 Aurèle Barrière. All rights reserved.
23
// This code is governed by the BSD license found in the LICENSE file.
34

45
/*---
56
esid: prod-CharacterClassEscape
67
description: >
7-
Compare range for digit class escape \d+ with flags ug
8+
Check positive cases of digit class escape \d.
89
info: |
910
This is a generated test. Please check out
1011
https://github.com/tc39/test262/tree/main/tools/regexp-generator/
@@ -45,28 +46,35 @@ includes: [regExpUtils.js]
4546
flags: [generated]
4647
---*/
4748

48-
const str = buildString({
49-
loneCodePoints: [],
50-
ranges: [
51-
[0x000030, 0x000039],
52-
],
53-
});
49+
const str = buildString(
50+
{
51+
loneCodePoints: [],
52+
ranges: [
53+
[0x000030, 0x000039]
54+
]
55+
}
56+
);
5457

55-
const re = /\d+/ug;
58+
const standard = /^\d+$/;
59+
const unicode = /^\d+$/u;
60+
const vflag = /^\d+$/v;
61+
const regexes = [standard,unicode,vflag];
5662

5763
const errors = [];
5864

59-
if (!re.test(str)) {
60-
// Error, let's find out where
61-
for (const char of str) {
62-
if (!re.test(char)) {
63-
errors.push('0x' + char.codePointAt(0).toString(16));
65+
for (const regex of regexes) {
66+
if (!regex.test(str)) {
67+
// Error, let's find out where
68+
for (const char of str) {
69+
if (!regex.test(char)) {
70+
errors.push('0x' + char.codePointAt(0).toString(16));
71+
}
6472
}
6573
}
6674
}
6775

6876
assert.sameValue(
6977
errors.length,
7078
0,
71-
'Expected matching code points, but received: ' + errors.join(',')
79+
'Expected full match, but did not match: ' + errors.join(',')
7280
);

test/built-ins/RegExp/CharacterClassEscapes/character-class-non-digit-class-escape-flags-u.js

-75
This file was deleted.

test/built-ins/RegExp/CharacterClassEscapes/character-class-digit-class-escape-flags-u.js test/built-ins/RegExp/CharacterClassEscapes/character-class-non-digit-class-escape-negative-cases.js

+22-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// Copyright (C) 2018 Leo Balter. All rights reserved.
2+
// Copyright (C) 2024 Aurèle Barrière. All rights reserved.
23
// This code is governed by the BSD license found in the LICENSE file.
34

45
/*---
56
esid: prod-CharacterClassEscape
67
description: >
7-
Compare range for digit class escape \d with flags ug
8+
Check negative cases of non-digit class escape \D.
89
info: |
910
This is a generated test. Please check out
1011
https://github.com/tc39/test262/tree/main/tools/regexp-generator/
@@ -45,28 +46,35 @@ includes: [regExpUtils.js]
4546
flags: [generated]
4647
---*/
4748

48-
const str = buildString({
49-
loneCodePoints: [],
50-
ranges: [
51-
[0x000030, 0x000039],
52-
],
53-
});
49+
const str = buildString(
50+
{
51+
loneCodePoints: [],
52+
ranges: [
53+
[0x000030, 0x000039]
54+
]
55+
}
56+
);
5457

55-
const re = /\d/ug;
58+
const standard = /\D/;
59+
const unicode = /\D/u;
60+
const vflag = /\D/v;
61+
const regexes = [standard,unicode,vflag];
5662

5763
const errors = [];
5864

59-
if (!re.test(str)) {
60-
// Error, let's find out where
61-
for (const char of str) {
62-
if (!re.test(char)) {
63-
errors.push('0x' + char.codePointAt(0).toString(16));
65+
for (const regex of regexes) {
66+
if (regex.test(str)) {
67+
// Error, let's find out where
68+
for (const char of str) {
69+
if (regex.test(char)) {
70+
errors.push('0x' + char.codePointAt(0).toString(16));
71+
}
6472
}
6573
}
6674
}
6775

6876
assert.sameValue(
6977
errors.length,
7078
0,
71-
'Expected matching code points, but received: ' + errors.join(',')
79+
'Expected no match, but matched: ' + errors.join(',')
7280
);

test/built-ins/RegExp/CharacterClassEscapes/character-class-non-digit-class-escape-plus-quantifier-flags-u.js

-75
This file was deleted.

0 commit comments

Comments
 (0)