-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.test.ts
173 lines (153 loc) · 5.52 KB
/
index.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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import inputLoop from './index.ts';
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
Deno.test("Initialize with no args", () => {
const loop = new inputLoop();
assertEquals(loop.done, false);
});
Deno.test("Should not be done", () => {
const loop = new inputLoop({
silent: true,
});
assertEquals(loop.done, false);
});
Deno.test("Should be marked as done", () => {
const loop = new inputLoop({
silent: true,
});
loop.close();
assertEquals(loop.done, true);
});
Deno.test("Should choose an answer (number)", async () => {
const loop = new inputLoop({
silent: true,
});
const result = await loop.choose(["Option 1", "Option 2", "Option 3"], false, undefined, 2);
assertEquals(result, [false, false, true]);
});
Deno.test("Should choose an answer (number) (privateInput)", async () => {
const loop = new inputLoop({
silent: true,
});
const result = await loop.choose(["Option 1", "Option 2", "Option 3"], false, true, 2);
assertEquals(result, [false, false, true]);
});
Deno.test("Should choose an answer (number) (privateInput explicitly false)", async () => {
const loop = new inputLoop({
silent: true,
});
const result = await loop.choose(["Option 1", "Option 2", "Option 3"], false, false, 2);
assertEquals(result, [false, false, true]);
});
Deno.test("Should choose an answer (string)", async () => {
const loop = new inputLoop({
silent: true,
});
const result = await loop.choose(["Option 1", "Option 2", "Option 3"], false, undefined, '2');
assertEquals(result, [false, false, true]);
});
// Added to test issue https://github.com/keegandonley/input-deno/issues/3
Deno.test("Should choose an answer (string | CRLF) ", async () => {
const loop = new inputLoop({
silent: true,
});
const result = await loop.choose(["Option 1", "Option 2", "Option 3"], false, undefined, '2\r\n');
assertEquals(result, [false, false, true]);
});
Deno.test("Should not choose an answer (number)", async () => {
const loop = new inputLoop({
silent: true,
});
const result = await loop.choose(["Option 1", "Option 2", "Option 3"], false, undefined, 3);
assertEquals(result, [false, false, false]);
});
Deno.test("Should not choose an answer (string)", async () => {
const loop = new inputLoop({
silent: true,
});
const result = await loop.choose(["Option 1", "Option 2", "Option 3"], false, undefined, '3');
assertEquals(result, [false, false, false]);
});
Deno.test("Should run repeat on choose success (number)", async () => {
const loop = new inputLoop({
silent: true,
});
const result = await loop.choose(["Option 1", "Option 2", "Option 3"], false, undefined, 2);
assertEquals(result, [false, false, true]);
const result2 = await loop.repeat(2);
assertEquals(result2, [false, false, true]);
});
Deno.test("Should run repeat on choose success (string)", async () => {
const loop = new inputLoop({
silent: true,
});
const result = await loop.choose(["Option 1", "Option 2", "Option 3"], false, undefined, '2');
assertEquals(result, [false, false, true]);
const result2 = await loop.repeat('2');
assertEquals(result2, [false, false, true]);
});
Deno.test("Should run repeat on choose fail (number)", async () => {
const loop = new inputLoop({
silent: true,
});
const result = await loop.choose(["Option 1", "Option 2", "Option 3"], false, undefined, 3);
assertEquals(result, [false, false, false]);
const result2 = await loop.repeat(3);
assertEquals(result2, [false, false, false]);
});
Deno.test("Should run repeat on choose fail (string)", async () => {
const loop = new inputLoop({
silent: true,
});
const result = await loop.choose(["Option 1", "Option 2", "Option 3"], false, undefined, "3");
assertEquals(result, [false, false, false]);
const result2 = await loop.repeat("3");
assertEquals(result2, [false, false, false]);
});
Deno.test("Should answer a question (number)", async () => {
const loop = new inputLoop({
silent: true,
});
const result = await loop.question("Please answer the question", true, undefined, 2);
assertEquals(result, '2');
});
Deno.test("Should answer a question (string)", async () => {
const loop = new inputLoop({
silent: true,
});
const result = await loop.question("Please answer the question", true, undefined, "Hello!");
assertEquals(result, "Hello!");
});
Deno.test("Should answer a question (string | no newline)", async () => {
const loop = new inputLoop({
silent: true,
});
const result = await loop.question("Please answer the question", false, undefined, "Hello!");
assertEquals(result, "Hello!");
});
Deno.test("Should run repeat on question (string)", async () => {
const loop = new inputLoop({
silent: true,
});
const result = await loop.question("Please answer the question", true, undefined, "Hello!");
assertEquals(result, "Hello!");
const result2 = await loop.repeat("Hello Again!");
assertEquals(result2, 'Hello Again!')
});
Deno.test("Should close automatically (string)", async () => {
const loop = new inputLoop({
silent: true,
});
assertEquals(loop.done, false);
const result = await loop.choose(["Option 1", "Option 2", "Option 3"], true, undefined, "2");
assertEquals(result, [false, false, true]);
assertEquals(loop.done, true);
});
Deno.test("Should close automatically (number)", async () => {
const loop = new inputLoop({
silent: true,
});
assertEquals(loop.done, false);
const result = await loop.choose(["Option 1", "Option 2", "Option 3"], true, undefined, 2);
assertEquals(result, [false, false, true]);
assertEquals(loop.done, true);
});