mirror of
https://github.com/bendtherules/completion-viz.git
synced 2026-08-18 13:42:51 +00:00
Clone engine262 in /engine262
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
'use strict';
|
||||
|
||||
/* eslint-disable no-await-in-loop */
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const glob = require('glob');
|
||||
const {
|
||||
pass, fail, skip, total,
|
||||
} = require('../base');
|
||||
const {
|
||||
Agent,
|
||||
setSurroundingAgent,
|
||||
ManagedRealm,
|
||||
AbruptCompletion,
|
||||
inspect,
|
||||
} = require('../..');
|
||||
|
||||
const BASE_DIR = path.resolve(__dirname, 'JSONTestSuite');
|
||||
|
||||
const agent = new Agent();
|
||||
setSurroundingAgent(agent);
|
||||
|
||||
function test(filename) {
|
||||
const realm = new ManagedRealm();
|
||||
|
||||
const source = fs.readFileSync(filename, 'utf8');
|
||||
|
||||
let result;
|
||||
try {
|
||||
result = realm.evaluateScript(`'use strict';
|
||||
const source = ${JSON.stringify(source)};
|
||||
JSON.parse(source);
|
||||
`);
|
||||
} catch {
|
||||
// ...
|
||||
}
|
||||
|
||||
const testName = path.basename(filename);
|
||||
|
||||
if (!result || result instanceof AbruptCompletion) {
|
||||
if (testName.startsWith('n_')) {
|
||||
pass();
|
||||
} else if (testName.startsWith('i_')) {
|
||||
skip();
|
||||
} else {
|
||||
fail(testName, inspect(result));
|
||||
}
|
||||
} else {
|
||||
if (testName.startsWith('n_')) {
|
||||
fail(testName, 'JSON parsed but should have failed!');
|
||||
} else {
|
||||
pass();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const tests = glob.sync(`${path.resolve(BASE_DIR, 'test_parsing')}/**/*.json`)
|
||||
.concat(glob.sync(`${path.resolve(BASE_DIR, 'test_transform')}/**/*.json`));
|
||||
|
||||
tests.forEach((t) => {
|
||||
total();
|
||||
test(t);
|
||||
});
|
||||
Reference in New Issue
Block a user