Skip to content

Commit 0d91ce6

Browse files
Simplify activationEvents and tests that activationEvents trigger correctly
1 parent ff1b7dc commit 0d91ce6

File tree

2 files changed

+61
-68
lines changed

2 files changed

+61
-68
lines changed

package.json

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,7 @@
1919
],
2020
"main": "./dist/extension.js",
2121
"activationEvents": [
22-
"onCommand:string-manipulation.titleize",
23-
"onCommand:string-manipulation.titleizeApStyle",
24-
"onCommand:string-manipulation.titleizeChicagoStyle",
25-
"onCommand:string-manipulation.camelize",
26-
"onCommand:string-manipulation.chop",
27-
"onCommand:string-manipulation.clean",
28-
"onCommand:string-manipulation.cleanDiacritics",
29-
"onCommand:string-manipulation.classify",
30-
"onCommand:string-manipulation.underscored",
31-
"onCommand:string-manipulation.dasherize",
32-
"onCommand:string-manipulation.snake",
33-
"onCommand:string-manipulation.screamingSnake",
34-
"onCommand:string-manipulation.humanize",
35-
"onCommand:string-manipulation.slugify",
36-
"onCommand:string-manipulation.reverse",
37-
"onCommand:string-manipulation.swapCase",
38-
"onCommand:string-manipulation.decapitalize",
39-
"onCommand:string-manipulation.capitalize",
40-
"onCommand:string-manipulation.sentence",
41-
"onCommand:string-manipulation.prune",
42-
"onCommand:string-manipulation.truncate",
43-
"onCommand:string-manipulation.repeat",
44-
"onCommand:string-manipulation.increment",
45-
"onCommand:string-manipulation.decrement",
46-
"onCommand:string-manipulation.duplicateAndIncrement",
47-
"onCommand:string-manipulation.duplicateAndDecrement",
48-
"onCommand:string-manipulation.sequence",
49-
"onCommand:string-manipulation.randomCase"
22+
"onCommand:string-manipulation.*"
5023
],
5124
"contributes": {
5225
"commands": [

src/test/extension.test.ts

Lines changed: 60 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -148,57 +148,77 @@ suite("Extension Test Suite", () => {
148148
});
149149

150150
suite("randomCase", () => {
151-
const input = "Hello, World!";
151+
const input = "Hello, World!";
152152

153-
test("returns a string of the same length", () => {
154-
const output = myExtension.commandNameFunctionMap["randomCase"](
155-
input
156-
) as string;
157-
assert.equal(output.length, input.length);
158-
});
159-
160-
test("contains the same characters ignoring case", () => {
161-
const output = myExtension.commandNameFunctionMap["randomCase"](
162-
input
163-
) as string;
164-
assert.equal(output.toLowerCase(), input.toLowerCase());
165-
});
153+
test("returns a string of the same length", () => {
154+
const output = myExtension.commandNameFunctionMap["randomCase"](
155+
input
156+
) as string;
157+
assert.equal(output.length, input.length);
158+
});
166159

167-
test("changes the case of at least one character (statistically)", () => {
168-
let changed = false;
169-
for (let i = 0; i < 10; i++) {
160+
test("contains the same characters ignoring case", () => {
170161
const output = myExtension.commandNameFunctionMap["randomCase"](
171162
input
172163
) as string;
173-
if (output !== input && output.toLowerCase() === input.toLowerCase()) {
174-
changed = true;
175-
break;
164+
assert.equal(output.toLowerCase(), input.toLowerCase());
165+
});
166+
167+
test("changes the case of at least one character (statistically)", () => {
168+
let changed = false;
169+
for (let i = 0; i < 10; i++) {
170+
const output = myExtension.commandNameFunctionMap["randomCase"](
171+
input
172+
) as string;
173+
if (
174+
output !== input &&
175+
output.toLowerCase() === input.toLowerCase()
176+
) {
177+
changed = true;
178+
break;
179+
}
176180
}
177-
}
178-
assert.equal(changed, true);
179-
});
181+
assert.equal(changed, true);
182+
});
180183

181-
test("handles empty strings", () => {
182-
const output = myExtension.commandNameFunctionMap.randomCase("");
183-
assert.equal(output, "");
184-
});
184+
test("handles empty strings", () => {
185+
const output = myExtension.commandNameFunctionMap.randomCase("");
186+
assert.equal(output, "");
187+
});
185188

186-
test("preserves non-alphabetic characters", () => {
187-
const specialChars = "12345!@#$%";
188-
const output =
189-
myExtension.commandNameFunctionMap.randomCase(specialChars);
190-
assert.equal(output, specialChars);
189+
test("preserves non-alphabetic characters", () => {
190+
const specialChars = "12345!@#$%";
191+
const output =
192+
myExtension.commandNameFunctionMap.randomCase(specialChars);
193+
assert.equal(output, specialChars);
194+
});
195+
196+
test("handles strings with mixed content", () => {
197+
const mixedInput = "Test123!";
198+
const output = myExtension.commandNameFunctionMap.randomCase(
199+
mixedInput
200+
) as string;
201+
assert.equal(output.length, mixedInput.length);
202+
assert.notEqual(output.replace(/[^a-zA-Z]/g, ""), "");
203+
});
191204
});
205+
});
206+
207+
suite("activation events", () => {
208+
const extension = vscode.extensions.getExtension(
209+
"marclipovsky.string-manipulation"
210+
)!;
192211

193-
test("handles strings with mixed content", () => {
194-
const mixedInput = "Test123!";
195-
const output = myExtension.commandNameFunctionMap.randomCase(
196-
mixedInput
197-
) as string;
198-
assert.equal(output.length, mixedInput.length);
199-
assert.notEqual(output.replace(/[^a-zA-Z]/g, ""), "");
212+
test("is not active by default", () => {
213+
const extension = vscode.extensions.getExtension(
214+
"marclipovsky.string-manipulation"
215+
)!;
216+
assert.equal(false, extension.isActive);
200217
});
201218

202-
});
219+
test("invoked when running one of the commands", async () => {
220+
await vscode.commands.executeCommand("string-manipulation.titleize");
221+
assert.equal(true, extension.isActive);
222+
});
203223
});
204224
});

0 commit comments

Comments
 (0)