-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Small readme update. Update types submodule. Extended fixtures for tr…
…acking. More unit tests for game utils.
- Loading branch information
Showing
25 changed files
with
474 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { describe, expect, it } from "@jest/globals"; | ||
|
||
import { trimString } from "@/engine/core/utils/string"; | ||
|
||
describe("'string' utils", () => { | ||
it("'trimString' should correctly trim string values", () => { | ||
expect(trimString("")).toBe(""); | ||
expect(trimString("abc")).toBe("abc"); | ||
expect(trimString("abc ")).toBe("abc"); | ||
expect(trimString(" abc")).toBe("abc"); | ||
expect(trimString(" abc ")).toBe("abc"); | ||
expect(trimString(" a b c ")).toBe("a b c"); | ||
expect(trimString("a b c ")).toBe("a b c"); | ||
expect(trimString(" a b c")).toBe("a b c"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { describe, expect, it, jest } from "@jest/globals"; | ||
|
||
import { AnyObject, LuaArray, Optional } from "@/engine/lib/types"; | ||
|
||
describe("'table' utils", () => { | ||
const tableUtils: { | ||
isEmpty: (target: Optional<LuaTable<any>>) => boolean; | ||
resetTable: (target: LuaTable<any>) => void; | ||
getTableSize: (target: LuaTable<any>) => number; | ||
copyTable: (first: AnyObject, second: AnyObject) => AnyObject; | ||
} = jest.requireActual("@/engine/core/utils/table"); | ||
|
||
it("'resetTable' should correctly empty provided table", () => { | ||
const first: LuaArray<number> = $fromArray([1, 2, 3, 4]); | ||
const second: LuaTable<string, string> = $fromObject<string, string>({ a: "1", b: "2" }); | ||
|
||
tableUtils.resetTable(first); | ||
tableUtils.resetTable(second); | ||
|
||
expect(first).toEqualLuaArrays([]); | ||
expect(second).toEqualLuaTables({}); | ||
}); | ||
|
||
it("'copyTable' should correctly copy table", () => { | ||
const from: LuaTable<any> = new LuaTable(); | ||
const to: LuaTable<any> = $fromObject({ a: 1, b: 2, c: 3, d: { a: "a" } }); | ||
|
||
expect(tableUtils.copyTable(to, from)).toEqualLuaTables({ a: 1, b: 2, c: 3, d: { a: "a" } }); | ||
expect(to).toEqualLuaTables({ a: 1, b: 2, c: 3, d: { a: "a" } }); | ||
expect(to.get("d")).not.toBe(from.get("d")); | ||
}); | ||
|
||
it("'getTableSize' should correctly get size of the table", () => { | ||
expect(tableUtils.getTableSize($fromObject({ a: 1, b: 2 }))).toBe(2); | ||
expect(tableUtils.getTableSize($fromArray(["a", "b", "c", "d", "e"]))).toBe(5); | ||
expect(tableUtils.getTableSize(new LuaTable())).toBe(0); | ||
expect(tableUtils.getTableSize($fromArray<unknown>([]))).toBe(0); | ||
expect(tableUtils.getTableSize($fromObject<string, unknown>({}))).toBe(0); | ||
}); | ||
|
||
it("'isEmpty' should correctly check table emptiness", () => { | ||
expect(tableUtils.isEmpty($fromObject({ a: 1, b: 2 }))).toBe(false); | ||
expect(tableUtils.isEmpty($fromArray(["a", "b", "c", "d", "e"]))).toBe(false); | ||
expect(tableUtils.isEmpty($fromArray([1, 2, 3]))).toBe(false); | ||
expect(tableUtils.isEmpty(new LuaTable())).toBe(true); | ||
expect(tableUtils.isEmpty($fromArray<unknown>([]))).toBe(true); | ||
expect(tableUtils.isEmpty($fromObject<string, unknown>({}))).toBe(true); | ||
expect(tableUtils.isEmpty(null)).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.