forked from Acode-Foundation/Acode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsanity.tests.js
More file actions
213 lines (194 loc) · 6.01 KB
/
Copy pathsanity.tests.js
File metadata and controls
213 lines (194 loc) · 6.01 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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import { getModeForPath } from "../cm/modelist";
import {
clearModifierState,
clearQuickToolsButtonFeedback,
removeActionStackEntries,
} from "../handlers/quickToolsState";
import {
getLanguageModeRecommendationSearchKeyword,
shouldRecommendLanguageModeExtension,
} from "../lib/languageModeRecommendations";
import { isVersionGreater } from "../utils/version";
import { TestRunner } from "./tester";
export async function runSanityTests(writeOutput) {
const runner = new TestRunner("JS (WebView) Sanity Tests");
// Test 1: String operations
runner.test("String concatenation", (test) => {
const result = "Hello" + " " + "World";
test.assertEqual(result, "Hello World", "String concatenation should work");
});
// Test 2: Number operations
runner.test("Basic arithmetic", (test) => {
const sum = 5 + 3;
test.assertEqual(sum, 8, "Addition should work correctly");
});
// Test 3: Array operations
runner.test("Array operations", (test) => {
const arr = [1, 2, 3];
test.assertEqual(arr.length, 3, "Array length should be correct");
test.assert(arr.includes(2), "Array should include 2");
});
// Test 4: Object operations
runner.test("Object operations", (test) => {
const obj = { name: "Test", value: 42 };
test.assertEqual(obj.name, "Test", "Object property should be accessible");
test.assertEqual(obj.value, 42, "Object value should be correct");
});
// Test 5: Function execution
runner.test("Function execution", (test) => {
const add = (a, b) => a + b;
const result = add(10, 20);
test.assertEqual(result, 30, "Function should return correct value");
});
// Test 6: Async function
runner.test("Async function handling", async (test) => {
const asyncFunc = async () => {
return new Promise((resolve) => {
setTimeout(() => resolve("done"), 10);
});
};
const result = await asyncFunc();
test.assertEqual(result, "done", "Async function should work correctly");
});
// Test 7: Error handling
runner.test("Error handling", (test) => {
try {
throw new Error("Test error");
} catch (e) {
test.assert(e instanceof Error, "Should catch Error instances");
}
});
// Test 8: Conditional logic
runner.test("Conditional logic", (test) => {
const value = 10;
test.assert(value > 5, "Condition should be true");
test.assert(!(value < 5), "Negation should work");
});
runner.test("Language mode recommendation keywords", (test) => {
test.assertEqual(
getLanguageModeRecommendationSearchKeyword(".gitignore"),
"gitignore",
"Dotfiles without extensions should use the dotfile name",
);
test.assertEqual(
getLanguageModeRecommendationSearchKeyword("src/main.js"),
"js",
"Normal files should use the file extension",
);
test.assertEqual(
getLanguageModeRecommendationSearchKeyword("README"),
"",
"Extensionless non-dotfiles should not request plugin recommendations",
);
test.assertEqual(
getLanguageModeRecommendationSearchKeyword("example"),
"",
"Arbitrary extensionless names should not request plugin recommendations",
);
});
runner.test("Language mode recommendation candidates", (test) => {
test.assert(
!shouldRecommendLanguageModeExtension(
"example.html ",
getModeForPath("example.html "),
),
"Built-in language extensions should not request plugins",
);
test.assert(
!shouldRecommendLanguageModeExtension(
"example.py ",
getModeForPath("example.py "),
),
"Built-in Python support should not request a plugin",
);
test.assert(
shouldRecommendLanguageModeExtension(
"example.acode-unknown-mode",
getModeForPath("example.acode-unknown-mode"),
),
"Unknown language extensions should remain eligible for recommendations",
);
});
runner.test("Quick tools modifier cleanup emits inactive state", (test) => {
const state = {
shift: true,
alt: true,
ctrl: true,
meta: true,
};
const emitted = [];
const events = {
shift: [(value) => emitted.push(["shift", value])],
alt: [(value) => emitted.push(["alt", value])],
ctrl: [(value) => emitted.push(["ctrl", value])],
meta: [(value) => emitted.push(["meta", value])],
};
test.assert(clearModifierState(state, events));
test.assertEqual(state.shift, false);
test.assertEqual(state.alt, false);
test.assertEqual(state.ctrl, false);
test.assertEqual(state.meta, false);
test.assertEqual(
JSON.stringify(emitted),
JSON.stringify([
["shift", false],
["alt", false],
["ctrl", false],
["meta", false],
]),
);
});
runner.test(
"Quick tools feedback cleanup clears stale button state",
(test) => {
const container = document.createElement("div");
const button = document.createElement("button");
button.className = "icon active click";
button.dataset.timeout = setTimeout(() => {}, 1000);
container.append(button);
test.assertEqual(clearQuickToolsButtonFeedback([container]), 1);
test.assert(!button.classList.contains("active"));
test.assert(!button.classList.contains("click"));
test.assertEqual(button.dataset.timeout, undefined);
},
);
runner.test(
"Quick tools search cleanup removes duplicate stack entries",
(test) => {
const entries = ["search-bar", "other", "search-bar"];
const stack = {
remove(id) {
const index = entries.indexOf(id);
if (index === -1) return false;
entries.splice(index, 1);
return true;
},
};
test.assertEqual(removeActionStackEntries(stack, "search-bar"), 2);
test.assertEqual(JSON.stringify(entries), JSON.stringify(["other"]));
},
);
runner.test(
"Plugin version comparison only accepts newer versions",
(test) => {
test.assert(
isVersionGreater("1.1.2", "1.1.1"),
"Patch updates should be newer",
);
test.assert(
isVersionGreater("1.2.0", "1.1.9"),
"Minor updates should be newer",
);
test.assert(
!isVersionGreater("1.1.1", "1.1.1"),
"Equal versions should not be updates",
);
test.assert(
!isVersionGreater("1.0.0", "1.1.1"),
"Lower remote versions should not be updates",
);
},
);
// Run all tests
return await runner.run(writeOutput);
}