Skip to content

Commit 73102a3

Browse files
committed
moving test antlr format to its own file
1 parent c079ab2 commit 73102a3

2 files changed

Lines changed: 29 additions & 24 deletions

File tree

tests/config/run-test.js

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { FULL_TEST } from "./constants.js";
2-
import * as failedTests from "./failed-format-tests.js";
32
import { format } from "./run-prettier.js";
43
import consistentEndOfLine from "./utils/consistent-end-of-line.js";
54
import createSnapshot from "./utils/create-snapshot.js";
@@ -9,11 +8,9 @@ import * as testBom from "./test-bom.js";
98
import * as testEndOfLine from "./test-end-of-line.js";
109
import * as testSecondFormat from "./test-second-format.js";
1110
import * as testBytecodeCompare from "./test-bytecode-compare.js";
11+
import * as testAntlrFormat from "./test-antlr-format.js";
1212
import * as testVariantCoverage from "./test-variant-coverage.js";
1313
import { shouldThrowOnFormat } from "./utilities.js";
14-
import getPrettier from "./get-prettier.js";
15-
import getCreateParser from "./get-create-parser.js";
16-
import getPlugins from "./get-plugins.js";
1714

1815
async function runTest({
1916
parsers,
@@ -67,26 +64,7 @@ async function runTest({
6764
if (!FULL_TEST) {
6865
return;
6966
}
70-
71-
if (formatOptions.parser === "slang") {
72-
const createParser = await getCreateParser();
73-
const { parser } = createParser(code, formatOptions);
74-
75-
if (!failedTests.isAntlrMismatch(filename, formatOptions)) {
76-
// Compare with ANTLR's format
77-
const prettier = await getPrettier();
78-
const { formatted: antlrOutput } = await prettier.formatWithCursor(code, {
79-
...formatOptions,
80-
// Since Slang forces us to decide on a compiler version, we need to do the
81-
// same for ANTLR unless it was already given as an option.
82-
compiler: formatOptions.compiler || parser.languageVersion,
83-
parser: "antlr",
84-
plugins: await getPlugins(),
85-
});
86-
expect(antlrOutput).toEqual(formatResult.output);
87-
}
88-
}
89-
67+
await testAntlrFormat.run(code, formatResult, filename, formatOptions);
9068
await testVariantCoverage.run(code, formatResult, filename, formatOptions);
9169
await testSecondFormat.run(code, formatResult, filename, formatOptions);
9270
await testAstCompare.run(code, formatResult, filename, formatOptions);

tests/config/test-antlr-format.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as failedTests from "./failed-format-tests.js";
2+
import getPrettier from "./get-prettier.js";
3+
import getCreateParser from "./get-create-parser.js";
4+
import getPlugins from "./get-plugins.js";
5+
6+
async function testAntlrFormat(source, formatResult, filename, formatOptions) {
7+
if (
8+
formatOptions.parser === "slang" &&
9+
!failedTests.isAntlrMismatch(filename, formatOptions)
10+
) {
11+
// Compare with ANTLR's format
12+
const createParser = await getCreateParser();
13+
const { parser } = createParser(source, formatOptions);
14+
const prettier = await getPrettier();
15+
const { formatted: antlrOutput } = await prettier.formatWithCursor(source, {
16+
...formatOptions,
17+
// Since Slang forces us to decide on a compiler version, we need to do the
18+
// same for ANTLR unless it was already given as an option.
19+
compiler: formatOptions.compiler || parser.languageVersion,
20+
parser: "antlr",
21+
plugins: await getPlugins(),
22+
});
23+
expect(antlrOutput).toEqual(formatResult.output);
24+
}
25+
}
26+
27+
export { testAntlrFormat as run };

0 commit comments

Comments
 (0)