-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.spec.ts
More file actions
92 lines (69 loc) · 2.03 KB
/
Copy pathindex.spec.ts
File metadata and controls
92 lines (69 loc) · 2.03 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { test } from "ava";
import { LuaArray } from "@wowts/lua";
import { concat, insert, sort, remove } from "./index";
test("concat an array without separator", t => {
// Arrange
const array:LuaArray<string> = { 1: "first", 2: "second" };
// Act
const result = concat(array);
// Assert
t.is(result, "firstsecond");
});
test("concat an array with a separator", t => {
// Arrange
const array:LuaArray<string> = { 1: "first", 2: "second", 3: "third" };
// Act
const result = concat(array, ",");
// Assert
t.is(result, "first,second,third");
});
test("insert an item at end", t => {
// Arrange
const array:LuaArray<string> = { 1: "first", 2: "second" };
// Act
insert(array, "third");
// Assert
t.deepEqual(array, { 1: "first", 2: "second", 3: "third" });
});
test("insert an item at the beginning", t => {
// Arrange
const array:LuaArray<string> = { 1: "first", 2: "second" };
// Act
insert(array, 1, "third");
// Assert
t.deepEqual(array, { 1: "third", 2: "first", 3: "second" });
});
test("sort with default sort", t => {
// Arrange
const array:LuaArray<string> = { 1: "B", 2: "A", 3: "C" };
// Act
sort(array);
// Assert
t.deepEqual(array, { 1: "A", 2: "B", 3: "C" });
});
test("sort with custom sort", t => {
// Arrange
const array:LuaArray<string> = { 1: "B", 2: "A", 3: "C" };
// Act
sort(array, (left, right) => left < right);
// Assert
t.deepEqual(array, { 1: "C", 2: "B", 3: "A" });
});
test("remove an element at the end", t => {
// Arrange
const array:LuaArray<string> = { 1: "A", 2: "B", 3: "C" };
// Act
const result = remove(array);
// Assert
t.is(result, "C");
t.deepEqual(array, { 1: "A", 2: "B" });
});
test("remove an element at the beginning", t => {
// Arrange
const array:LuaArray<string> = { 1: "A", 2: "B", 3: "C" };
// Act
const result = remove(array, 1);
// Assert
t.is(result, "A");
t.deepEqual(array, { 1: "B", 2: "C" });
});