Skip to content

Commit

Permalink
test(utils): add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
TomokiMiyauci committed Apr 19, 2023
1 parent b5fc092 commit 709e2d6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function assertTokenFormat(input: string, msg?: string): asserts input {
if (!reToken.test(input)) throw Error(msg);
}

/** Serialize instance path. */
export function stringifyInstancePath(
...paths: readonly (string | number)[]
): string {
Expand Down
27 changes: 25 additions & 2 deletions utils_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { fromResponse } from "./utils.ts";
import { assert, describe, equalsResponse, it, Status } from "./_dev_deps.ts";
import { fromResponse, stringifyInstancePath } from "./utils.ts";
import {
assert,
assertEquals,
describe,
equalsResponse,
it,
Status,
} from "./_dev_deps.ts";

describe("fromResponse", () => {
it("should return new response what change partial properties", async () => {
Expand Down Expand Up @@ -46,3 +53,19 @@ describe("fromResponse", () => {
);
});
});

describe("stringifyInstancePath", () => {
const table: [(number | string)[], string][] = [
[[], ""],
[["a"], "a"],
[["a", 0], "a[0]"],
[["a", 0, "b", 1], "a[0].b[1]"],
[[0], "0"],
[[0, 0, 0], "0[0][0]"],
[[0, "0", 0, "0"], "0.0[0].0"],
];

table.forEach(([input, expected]) => {
assertEquals(stringifyInstancePath(...input), expected);
});
});

0 comments on commit 709e2d6

Please sign in to comment.