Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions test/json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,4 @@ encode = function(val, stack)
error("unexpected type '" .. t .. "'")
end


-- TODO: Since it supports NaN and Infinity it is considered a superset of JSON, so it probably should be renamed
function JSONStringify(val)
return ( encode(val) )
end
return {stringify = function(val) return ( encode(val) ) end}
168 changes: 0 additions & 168 deletions test/legacy-utils.ts

This file was deleted.

3 changes: 2 additions & 1 deletion test/transpile/bundle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ test("should transpile into one file", () => {
// Verify the name is as specified in tsconfig
expect(name).toBe("bundle/bundle.lua");
// Verify exported module by executing
expect(util.executeLuaModule(text)).toEqual({ myNumber: 3 });
// Use an empty TS string because we already transpiled the TS project
util.testModule("").setLuaHeader(text).expectToEqual({ myNumber: 3 });
});
12 changes: 12 additions & 0 deletions test/unit/__snapshots__/expressions.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,12 @@ ____exports.__result = bit.bor(a, b)
return ____exports"
`;

exports[`Null Expression 1`] = `
"local ____exports = {}
____exports.__result = nil
return ____exports"
`;

exports[`Unary expressions basic ("!a") 1`] = `
"local ____exports = {}
function ____exports.__main(self)
Expand Down Expand Up @@ -523,6 +529,12 @@ end
return ____exports"
`;

exports[`Undefined Expression 1`] = `
"local ____exports = {}
____exports.__result = nil
return ____exports"
`;

exports[`Unsupported bitop 5.3 ("a>>=b"): code 1`] = `
"local ____exports = {}
____exports.__result = (function()
Expand Down
8 changes: 8 additions & 0 deletions test/unit/__snapshots__/identifiers.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ exports[`ambient identifier must be a valid lua identifier (object literal short

exports[`ambient identifier must be a valid lua identifier (object literal shorthand) ("ɥɣɎɌͼƛಠ"): diagnostics 1`] = `"main.ts(3,27): error TSTL: Invalid ambient identifier name 'ɥɣɎɌͼƛಠ'. Ambient identifiers must be valid lua identifiers."`;

exports[`declaration-only variable with lua keyword as name is not renamed 1`] = `
"local ____exports = {}
function ____exports.__main(self)
type(7)
end
return ____exports"
`;

exports[`undeclared identifier must be a valid lua identifier ("$$"): code 1`] = `"foo = _____24_24_24"`;

exports[`undeclared identifier must be a valid lua identifier ("$$"): diagnostics 1`] = `"main.ts(2,21): error TSTL: Invalid ambient identifier name '$$$'. Ambient identifiers must be valid lua identifiers."`;
Expand Down
9 changes: 6 additions & 3 deletions test/unit/annotations/customConstructor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ test("CustomCreate", () => {
}
`;

const result = util.transpileAndExecute("return new Point2D(1, 2).x;", undefined, luaHeader, tsHeader);

expect(result).toBe(1);
// Can't use expectToMatchJsResult because above is not valid TS/JS
util.testModule`export default new Point2D(1, 2).x;`
.setTsHeader(tsHeader)
.setLuaHeader(luaHeader)
.setReturnExport("default")
.expectToEqual(1);
});

