-
Notifications
You must be signed in to change notification settings - Fork 0
/
tail_test.ts
65 lines (49 loc) · 1.43 KB
/
tail_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright © 2023 Tomoki Miyauchi. All rights reserved. MIT license.
import { tail } from "./tail.ts";
import { Sliceable } from "./types.ts";
import {
assertEquals,
assertType,
describe,
IsExact,
it,
} from "./_dev_deps.ts";
describe("tail", () => {
it("should return elements without head", () => {
const table: [Sliceable<unknown>, unknown][] = [
[[""], []],
[["a", "b", "c"], ["b", "c"]],
["a", ""],
["abc", "bc"],
[[], []],
["", ""],
];
table.forEach(([seq, expected]) => {
assertEquals(tail(seq), expected);
});
});
it("should infer never[] if empty array", () => {
const result = tail([]);
assertType<IsExact<typeof result, never[]>>(true);
});
it("should should infer empty array if single tuple", () => {
const result = tail([0]);
assertType<IsExact<typeof result, []>>(true);
});
it("should infer tail elements", () => {
const result = tail([0, 1, 2]);
assertType<IsExact<typeof result, [1, 2]>>(true);
});
it("should infer string if empty string", () => {
const result = tail("");
assertType<IsExact<typeof result, string>>(true);
});
it("should infer empty string if single string", () => {
const result = tail("a");
assertType<IsExact<typeof result, "">>(true);
});
it("should infer tail chars", () => {
const result = tail("abc");
assertType<IsExact<typeof result, "bc">>(true);
});
});