Skip to content

Commit

Permalink
added jison action code test cases. (Running into trouble cf. jestjs/…
Browse files Browse the repository at this point in the history
…jest#2441 while trying to make these work. !@#$%^&*-jest!)
  • Loading branch information
GerHobbelt committed Jun 11, 2018
1 parent f9bcfbf commit bf84c93
Show file tree
Hide file tree
Showing 30 changed files with 135 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/jison-action-codeblocks/action-blocks_0001.js
@@ -0,0 +1 @@
rv = #LABEL#;
1 change: 1 addition & 0 deletions tests/jison-action-codeblocks/action-blocks_0002.js
@@ -0,0 +1 @@
@$ = @1 + 1;
1 change: 1 addition & 0 deletions tests/jison-action-codeblocks/action-blocks_0003.js
@@ -0,0 +1 @@
$$ = $1.tx(`blub: ${$1} @ ${@1} vs. ${@alt_loc}?`);
1 change: 1 addition & 0 deletions tests/jison-action-codeblocks/action-blocks_0004.js
@@ -0,0 +1 @@
yyparser.prettyPrint(`no dice! ${#ID#} is not what you are looking for!`);
4 changes: 4 additions & 0 deletions tests/jison-action-codeblocks/action-blocks_0005.js
@@ -0,0 +1,4 @@
$1.push($2, {
yylloc,
tokens: [#1, #2],
})
2 changes: 2 additions & 0 deletions tests/jison-action-codeblocks/action-blocks_0006.js
@@ -0,0 +1,2 @@
if ($1 > 0) YYCONTINUE
yyerror("B0rk @ " + #STMT)
1 change: 1 addition & 0 deletions tests/jison-action-codeblocks/action-blocks_0014.js
@@ -0,0 +1 @@
$$ = $1.tx(`blub: ${$$1} @ ${@@1} vs. ${##alt_loc}?`);
6 changes: 6 additions & 0 deletions tests/jison-action-codeblocks/action-blocks_0015.js
@@ -0,0 +1,6 @@
// test jison negative index reference variables recognition:
$$ = {
val: $-1 + a.tx(`blub: ${$$-2} @ ${@@-3} vs. ${##-4}?`),
loc: @-5,
idx: #-6,
};
11 changes: 11 additions & 0 deletions tests/jison-action-codeblocks/action-blocks_0016.js
@@ -0,0 +1,11 @@
if ($prec) {
if ($handle.length === 0) {
yyerror(rmCommonWS`
You cannot specify a precedence override for an epsilon (a.k.a. empty) rule!
Erroneous area:
${yylexer.prettyPrintRange(@handle, @0 /* @handle is very probably NULL! We need this one for some decent location info! */, @action /* ditto! */)}
`);
}
$$.push($prec);
}
4 changes: 4 additions & 0 deletions tests/jison-action-codeblocks/action-var-edge-cases_0017.js
@@ -0,0 +1,4 @@
// test jison variable decoding edge cases: accept any number of $ as legal variable names
if ($) {
$$.push($);
}
7 changes: 7 additions & 0 deletions tests/jison-action-codeblocks/action-var-edge-cases_0018.js
@@ -0,0 +1,7 @@
// any jison var referencing current value is okay: $$, @$, #$, ##$, #$#
$$ = 0;
@$.range = [1, 2];
// highly suspect as the next few are considered strictly CONSTANTS/RVALUES in JISON:
#$--;
##$--;
#$#--;
3 changes: 3 additions & 0 deletions tests/jison-action-codeblocks/action-var-edge-cases_0019.js
@@ -0,0 +1,3 @@
// do not confuse jison vars with @def or @@iter ES7/ESX constructs:
@def.start_line = 1;
@@iter.range = [2, 3];
8 changes: 8 additions & 0 deletions tests/jison-action-codeblocks/action-var-edge-cases_0020.js
@@ -0,0 +1,8 @@
// negative index jison variables:
$$ = $-1 + $-2 + $12;
@$ = @-1 + @0;

// babel itself does not have the smarts built in to detect the wrongness in these:
#$ = #-1 + #0;
##$ = ##-1 + ##7;
#$# += #-1# + #0#;
2 changes: 2 additions & 0 deletions tests/jison-action-codeblocks/illegal-action-blocks_0007.js
@@ -0,0 +1,2 @@
// illegal = non-jison identifier:
rv = #1#2#;
2 changes: 2 additions & 0 deletions tests/jison-action-codeblocks/illegal-action-blocks_0008.js
@@ -0,0 +1,2 @@
// illegal = non-jison identifiers:
location@home = 1;
2 changes: 2 additions & 0 deletions tests/jison-action-codeblocks/illegal-action-blocks_0009.js
@@ -0,0 +1,2 @@
// illegal = non-jison markers. These are not identifiers!
rv = #;
2 changes: 2 additions & 0 deletions tests/jison-action-codeblocks/illegal-action-blocks_0010.js
@@ -0,0 +1,2 @@
// illegal = non-jison markers. These are not identifiers!
rv = @;
2 changes: 2 additions & 0 deletions tests/jison-action-codeblocks/illegal-action-blocks_0011.js
@@ -0,0 +1,2 @@
// illegal = non-jison markers. These are not identifiers!
rv = #@;
2 changes: 2 additions & 0 deletions tests/jison-action-codeblocks/illegal-action-blocks_0012.js
@@ -0,0 +1,2 @@
// illegal = non-jison identifier:
rv = a2#;
2 changes: 2 additions & 0 deletions tests/jison-action-codeblocks/illegal-action-blocks_0013.js
@@ -0,0 +1,2 @@
// illegal = non-jison identifier:
rv = a#b;
2 changes: 2 additions & 0 deletions tests/jison-action-codeblocks/illegal-action-blocks_0021.js
@@ -0,0 +1,2 @@
// illegal = non-jison identifier:
rv = a#b;
2 changes: 2 additions & 0 deletions tests/jison-action-codeblocks/illegal-action-blocks_0022.js
@@ -0,0 +1,2 @@
// illegal = non-jison identifier:
rv = @@;
2 changes: 2 additions & 0 deletions tests/jison-action-codeblocks/illegal-action-blocks_0023.js
@@ -0,0 +1,2 @@
// illegal = non-jison identifier:
rv = ##;
2 changes: 2 additions & 0 deletions tests/jison-action-codeblocks/illegal-action-blocks_0025.js
@@ -0,0 +1,2 @@
// illegal = non-jison identifier: yet this decodes as legal JS: `$ - $`
rv = @-@;
43 changes: 43 additions & 0 deletions tests/jison-action-codeblocks/jsfmt.spec.js
@@ -0,0 +1,43 @@
// const defaultOptions = {
// // Source type ("script" or "module") for different semantics
// sourceType: "script",
// // Source filename.
// sourceFilename: undefined,
// // Line from which to start counting source. Useful for
// // integration with other tools.
// startLine: 1,
// // When enabled, await at the top level is not considered an
// // error.
// allowAwaitOutsideFunction: false,
// // When enabled, a return at the top level is not considered an
// // error.
// allowReturnOutsideFunction: false,
// // When enabled, import/export statements are not constrained to
// // appearing at the top of the program.
// allowImportExportEverywhere: false,
// // TODO
// allowSuperOutsideMethod: false,
// // An array of plugins to enable
// plugins: [],
// // TODO
// strictMode: null,
// // Nodes have their start and end characters offsets recorded in
// // `start` and `end` properties (directly on the node, rather than
// // the `loc` object, which holds line/column data. To also add a
// // [semi-standardized][range] `range` property holding a `[start,
// // end]` array with the same numbers, set the `ranges` option to
// // `true`.
// //
// // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
// ranges: false,
// // Adds all parsed tokens to a `tokens` property on the `File` node
// tokens: false,
// // Recognize JISON action block variables, e.g. `#1` or `@id`
// jisonVariables: false,
// };

run_spec(__dirname, ["babylon"], {
parserOptions: {
jisonVariables: true
}
});
2 changes: 2 additions & 0 deletions tests/jison-action-codeblocks/not-jison-yet-legal-JS_0024.js
@@ -0,0 +1,2 @@
// illegal = non-jison identifier: yet this decodes as legal JS: `$ - $`
rv = $-$;
2 changes: 2 additions & 0 deletions tests/jison-action-codeblocks/not-jison-yet-legal-JS_0026.js
@@ -0,0 +1,2 @@
// this decodes as legal JS: `$ - 5`
rv = $- 5;
2 changes: 2 additions & 0 deletions tests/jison-action-codeblocks/not-jison-yet-legal-JS_0027.js
@@ -0,0 +1,2 @@
// this decodes as legal JS: `$ - 5`
rv = $ -5;
1 change: 1 addition & 0 deletions tmp/aficionado
Submodule aficionado added at 9c3946
13 changes: 13 additions & 0 deletions tmp/package.json
@@ -0,0 +1,13 @@
{
"name": "tmp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
}
}

0 comments on commit bf84c93

Please sign in to comment.