Skip to content

Commit 0152521

Browse files
committed
impr(british english): replace double quotes with single quotes
closes monkeytypegame#7015
1 parent be106b8 commit 0152521

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

frontend/__tests__/test/british-english.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,30 @@ describe("british-english", () => {
3838
"armour-flavouring"
3939
);
4040
});
41+
42+
it("should convert double quotes to single quotes", async () => {
43+
await expect(replace('"hello"', "")).resolves.toEqual("'hello'");
44+
await expect(replace('"test"', "")).resolves.toEqual("'test'");
45+
await expect(replace('"Hello World"', "")).resolves.toEqual(
46+
"'Hello World'"
47+
);
48+
});
49+
50+
it("should convert double quotes and replace words", async () => {
51+
await expect(replace('"color"', "")).resolves.toEqual("'colour'");
52+
await expect(replace('"math"', "")).resolves.toEqual("'maths'");
53+
await expect(replace('"Color"', "")).resolves.toEqual("'Colour'");
54+
});
55+
56+
it("should handle multiple double quotes in a word", async () => {
57+
await expect(
58+
replace('He said "hello" and "goodbye"', "")
59+
).resolves.toEqual("He said 'hello' and 'goodbye'");
60+
});
61+
62+
it("should not affect words without double quotes", async () => {
63+
await expect(replace("'hello'", "")).resolves.toEqual("'hello'");
64+
await expect(replace("test", "")).resolves.toEqual("test");
65+
});
4166
});
4267
});

frontend/src/ts/test/british-english.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,11 @@ export async function replace(
658658
word: string,
659659
previousWord: string
660660
): Promise<string> {
661+
// Convert American-style double quotes to British-style single quotes
662+
if (word.includes('"')) {
663+
word = word.replace(/"/g, "'");
664+
}
665+
661666
if (word.includes("-")) {
662667
//this handles hyphenated words (for example "cream-colored") to make sure
663668
//we don't have to add every possible combination to the list

0 commit comments

Comments
 (0)