GithubHelp home page GithubHelp logo

test262-parser-tests's Introduction

Parser Tests

This repository contains tests designed for parsers. There are three directories of tests:

  • pass/, which contains syntactically valid ECMAScript programs,
  • early/, which contains programs which match the grammar of ECMAScript but which trigger early errors, and
  • fail/, which contains files which do not match the grammar of ECMAScript.

A fourth directory, pass-explicit/, contains alternative versions of the programs in pass/, for reasons discussed below.

Note that these tests are not intended to be evaluated, only parsed. Most would throw an error if run. Because they are testing syntax without depending on a functioning eval(), they include no metadata; each file is a utf8-encoded sequence of bytes which is to be parsed in full. The file LICENSES.md gives the origin and license of each file.

Equivalence tests

Every file in pass/ has a corresponding file in pass-explicit/ of the same name. The explicit version (in pass-explicit/) is intended to appear as a human might write it, with parentheses included where there could conceivably be unclear precedence.

The two versions of each file should be parsed to structures which are equivalent excepting unnecessary whitespace, comments, grouping parentheses, and semicolons.

Contributing

New pass/ and early/ tests should be normalized using the NPM module normalize-parser-test. pass/ tests should additionally have an explicit version created using the provided node.js program make-explicit.js, which requires node v5 or later.

Add copyright information for new tests to licenses.md.

Sample consumer

Below is a node.js program which checks that a particular choice of parser has the correct behavior for all of the tests in this directory. Note that a parser which does not distinguish between early errors and other invalid syntax should treat the tests in early/ just as they would the tests in fail/.

const fs = require('fs');
const shift = require('shift-parser');
const assert = require('assert');

function parse(src, {isModule, earlyErrors}) {
  (isModule ? shift.parseModule : shift.parseScript)(src, {earlyErrors});
}

let passExcludes = [];
let failExcludes = [];
let earlyExcludes = ['557.script.js', '558.script.js', '559.script.js', '560.script.js', '561.script.js', '563.script.js', '564.script.js', '565.script.js', '566.script.js', '567.script.js', '568.script.js', '569.script.js', '570.script.js', '571.script.js', '572.script.js', '574.script.js', '575.script.js', '576.script.js', '577.script.js', '578.script.js', '579.script.js', '580.script.js', '581.script.js', '582.script.js', '583.script.js', '585.script.js', '586.script.js', '587.script.js', '588.script.js', '589.script.js', '590.script.js', '591.script.js', '592.script.js', '593.script.js', '594.script.js', '596.script.js', '597.script.js', '598.script.js', '599.script.js', '600.script.js', '601.script.js', '602.script.js'];

fs.readdirSync('pass').filter(f => !passExcludes.includes(f)).forEach(f => {
  let firstTree, secondTree;
  assert.doesNotThrow(() => {
    firstTree = parse(
      fs.readFileSync(`pass/${f}`, 'utf8'),
      {isModule: f.match('.module.js'), earlyErrors: true}
    );
  });
  assert.doesNotThrow(() => {
    secondTree = parse(
      fs.readFileSync(`pass-explicit/${f}`, 'utf8'),
      {isModule: f.match('.module.js'), earlyErrors: true}
    );
  });
  assert.deepStrictEqual(firstTree, secondTree);
});

fs.readdirSync('fail').filter(f => !failExcludes.includes(f)).forEach(f => {
  assert.throws(() => {
    parse(
      fs.readFileSync(`fail/${f}`, 'utf8'),
      {isModule: f.match('.module.js'), earlyErrors: false}
    );
  });
});

fs.readdirSync('early').filter(f => !earlyExcludes.includes(f)).forEach(f => {
  assert.doesNotThrow(() => {
    parse(
      fs.readFileSync(`early/${f}`, 'utf8'),
      {isModule: f.match('.module.js'), earlyErrors: false}
    );
  });
  assert.throws(() => {
    parse(
      fs.readFileSync(`early/${f}`, 'utf8'),
      {isModule: f.match('.module.js'), earlyErrors: true}
    );
  });
});

test262-parser-tests's People

Contributors

bakkot avatar shilpi3 avatar michaelficarra avatar jugglinmike avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.