Skip to content

Commit

Permalink
Fix Regex Character Class Escape Tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Aurele-Barriere committed Dec 22, 2024
1 parent c4317b0 commit a91b44f
Show file tree
Hide file tree
Showing 35 changed files with 939 additions and 1,730 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// 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: >
Compare range for digit class escape \d with flags g
Check negative cases of digit class escape \d.
info: |
This is a generated test. Please check out
https://github.com/tc39/test262/tree/main/tools/regexp-generator/
Expand Down Expand Up @@ -45,28 +46,38 @@ includes: [regExpUtils.js]
flags: [generated]
---*/

const str = buildString({
loneCodePoints: [],
ranges: [
[0x000030, 0x000039],
],
});
const str = buildString(
{
loneCodePoints: [],
ranges: [
[0x00DC00, 0x00DFFF],
[0x000000, 0x00002F],
[0x00003A, 0x00DBFF],
[0x00E000, 0x10FFFF]
]
}
);

const re = /\d/g;
const standard = /\d/;
const unicode = /\d/u;
const vflag = /\d/v;
const regexes = [standard,unicode,vflag];

const errors = [];

if (!re.test(str)) {
// Error, let's find out where
for (const char of str) {
if (!re.test(char)) {
errors.push('0x' + char.codePointAt(0).toString(16));
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 matching code points, but received: ' + errors.join(',')
'Expected no match, but matched: ' + errors.join(',')
);
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// 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: >
Compare range for digit class escape \d+ with flags ug
Check positive cases of digit class escape \d.
info: |
This is a generated test. Please check out
https://github.com/tc39/test262/tree/main/tools/regexp-generator/
Expand Down Expand Up @@ -45,28 +46,35 @@ includes: [regExpUtils.js]
flags: [generated]
---*/

const str = buildString({
loneCodePoints: [],
ranges: [
[0x000030, 0x000039],
],
});
const str = buildString(
{
loneCodePoints: [],
ranges: [
[0x000030, 0x000039]
]
}
);

const re = /\d+/ug;
const standard = /^\d+$/;
const unicode = /^\d+$/u;
const vflag = /^\d+$/v;
const regexes = [standard,unicode,vflag];

const errors = [];

if (!re.test(str)) {
// Error, let's find out where
for (const char of str) {
if (!re.test(char)) {
errors.push('0x' + char.codePointAt(0).toString(16));
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 matching code points, but received: ' + errors.join(',')
'Expected full match, but did not match: ' + errors.join(',')
);

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// 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: >
Compare range for digit class escape \d with flags ug
Check negative cases of non-digit class escape \D.
info: |
This is a generated test. Please check out
https://github.com/tc39/test262/tree/main/tools/regexp-generator/
Expand Down Expand Up @@ -45,28 +46,35 @@ includes: [regExpUtils.js]
flags: [generated]
---*/

const str = buildString({
loneCodePoints: [],
ranges: [
[0x000030, 0x000039],
],
});
const str = buildString(
{
loneCodePoints: [],
ranges: [
[0x000030, 0x000039]
]
}
);

const re = /\d/ug;
const standard = /\D/;
const unicode = /\D/u;
const vflag = /\D/v;
const regexes = [standard,unicode,vflag];

const errors = [];

if (!re.test(str)) {
// Error, let's find out where
for (const char of str) {
if (!re.test(char)) {
errors.push('0x' + char.codePointAt(0).toString(16));
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 matching code points, but received: ' + errors.join(',')
'Expected no match, but matched: ' + errors.join(',')
);

This file was deleted.

Loading

0 comments on commit a91b44f

Please sign in to comment.