test("IncorrectUsage", () => {
Expand Down
54 changes: 18 additions & 36 deletions test/unit/annotations/luaIterator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as util from "../../util";
import { luaIteratorForbiddenUsage } from "../../../src/transformation/utils/diagnostics";

test("forof lua iterator", () => {
const code = `
util.testFunction`
const arr = ["a", "b", "c"];
/** @luaIterator */
interface Iter extends Iterable<string> {}
Expand All @@ -13,13 +13,11 @@ test("forof lua iterator", () => {
let result = "";
for (let e of luaIter()) { result += e; }
return result;
`;
const result = util.transpileAndExecute(code);
expect(result).toBe("abc");
`.expectToEqual("abc");
});

test("forof array lua iterator", () => {
const code = `
util.testFunction`
const arr = ["a", "b", "c"];
/** @luaIterator */
interface Iter extends Array<string> {}
Expand All @@ -30,13 +28,11 @@ test("forof array lua iterator", () => {
let result = "";
for (let e of luaIter()) { result += e; }
return result;
`;
const result = util.transpileAndExecute(code);
expect(result).toBe("abc");
`.expectToEqual("abc");
});

test("forof lua iterator with existing variable", () => {
const code = `
util.testFunction`
const arr = ["a", "b", "c"];
/** @luaIterator */
interface Iter extends Iterable<string> {}
Expand All @@ -48,13 +44,11 @@ test("forof lua iterator with existing variable", () => {
let e: string;
for (e of luaIter()) { result += e; }
return result;
`;
const result = util.transpileAndExecute(code);
expect(result).toBe("abc");
`.expectToEqual("abc");
});

test("forof lua iterator destructuring", () => {
const code = `
util.testFunction`
const arr = ["a", "b", "c"];
/** @luaIterator */
interface Iter extends Iterable<[string, string]> {}
Expand All @@ -65,13 +59,11 @@ test("forof lua iterator destructuring", () => {
let result = "";
for (let [a, b] of luaIter()) { result += a + b; }
return result;
`;
const result = util.transpileAndExecute(code);
expect(result).toBe("0a1b2c");
`.expectToEqual("0a1b2c");
});

test("forof lua iterator destructuring with existing variables", () => {
const code = `
util.testFunction`
const arr = ["a", "b", "c"];
/** @luaIterator */
interface Iter extends Iterable<[string, string]> {}
Expand All @@ -84,13 +76,11 @@ test("forof lua iterator destructuring with existing variables", () => {
let b: string;
for ([a, b] of luaIter()) { result += a + b; }
return result;
`;
const result = util.transpileAndExecute(code);
expect(result).toBe("0a1b2c");
`.expectToEqual("0a1b2c");
});

test("forof lua iterator tuple-return", () => {
const code = `
util.testFunction`
const arr = ["a", "b", "c"];
/**
* @luaIterator
Expand All @@ -106,13 +96,11 @@ test("forof lua iterator tuple-return", () => {
let result = "";
for (let [a, b] of luaIter()) { result += a + b; }
return result;
`;
const result = util.transpileAndExecute(code);
expect(result).toBe("0a1b2c");
`.expectToEqual("0a1b2c");
});

test("forof lua iterator tuple-return with existing variables", () => {
const code = `
util.testFunction`
const arr = ["a", "b", "c"];
/**
* @luaIterator
Expand All @@ -130,9 +118,7 @@ test("forof lua iterator tuple-return with existing variables", () => {
let b: string;
for ([a, b] of luaIter()) { result += a + b; }
return result;
`;
const result = util.transpileAndExecute(code);
expect(result).toBe("0a1b2c");
`.expectToEqual("0a1b2c");
});

test("forof lua iterator tuple-return single variable", () => {
Expand Down Expand Up @@ -161,7 +147,7 @@ test("forof lua iterator tuple-return single existing variable", () => {
});

test("forof forwarded lua iterator", () => {
const code = `
util.testFunction`
const arr = ["a", "b", "c"];
/** @luaIterator */
interface Iter extends Iterable<string> {}
Expand All @@ -177,13 +163,11 @@ test("forof forwarded lua iterator", () => {
let result = "";
for (let a of forward()) { result += a; }
return result;
`;
const result = util.transpileAndExecute(code);
expect(result).toBe("abc");
`.expectToEqual("abc");
});

test("forof forwarded lua iterator with tupleReturn", () => {
const code = `
util.testFunction`
const arr = ["a", "b", "c"];
/**
* @luaIterator
Expand All @@ -203,7 +187,5 @@ test("forof forwarded lua iterator with tupleReturn", () => {
let result = "";
for (let [a, b] of forward()) { result += a + b; }
return result;
`;
const result = util.transpileAndExecute(code);
expect(result).toBe("0a1b2c");
`.expectToEqual("0a1b2c");
});
Loading