Skip to content

Commit eef923d

Browse files
committed
Clean up tests directory a bit
1 parent ee94634 commit eef923d

File tree

8 files changed

+56
-124
lines changed

8 files changed

+56
-124
lines changed

tests/README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ consists of:
77
* A test file that is parsed or compiled (.ts)
88
* One or multiple automatically generated fixtures generated from the source file
99

10-
Creating a test:
10+
### Creating a test:
1111

1212
* Run `npm run clean` to make sure that the sources are tested instead of the distribution
1313
* Create a new test file (.ts) within the respective directory (see below) that contains your test code
1414
* Follow the instructions below to generate the first fixture(s)
1515
* Make sure the fixture(s) contain exactly what you'd expect
1616

17-
Updating a test:
17+
### Updating a test:
1818

1919
* Run `npm run clean` to make sure that the sources are tested instead of the distribution
2020
* Make changes to the respective test file (.ts)
@@ -54,11 +54,11 @@ Note that the parser suite currently can't recreate just a specific fixture.
5454
Compiler
5555
--------
5656

57-
General directory: [tests/compiler](./compiler)
57+
General directory: [tests/compiler](./compiler)<br />
5858
Standard library directory: [tests/compiler/std](./compiler/std)
5959

60-
The source file is parsed and compiled to a module, validated, interpreted and the resulting module
61-
converted to WebAsssembly text format.
60+
The source file is parsed and compiled to a module, validated and the resulting module converted to
61+
WebAsssembly text format.
6262

6363
The text format output is compared to its fixture and the module interpreted in a WebAssembly VM. To
6464
assert for runtime conditions, the `assert` builtin can be used. Note that tree-shaking is enabled
@@ -94,5 +94,9 @@ $> npm run test:compiler -- testNameWithoutTs --create
9494
Other
9595
-----
9696

97-
Tests in other directories are not run automatically and do not need to be updated. Most of them
98-
are legacy tests.
97+
Tests in other directories are not run automatically and do not need to be updated.
98+
99+
* [tests/allocators](./allocators) contains the memory allocator test suite
100+
* [tests/binaryen](./binaryen) contains various triggers for earlier Binaryen issues
101+
* [tests/tokenizer](./tokenizer.js) is a visual test for the tokenizer tokenizing itself
102+
* [tests/util-path](./util-path.js) is a sanity test for the path utility

tests/bundled-asc.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

tests/i64.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

tests/parser.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require("ts-node").register({ project: require("path").join(__dirname, "..", "sr
77
require("../src/glue/js");
88

99
var Parser = require("../src/parser").Parser;
10-
var serializeSource = require("../src/extra/ast").serializeSource;
10+
var ASTBuilder = require("../src/extra/ast").ASTBuilder;
1111

1212
var isCreate = process.argv[2] === "--create";
1313
var filter = process.argv.length > 2 && !isCreate ? "*" + process.argv[2] + "*.ts" : "**.ts";
@@ -21,13 +21,10 @@ glob.sync(filter, { cwd: __dirname + "/parser" }).forEach(filename => {
2121

2222
var failed = false;
2323
var parser = new Parser();
24-
// parser.silentDiagnostics = true;
2524
var sourceText = fs.readFileSync(__dirname + "/parser/" + filename, { encoding: "utf8" }).replace(/\r?\n/g, "\n").replace(/^\/\/.*\r?\n/mg, "");
2625
parser.parseFile(sourceText, filename, true);
27-
28-
var sb = [];
29-
serializeSource(parser.program.sources[0], sb);
30-
var actual = sb.join("") + parser.diagnostics.map(diagnostic => "// " + diagnostic + "\n").join("");
26+
var serializedSourceText = ASTBuilder.build(parser.program.sources[0]);
27+
var actual = serializedSourceText + parser.diagnostics.map(diagnostic => "// " + diagnostic + "\n").join("");
3128
var fixture = filename + ".fixture.ts";
3229

3330
if (isCreate) {

tests/path.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/tokenizer.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
4+
require("ts-node").register({ project: path.join(__dirname, "..", "src", "tsconfig.json") });
5+
require("../src/glue/js");
6+
7+
const { Tokenizer, Token } = require("../src/tokenizer");
8+
const { Source, SourceKind } = require("../src/ast");
9+
10+
const text = fs.readFileSync(__dirname + "/../src/tokenizer.ts").toString();
11+
const tn = new Tokenizer(new Source("compiler.ts", text, SourceKind.ENTRY));
12+
13+
do {
14+
let token = tn.next();
15+
if (token == Token.IDENTIFIER) {
16+
console.log(Token[token] + " > " + tn.readIdentifier());
17+
} else if (token == Token.INTEGERLITERAL) {
18+
console.log(Token[token] + " > " + tn.readInteger());
19+
} else if (token == Token.FLOATLITERAL) {
20+
console.log(Token[token] + " > " + tn.readFloat());
21+
} else if (token == Token.STRINGLITERAL) {
22+
console.log(Token[token] + " > " + tn.readString());
23+
} else if (token == Token.ENDOFFILE) {
24+
console.log(Token[token]);
25+
break;
26+
} else {
27+
let range = tn.range();
28+
console.log(Token[token] + " > " + range.source.text.substring(range.start, range.end));
29+
}
30+
} while (true);

tests/tokenizer.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

tests/util-path.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const path = require("path");
2+
const assert = require("assert");
3+
4+
require("ts-node").register({ project: path.join(__dirname, "..", "src", "tsconfig.json") });
5+
require("../src/glue/js");
6+
7+
const { normalize, resolve } = require("../src/util/path");
8+
9+
var test = "./Y/./N/./N/../../././../Y/./.";
10+
assert.strictEqual(normalize(test), path.posix.normalize(test));
11+
12+
assert.strictEqual(resolve("../../..", "lib/util/i64.ts"), "..");

0 commit comments

Comments
 (0)