Skip to content

Commit

Permalink
other: Split core functionality tests into separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
Luna-Klatzer committed Nov 29, 2024
1 parent 492008d commit 145a572
Show file tree
Hide file tree
Showing 29 changed files with 2,247 additions and 2,040 deletions.
4 changes: 2 additions & 2 deletions test/module/core/built-ins.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { CompileConfig, KipperCompileResult, KipperError } from "@kipper/co
import { KipperCompiler, KipperFileStream } from "@kipper/core";
import { assert } from "chai";
import * as ts from "typescript";
import { testPrintOutput } from "./core-functionality.test";
import { testPrintOutput } from "./index";

/**
* Returns the JavaScript code from the given Kipper compilation result.
Expand Down Expand Up @@ -179,7 +179,7 @@ describe("Built-ins", () => {
assert.equal(result.programCtx!!.builtInVariableReferences.length, 1);

const code: string = getJSEvalCode(result);
testPrintOutput((out) => assert.equal(out, "test.kip"), code);
testPrintOutput((out: any) => assert.equal(out, "test.kip"), code);
});

it("NaN", async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/module/core/compiler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as ts from "typescript";
import * as path from "path";
import { KipperTypeScriptTarget, TargetTS } from "@kipper/target-ts";
import { KipperJavaScriptTarget } from "@kipper/target-js";
import { testPrintOutput } from "./core-functionality.test";
import { testPrintOutput } from "./index";

export function getFileName(pathString: string): string {
return path.resolve(`${__dirname}/../../kipper-files/${pathString}`);
Expand Down
2,037 changes: 0 additions & 2,037 deletions test/module/core/core-functionality.test.ts

This file was deleted.

62 changes: 62 additions & 0 deletions test/module/core/core-functionality/arrays.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import type { KipperCompileResult } from "@kipper/core";
import { KipperCompiler } from "@kipper/core";

Check warning on line 2 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (22.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (20.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (20.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (22.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (20.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (22.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (18.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (18.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (18.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / run (16.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (18.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (16.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (20.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (16.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (22.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (16.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / run (16.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (16.x)

'KipperCompiler' is defined but never used
import { assert } from "chai";
import * as ts from "typescript";
import { KipperTypeScriptTarget } from "@kipper/target-ts";

Check warning on line 5 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (22.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (20.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (20.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (22.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (20.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (22.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (18.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (18.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (18.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / run (16.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (18.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (16.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (20.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (16.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (22.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (16.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / run (16.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (16.x)

'KipperTypeScriptTarget' is defined but never used
import { jsConfig } from "../errors";

Check warning on line 6 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (22.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (20.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (20.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (22.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (20.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (22.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (18.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (18.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (18.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / run (16.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (18.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (16.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (20.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (16.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (22.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (16.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / run (16.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/arrays.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (16.x)

'jsConfig' is defined but never used
import { ScriptTarget } from "typescript";
import { compiler, defaultTarget } from ".";
import { testPrintOutput } from "..";

describe("Arrays", () => {
it("Simple array declaration", async () => {
const fileContent = `var x: Array<num> = [1, 2, 3];`;
const instance: KipperCompileResult = await compiler.compile(fileContent, { target: defaultTarget });

assert.isDefined(instance.programCtx);
assert.deepEqual(instance.programCtx?.errors, [], "Expected no compilation errors");

const code = instance.write();
assert.include(
code,
"let x: Array<number> = __kipper.assignTypeMeta([1, 2, 3],__kipper.builtIn.Array.changeGenericTypeArguments({T: __kipper.builtIn.num}));",
"Invalid TypeScript code (Expected different output)",
);
});

it("Assign array to array", async () => {
const code = "var x: Array<num> = [1, 2, 3]; var y: Array<num> = x;";
const instance: KipperCompileResult = await compiler.compile(code, { target: defaultTarget });

assert.isDefined(instance.programCtx);
assert.deepEqual(instance.programCtx?.errors, [], "Expected no compilation errors");

const jsCode = instance.write();
assert.include(
jsCode,
`let x: Array<number> = __kipper.assignTypeMeta([1, 2, 3],__kipper.builtIn.Array.changeGenericTypeArguments({T: __kipper.builtIn.num}));\nlet y: Array<number> = x;`,
);
});

it("Accessing array element", async () => {
const code = "var x: Array<num> = [1, 2, 3]; print(x[1] as str);";
const instance: KipperCompileResult = await compiler.compile(code, { target: defaultTarget });

assert.isDefined(instance.programCtx);
assert.deepEqual(instance.programCtx?.errors, [], "Expected no compilation errors");

const jsCode = ts.transpile(instance.write(), { target: ScriptTarget.ES2015 });
testPrintOutput((message: any) => assert.equal(message, "2", "Expected different output"), jsCode);
});

it("Assigning one array element to another", async () => {
const code = "var x: Array<num> = [1, 2, 3]; var y: num = x[1]; print(y as str);";
const instance: KipperCompileResult = await compiler.compile(code, { target: defaultTarget });

assert.isDefined(instance.programCtx);
assert.deepEqual(instance.programCtx?.errors, [], "Expected no compilation errors");

const jsCode = ts.transpile(instance.write(), { target: ScriptTarget.ES2015 });
testPrintOutput((message: any) => assert.equal(message, "2", "Expected different output"), jsCode);
});
});
94 changes: 94 additions & 0 deletions test/module/core/core-functionality/assignment.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import type { KipperCompileResult } from "@kipper/core";
import { KipperCompiler } from "@kipper/core";

Check warning on line 2 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (22.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (20.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (20.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (22.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (20.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (22.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (18.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (18.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (18.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / run (16.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (18.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (16.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (20.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (16.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (22.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (16.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / run (16.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (16.x)

'KipperCompiler' is defined but never used
import { assert } from "chai";
import * as ts from "typescript";
import { KipperTypeScriptTarget } from "@kipper/target-ts";

Check warning on line 5 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (22.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (20.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (20.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (22.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (20.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (22.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (18.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (18.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (18.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / run (16.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (18.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (16.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (20.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (16.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (22.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (16.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / run (16.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (16.x)

'KipperTypeScriptTarget' is defined but never used
import { jsConfig } from "../errors";

Check warning on line 6 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (22.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (20.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (20.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (22.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (20.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (22.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (18.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (18.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (18.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / run (16.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (18.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (16.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (20.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (16.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (22.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (16.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / run (16.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/assignment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (16.x)

'jsConfig' is defined but never used
import { ScriptTarget } from "typescript";
import { compiler, defaultTarget } from ".";
import { testPrintOutput } from "..";

describe("Assignment", () => {
it("to 'num'", async () => {
const fileContent = "var x: num = 4;\nx = 5;";
const instance: KipperCompileResult = await compiler.compile(fileContent, { target: defaultTarget });

assert.isDefined(instance.programCtx);
assert.deepEqual(instance.programCtx?.errors, [], "Expected no compilation errors");
assert(
instance.write().includes("let x: number = 4;\nx = 5;"),
"Invalid TypeScript code (Expected different output)",
);
});

it("to 'str'", async () => {
const fileContent = 'var x: str = "4";\nx = "5";';
const instance: KipperCompileResult = await compiler.compile(fileContent, { target: defaultTarget });

assert.isDefined(instance.programCtx);
assert.deepEqual(instance.programCtx?.errors, [], "Expected no compilation errors");
assert(
instance.write().includes('let x: string = "4";\nx = "5";'),
"Invalid TypeScript code (Expected different output)",
);
});

it("to 'bool'", async () => {
const fileContent = "var x: bool = true;\nx = false;";
const instance: KipperCompileResult = await compiler.compile(fileContent, { target: defaultTarget });

assert.isDefined(instance.programCtx);
assert.deepEqual(instance.programCtx?.errors, [], "Expected no compilation errors");
assert(
instance.write().includes("let x: boolean = true;\nx = false;"),
"Invalid TypeScript code (Expected different output)",
);
});

it("to 'array'", async () => {
const fileContent = "var x: Array<num> = [1, 2, 3];\nx = [4, 5, 6];";
const instance: KipperCompileResult = await compiler.compile(fileContent, { target: defaultTarget });

assert.isDefined(instance.programCtx);
assert.deepEqual(instance.programCtx?.errors, [], "Expected no compilation errors");
assert(
instance
.write()
.includes(
"let x: Array<number> = __kipper.assignTypeMeta([1, 2, 3],__kipper.builtIn.Array.changeGenericTypeArguments({T: __kipper.builtIn.num}));\nx = __kipper.assignTypeMeta([4, 5, 6],__kipper.builtIn.Array.changeGenericTypeArguments({T: __kipper.builtIn.num}));",
),
"Invalid TypeScript code (Expected different output)",
);
});

it("to 'func'", async () => {
const fileContent = "var x: Func<str, void> = print;\nx = print;";
const instance: KipperCompileResult = await compiler.compile(fileContent, { target: defaultTarget });

assert.isDefined(instance.programCtx);
assert.deepEqual(instance.programCtx?.errors, [], "Expected no compilation errors");
assert(
instance.write().includes("let x: (arg0: string) => void = __kipper.print;\nx = __kipper.print;"),
"Invalid TypeScript code (Expected different output)",
);
});

it("to 'array[]'", async () => {
const fileContent = "var x: Array<num> = [1, 2, 3];\nx[0] = 4;\nprint(x[0]);";
const instance: KipperCompileResult = await compiler.compile(fileContent, { target: defaultTarget });

assert.isDefined(instance.programCtx);
assert.deepEqual(instance.programCtx?.errors, [], "Expected no compilation errors");
assert(
instance
.write()
.includes(
"let x: Array<number> = __kipper.assignTypeMeta([1, 2, 3],__kipper.builtIn.Array.changeGenericTypeArguments({T: __kipper.builtIn.num}));\nx[0] = 4;",
),
"Invalid TypeScript code (Expected different output)",
);

const jsCode = ts.transpile(instance.write(), { target: ScriptTarget.ES2015 });
testPrintOutput((message: any) => assert.equal(message, "4", "Expected different output"), jsCode);
});
});
171 changes: 171 additions & 0 deletions test/module/core/core-functionality/class.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import type { KipperCompileResult } from "@kipper/core";
import { KipperCompiler } from "@kipper/core";

Check warning on line 2 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (22.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (20.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (20.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (22.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (20.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (22.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (18.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (18.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (18.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / run (16.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (18.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (16.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (20.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (16.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (22.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (16.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / run (16.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (16.x)

'KipperCompiler' is defined but never used
import { assert } from "chai";
import * as ts from "typescript";
import { KipperTypeScriptTarget } from "@kipper/target-ts";

Check warning on line 5 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (22.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (20.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (20.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (22.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (20.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (22.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (18.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (18.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (18.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / run (16.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (18.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (16.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (20.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (16.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (22.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (16.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / run (16.x)

'KipperTypeScriptTarget' is defined but never used

Check warning on line 5 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (16.x)

'KipperTypeScriptTarget' is defined but never used
import { jsConfig } from "../errors";

Check warning on line 6 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (22.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (20.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (20.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (22.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (20.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (22.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (18.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (18.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (18.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / run (16.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (18.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (16.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (20.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (16.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (22.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (16.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / run (16.x)

'jsConfig' is defined but never used

Check warning on line 6 in test/module/core/core-functionality/class.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (16.x)

'jsConfig' is defined but never used
import { ScriptTarget } from "typescript";
import { compiler, defaultTarget } from ".";
import { testPrintOutput } from "..";

describe("Class", () => {
it("should be able to create an empty class", async () => {
const fileContent = "class Test { }";
const instance: KipperCompileResult = await compiler.compile(fileContent, { target: defaultTarget });

assert.isDefined(instance.programCtx);
assert.equal(instance.programCtx!!.errors.length, 0, "Expected no compilation errors");
let written = instance.write();
assert.include(written, "class Test {\n}", "Invalid TypeScript code (Expected different output)");
});

it("should be able to create class with constructor", async () => {
const fileContent = "class Test {constructor (a:num, b:str) {};};";
const instance: KipperCompileResult = await compiler.compile(fileContent, { target: defaultTarget });

assert.isDefined(instance.programCtx);
assert.equal(instance.programCtx!!.errors.length, 0, "Expected no compilation errors");
let written = instance.write();
assert.include(
written,
"class Test {\n constructor(a: number, b: string)\n {\n }\n}",
"Invalid TypeScript code (Expected different output)",
);
});

it("should be able to create class with members", async () => {
const fileContent = `class Test {\n x: num;\n y: str;\ngreet(): void {\nprint("Kippa");\n};\n constructor(a: num, b: str)\n{\n};}`;
const instance: KipperCompileResult = await compiler.compile(fileContent, { target: defaultTarget });

assert.isDefined(instance.programCtx);
assert.equal(instance.programCtx!!.errors.length, 0, "Expected no compilation errors");

const written = instance.write();
assert.include(
written,
"class Test {\n" +
" x: number;\n" +
" y: string;\n" +
" greet(): void\n" +
" {\n" +
' __kipper.print("Kippa");\n' +
" }\n" +
" constructor(a: number, b: string)\n" +
" {\n" +
" }\n" +
"}",
);
});

it("should be able to instantiate a class with new", async () => {
const fileContent = `class Test {a: str; constructor (b: str) {this.a = b;}}; var x: Test = new Test("3"); print(x.a);`;
const instance: KipperCompileResult = await compiler.compile(fileContent, { target: defaultTarget });

assert.isDefined(instance.programCtx);
assert.equal(instance.programCtx!!.errors.length, 0, "Expected no compilation errors");

const written = instance.write();
assert.include(
written,
"class Test {\n" +
" a: string;\n" +
" constructor(b: string)\n" +
" {\n" +
" this.a = b;\n" +
" }\n" +
"}\n" +
'let x: Test = new Test("3");\n' +
"__kipper.print(x.a);",
"Invalid TypeScript code (Expected different output)",
);

const jsCode = ts.transpile(written);
testPrintOutput((message: any) => assert.equal(message, "3", "Expected different output"), jsCode);
});

it("should be able to instantiate a class with new and two properties", async () => {
const fileContent = `class Test {x: str; y: num; constructor (a: str, b: num) {this.x = a; this.y = b;}}; var x: Test = new Test("hello", 42); print(x.x);`;
const instance: KipperCompileResult = await compiler.compile(fileContent, { target: defaultTarget });

assert.isDefined(instance.programCtx);
assert.equal(instance.programCtx!!.errors.length, 0, "Expected no compilation errors");

const written = instance.write();
assert.include(
written,
"class Test {\n" +
" x: string;\n" +
" y: number;\n" +
" constructor(a: string, b: number)\n" +
" {\n" +
" this.x = a;\n" +
" this.y = b;\n" +
" }\n" +
"}\n" +
'let x: Test = new Test("hello", 42);\n' +
"__kipper.print(x.x);",
"Invalid TypeScript code (Expected different output)",
);

const jsCode = ts.transpile(written);
testPrintOutput((message: any) => assert.equal(message, "hello", "Expected different output"), jsCode);
});

it("should be able to access 'this' inside a class method", async () => {
const fileContent = `class Test {x: str; constructor (a: str) {this.x = a;} greet(): void {print(this.x);}}; var x: Test = new Test("hello"); x.greet();`;
const instance: KipperCompileResult = await compiler.compile(fileContent, { target: defaultTarget });

assert.isDefined(instance.programCtx);
assert.equal(instance.programCtx!!.errors.length, 0, "Expected no compilation errors");
let written = instance.write();
assert.include(
written,
"class Test {\n" +
" x: string;\n" +
" greet(): void\n" +
" {\n" +
" __kipper.print(this.x);\n" +
" }\n" +
" constructor(a: string)\n" +
" {\n" +
" this.x = a;\n" +
" }\n" +
"}\n" +
'let x: Test = new Test("hello");\n' +
"x.greet();",
"Invalid TypeScript code (Expected different output)",
);

const jsCode = ts.transpile(written);
testPrintOutput((message: any) => assert.equal(message, "hello", "Expected different output"), jsCode);
});

it("should be able to return a value inside a class method", async () => {
const fileContent = `class Test {x: str; constructor (a: str) {this.x = a;} greet(): str {return this.x;}}; var x: Test = new Test("hello"); print(x.greet());`;
const instance: KipperCompileResult = await compiler.compile(fileContent, { target: defaultTarget });

assert.isDefined(instance.programCtx);
assert.equal(instance.programCtx!!.errors.length, 0, "Expected no compilation errors");
let written = instance.write();
assert.include(
written,
"class Test {\n" +
" x: string;\n" +
" greet(): string\n" +
" {\n" +
" return this.x;\n" +
" }\n" +
" constructor(a: string)\n" +
" {\n" +
" this.x = a;\n" +
" }\n" +
"}\n" +
'let x: Test = new Test("hello");\n' +
"__kipper.print(x.greet());",
"Invalid TypeScript code (Expected different output)",
);

const jsCode = ts.transpile(written, { target: ScriptTarget.ES2015 });
testPrintOutput((message: any) => assert.equal(message, "hello", "Expected different output"), jsCode);
});
});
31 changes: 31 additions & 0 deletions test/module/core/core-functionality/comment.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { KipperCompileResult } from "@kipper/core";
import { KipperCompiler } from "@kipper/core";

Check warning on line 2 in test/module/core/core-functionality/comment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (22.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/comment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (20.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/comment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (20.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/comment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (22.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/comment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (20.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/comment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (22.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/comment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (18.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/comment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (18.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/comment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (18.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/comment.test.ts

View workflow job for this annotation

GitHub Actions / run (16.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/comment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (18.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/comment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (16.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/comment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (20.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/comment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (16.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/comment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (22.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/comment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-lock-dependencies (16.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/comment.test.ts

View workflow job for this annotation

GitHub Actions / run (16.x)

'KipperCompiler' is defined but never used

Check warning on line 2 in test/module/core/core-functionality/comment.test.ts

View workflow job for this annotation

GitHub Actions / tests-with-pck-dependencies (16.x)

'KipperCompiler' is defined but never used
import { assert } from "chai";
import * as ts from "typescript";
import { KipperTypeScriptTarget } from "@kipper/target-ts";
import { jsConfig } from "../errors";
import { ScriptTarget } from "typescript";
import { compiler, defaultTarget } from ".";
import { testPrintOutput } from "..";

describe("Comment", () => {
it("Single line", async () => {
const fileContent = 'var x: num = 5;\n// A comment\n print("");';
const instance: KipperCompileResult = await compiler.compile(fileContent, { target: defaultTarget });

assert.isDefined(instance.programCtx);
assert.deepEqual(instance.programCtx?.errors, [], "Expected no compilation errors");
assert.include(instance.write(), "let x: number = 5;", "Expected variable declaration to be present in output");
assert.include(instance.write(), '__kipper.print("");', "Expected print call to be present in output");
});

it("Multi line", async () => {
const fileContent = 'var x: num = 5;\n/* A comment\n ... \n end of comment */\n print("");';
const instance: KipperCompileResult = await compiler.compile(fileContent, { target: defaultTarget });

assert.isDefined(instance.programCtx);
assert.deepEqual(instance.programCtx?.errors, [], "Expected no compilation errors");
assert.include(instance.write(), "let x: number = 5;", "Expected variable declaration to be present in output");
assert.include(instance.write(), '__kipper.print("");', "Expected print call to be present in output");
});
});
Loading

0 comments on commit 145a572

Please sign in to comment.