ecma-parser-tests
v0.1.9
Published
Test cases for ECMAScript parsers
Downloads
11
Maintainers
Readme
ECMA-262 Parser Tests
This repository contains a bunch of ECMAScript tests, copied from the Test262 repo
and changed so it can be used together
with any ECMAScript parser.
All tests in this repo are up to date with latest ECMAScript specs (ES2017) and it is parser independent.
Note!! Tests for module code are marked with .module
.
| Directory | Description |
| ----------- | ------------------------------------------------------------ |
| pass
| Contains syntactically valid ECMAScript programs copied form Test262 repo |
| early
| Contains programs which match the grammar of ECMAScript but which trigger early errors |
| fail
| Contains files which do not match the grammar of ECMAScript |
| next
| Contains Stage 3 proposal tests. Separated from Test262
. Each of the tests has three sub-directories - pass
, fail
, early
|
| annexb
| Contains AnnexB tests. Each of the tests has three sub-directories - pass
, fail
, early
|
Configure
One way to get the tests running is to follow the example below. In this example Cherow have been used as the ECMAScript parser, but all parsers should work as long as they support the latest ECMAScript features (ES2017).
Note! It's a quick 5 minutes task to get this tests running on your project, but be aware that you would need to create a whitelist to skip tests that your parser doesn't parse correctly.
import { parseScript} from '../../../src/cherow';
import { readdirSync, readFileSync } from 'fs';
import whitelist from './whitelist'; // Your own whitelist file
import * as t from 'assert';
const EcmaParserTestDir = 'node_modules/ecma-parser-tests';
const parse = (src, module) => (module ? parseModule : parseScript)(src);
const isModule = (val) => /\.module\.js/.test(val);
describe('Test262 Parser tests', () => {
describe('Pass', () => {
for (const f of readdirSync(`${EcmaParserTestDir}/pass`)) {
if (whitelist.pass.indexOf(f) !== -1) continue;
it(`Should pass - [${f}]`, () => {
const passSrc = readFileSync(`${EcmaParserTestDir}/pass/${f}`, 'utf8');
t.doesNotThrow(() => {
parse(passSrc, isModule(f));
});
});
}
});
describe('Fail', () => {
for (const f of readdirSync(`${EcmaParserTestDir}/fail`)) {
if (whitelist.fail.indexOf(f) !== -1) continue;
it(`Should fail on - [${f}]`, () => {
const passSrc = readFileSync(`${EcmaParserTestDir}/fail/${f}`, 'utf8');
t.throws(() => {
parse(passSrc, isModule(f));
});
});
}
});
describe('Early errors', () => {
for (const f of readdirSync(`${EcmaParserTestDir}/early`)) {
if (whitelist.early.indexOf(f) !== -1) continue;
const passTestFile = `${EcmaParserTestDir}/early/${f}`;
it(`should fail on early error [${f}]`, () => {
const passSrc = readFileSync(`${EcmaParserTestDir}/early/${f}`, 'utf8');
t.throws(() => {
parse(passSrc, isModule(f));
});
});
}
});
describe('AnnexB - Pass', () => {
for (const f of readdirSync(`${EcmaParserTestDir}/annexb/pass`)) {
if (whitelist.annexb_pass.indexOf(f) !== -1) continue;
it(`Should pass - [${f}]`, () => {
const passSrc = readFileSync(`${EcmaParserTestDir}/annexb/pass/${f}`, 'utf8');
t.doesNotThrow(() => {
parse(passSrc, isModule(f));
});
});
}
});
describe('AnnexB - Fail', () => {
for (const f of readdirSync(`${EcmaParserTestDir}/annexb/fail`)) {
if (whitelist.annexb_fail.indexOf(f) !== -1) continue;
it(`Should fail on - [${f}]`, () => {
const passSrc = readFileSync(`${EcmaParserTestDir}/annexb/fail/${f}`, 'utf8');
t.throws(() => {
parse(passSrc, isModule(f));
});
});
}
});
describe('Next - Pass', () => {
for (const f of readdirSync(`${EcmaParserTestDir}/next/pass`)) {
if (expectations.next_pass.indexOf(f) !== -1) continue;
it(`Should pass - [${f}]`, () => {
const passSrc = readFileSync(`${EcmaParserTestDir}/next/pass/${f}`, 'utf8');
t.doesNotThrow(() => {
parse(passSrc, /\.module\.js/.test(f));
});
});
}
});
describe('Next - Fail', () => {
for (const f of readdirSync(`${EcmaParserTestDir}/next/fail`)) {
if (whitelist.next_fail.indexOf(f) !== -1) continue;
it(`Should fail on - [${f}]`, () => {
const passSrc = readFileSync(`${EcmaParserTestDir}/next/fail/${f}`, 'utf8');
t.throws(() => {
parse(passSrc, isModule(f));
});
});
}
});
});
Your whitelist:
export default {
pass: [
'1.js' // skips the first passing test
],
fail: [],
early: [],
annexb_pass: [],
annexb_fail: [],
next_pass: [],
next_fail: []
}