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.

This is part of my work at the SYSTEMF lab at EPFL.
  • Loading branch information
Aurele-Barriere committed Aug 14, 2024
1 parent 5dc04b7 commit 27b8f1b
Show file tree
Hide file tree
Showing 36 changed files with 628 additions and 1,656 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

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(',')
);
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(',')
);
Loading

0 comments on commit 27b8f1b

Please sign in to comment.