Skip to content

Commit

Permalink
Runtime API tests done
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-lischke committed Jan 23, 2024
1 parent 827d0c0 commit 6370cc8
Show file tree
Hide file tree
Showing 21 changed files with 524 additions and 197 deletions.
34 changes: 28 additions & 6 deletions runtime-testsuite/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,34 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

import { TestTokenStreamRewriter } from "./src/tests/api/TestTokenStreamRewriter.js";
import { TestCodePointCharStream } from "./src/api/TestCodePointCharStream.js";
import { TestInterpreterDataReader } from "./src/api/TestInterpreterDataReader.js";
import { TestTokenStream } from "./src/api/TestTokenStream.js";
import { TestTokenStreamRewriter } from "./src/api/TestTokenStreamRewriter.js";
import { TestVisitors } from "./src/api/TestVisitors.js";
import { TestNG } from "./utils/TestNG.js";

describe("Direct API Tests", () => {
describe("TokenStreamRewriter", () => {
const testNG = new TestNG();
testNG.run(TestTokenStreamRewriter);
});
describe("TokenStreamRewriter", () => {
const testNG = new TestNG();
testNG.run(TestTokenStreamRewriter);
});

describe("TestTokenStream", () => {
const testNG = new TestNG();
testNG.run(TestTokenStream);
});

describe("TestVisitors", () => {
const testNG = new TestNG();
testNG.run(TestVisitors);
});

describe("TestCodePointCharStream", () => {
const testNG = new TestNG();
testNG.run(TestCodePointCharStream);
});

describe("TestInterpreterDataReader", () => {
const testNG = new TestNG();
testNG.run(TestInterpreterDataReader);
});
47 changes: 47 additions & 0 deletions runtime-testsuite/src/api/TestInterpreterDataReader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* java2ts: keep */

/*
* Copyright (c) 2012-2022 The ANTLR Project. All rights reserved.
* Use of this file is governed by the BSD 3-clause license that
* can be found in the LICENSE.txt file in the project root.
*/

import fs from "fs";

import { InterpreterDataReader } from "antlr4ng";

import { Test } from "../../utils/decorators.js";
import { assertEquals } from "../../utils/junit.js";

/**
* This file represents a simple sanity checks on the parsing of the .interp file
* available to the Java runtime for interpreting rather than compiling and executing parsers.
*/
export class TestInterpreterDataReader {
@Test
public testLexerFile(): void {
const content = fs.readFileSync("runtime-testsuite/generated/VisitorCalcLexer.interp", "utf-8");

const interpreterData = InterpreterDataReader.parseInterpreterData(content);

assertEquals(6, interpreterData.vocabulary.getMaxTokenType());
assertEquals(["INT", "MUL", "DIV", "ADD", "SUB", "WS"], interpreterData.ruleNames);
assertEquals([null, null, "'*'", "'/'", "'+'", "'-'", null], interpreterData.vocabulary.getLiteralNames());
assertEquals([null, "INT", "MUL", "DIV", "ADD", "SUB", "WS"], interpreterData.vocabulary.getSymbolicNames());
assertEquals(["DEFAULT_TOKEN_CHANNEL", "HIDDEN"], interpreterData.channels);
assertEquals(["DEFAULT_MODE"], interpreterData.modes);
}

@Test
public testParserFile(): void {
const content = fs.readFileSync("runtime-testsuite/generated/VisitorCalc.interp", "utf-8");

const interpreterData = InterpreterDataReader.parseInterpreterData(content);

assertEquals(6, interpreterData.vocabulary.getMaxTokenType());
assertEquals(["s", "expr"], interpreterData.ruleNames);
assertEquals([null, null, "'*'", "'/'", "'+'", "'-'", null], interpreterData.vocabulary.getLiteralNames());
assertEquals([null, "INT", "MUL", "DIV", "ADD", "SUB", "WS"], interpreterData.vocabulary.getSymbolicNames());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
* can be found in the LICENSE.txt file in the project root.
*/

import { BufferedTokenStream, CharStreams, Token, type TokenStream } from "antlr4ng";
import { BufferedTokenStream, CharStreams, Token } from "antlr4ng";

import { Test } from "../../../utils/decorators.js";
import { VisitorBasicLexer } from "../../../generated/VisitorBasicLexer.js";
import { assertEquals } from "../../../utils/junit.js";
import { Test } from "../../utils/decorators.js";
import { VisitorBasicLexer } from "../../generated/VisitorBasicLexer.js";
import { assertEquals } from "../../utils/junit.js";

/**
* This class contains tests for specific API functionality in {@link TokenStream} and derived types.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

import { CommonTokenStream, TokenStreamRewriter, Interval, CharStreams, Lexer, CharStream } from "antlr4ng";

import { Test } from "../../../utils/decorators.js";
import { assertEquals, assertNotNull } from "../../../utils/junit.js";
import { Test } from "../../utils/decorators.js";
import { assertEquals, assertNotNull } from "../../utils/junit.js";

import { T1 } from "../../../generated/T1.js";
import { T2 } from "../../../generated/T2.js";
import { T3 } from "../../../generated/T3.js";
import { T1 } from "../../generated/T1.js";
import { T2 } from "../../generated/T2.js";
import { T3 } from "../../generated/T3.js";

/**
* @param lexerClass The lexer class to use.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import {
TerminalNode, CharStreams, Token, ATNSimulator, RuleContext,
} from "antlr4ng";

import { Test } from "../../../utils/decorators.js";
import { VisitorBasicLexer } from "../../../generated/VisitorBasicLexer.js";
import { VisitorBasicParser } from "../../../generated/VisitorBasicParser.js";
import { VisitorBasicVisitor } from "../../../generated/VisitorBasicVisitor.js";
import { assertEquals } from "../../../utils/junit.js";
import { VisitorCalcLexer } from "../../../generated/VisitorCalcLexer.js";
import { Test } from "../../utils/decorators.js";
import { VisitorBasicLexer } from "../../generated/VisitorBasicLexer.js";
import { VisitorBasicParser } from "../../generated/VisitorBasicParser.js";
import { VisitorBasicVisitor } from "../../generated/VisitorBasicVisitor.js";
import { assertEquals } from "../../utils/junit.js";
import { VisitorCalcLexer } from "../../generated/VisitorCalcLexer.js";
import {
AddContext, MultiplyContext, NumberContext, SContext, VisitorCalcParser,
} from "../../../generated/VisitorCalcParser.js";
import { VisitorCalcVisitor } from "../../../generated/VisitorCalcVisitor.js";
} from "../../generated/VisitorCalcParser.js";
import { VisitorCalcVisitor } from "../../generated/VisitorCalcVisitor.js";

export class TestVisitors {

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { basename } from "path";
import { CharStream, CharStreams, CommonTokenStream, Lexer } from "antlr4ng";
import { printf } from "fast-printf";

import { JavaLexer } from "../../../../generated/JavaLexer.js";
import { graphemesLexer } from "../../../../generated/graphemesLexer.js";
import { JavaLexer } from "../../../generated/JavaLexer.js";
import { graphemesLexer } from "../../../generated/graphemesLexer.js";

// cspell: ignore udhr

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions runtime-testsuite/src/helpers/Character.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,10 @@ export class Character {
return isUpperCase(c);
}

public static isISOControl(c: number): boolean {
return c <= 0x1F || (c >= 0x7F && c <= 0x9F);
}

/**
* Converts the specified surrogate pair to its supplementary code point value.
*
Expand Down
1 change: 0 additions & 1 deletion runtime-testsuite/src/helpers/package_js.json

This file was deleted.

9 changes: 0 additions & 9 deletions runtime-testsuite/src/helpers/package_ts.json

This file was deleted.

57 changes: 0 additions & 57 deletions runtime-testsuite/src/tests/TestInterpreterDataReader.ts

This file was deleted.

88 changes: 0 additions & 88 deletions runtime-testsuite/src/tests/TsNodeRunner.ts

This file was deleted.

17 changes: 0 additions & 17 deletions runtime-testsuite/src/tests/TypeScriptRuntimeTests.ts

This file was deleted.

Loading

0 comments on commit 6370cc8

Please sign in to comment.