Skip to content

Commit

Permalink
Run validStrings.mjs
Browse files Browse the repository at this point in the history
  • Loading branch information
jessealama authored and ptomato committed Feb 23, 2022
1 parent 53dc34b commit ba29843
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 23 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,16 @@ jobs:
node-version: 12.x
- run: npm ci
- run: npm run test-cookbook
test-validstrings:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: use node.js v16.x
uses: actions/setup-node@v1
with:
node-version: 16.x
- run: npm ci
- run: |
cd polyfill
npm install
node --experimental-modules --no-warnings --icu-data-dir ./node_modules/full-icu/ test/validStrings.mjs
51 changes: 28 additions & 23 deletions polyfill/test/validStrings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -450,29 +450,34 @@ const comparisonItems = {
};
const plainModes = ['Date', 'DateTime', 'MonthDay', 'Time', 'YearMonth'];

const mode = 'Instant';

for (let count = 0; count < 1000; count++) {
let generatedData, fuzzed;
do {
generatedData = {};
fuzzed = goals[mode].generate(generatedData);
} while (plainModes.includes(mode) && /[0-9][zZ]/.test(fuzzed));
try {
const parsed = ES[`ParseTemporal${mode}String`](fuzzed);
for (let prop of comparisonItems[mode]) {
let expected = generatedData[prop];
if (prop !== 'ianaName' && prop !== 'offset' && prop !== 'calendar') expected = expected || 0;
assert.equal(parsed[prop], expected);
}
console.log(`${fuzzed} => ok`);
} catch (e) {
if (e instanceof assert.AssertionError) {
console.log(`${fuzzed} => parsed wrong: expected`, e.expected, 'actual', e.actual);
console.log('generated data:', generatedData);
} else {
console.log(`${fuzzed} failed!`, e);
function fuzzMode(mode) {
console.log('// starting to fuzz ' + mode);
for (let count = 0; count < 1000; count++) {
let generatedData, fuzzed;
do {
generatedData = {};
fuzzed = goals[mode].generate(generatedData);
} while (plainModes.includes(mode) && /[0-9][zZ]/.test(fuzzed));
try {
const parsed = ES[`ParseTemporal${mode}String`](fuzzed);
for (let prop of comparisonItems[mode]) {
let expected = generatedData[prop];
if (prop !== 'ianaName' && prop !== 'offset' && prop !== 'calendar') expected = expected || 0;
assert.equal(parsed[prop], expected);
}
console.log(`${fuzzed} => ok`);
} catch (e) {
if (e instanceof assert.AssertionError) {
console.log(`${fuzzed} => parsed wrong: expected`, e.expected, 'actual', e.actual);
console.log('generated data:', generatedData);
} else {
console.log(`${fuzzed} failed!`, e);
}
return 0;
}
break;
}
console.log('// done fuzzing ' + mode);
return 1;
}

Object.keys(goals).every(fuzzMode);

0 comments on commit ba29843

Please sign in to comment.