Skip to content

Commit

Permalink
fix(test): resolve I being replaced with i when english punctuation w…
Browse files Browse the repository at this point in the history
…as enabled

closes #4763
  • Loading branch information
Miodec committed Nov 6, 2023
1 parent 79d1b35 commit 04077fa
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions frontend/src/ts/test/english-punctuation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { randomElementFromArray } from "../utils/misc";
import {
capitalizeFirstLetterOfEachWord,
randomElementFromArray,
} from "../utils/misc";

type Pair = [string, string[]];

Expand Down Expand Up @@ -54,6 +57,21 @@ export async function replace(word: string): Promise<string> {

return word.replace(
RegExp(`^(?:([\\W]*)(${replacement[0]})([\\W]*))$`, "gi"),
randomReplacement
(_, $1, $2, $3) =>
$1 +
($2.charAt(0) === $2.charAt(0).toUpperCase()
? shouldWholeReplacementWordBeCapitalised($2)
? randomReplacement.toUpperCase()
: capitalizeFirstLetterOfEachWord(randomReplacement)
: randomReplacement) +
$3
);
}

function shouldWholeReplacementWordBeCapitalised(
wordToBeReplaced: string
): boolean {
if (wordToBeReplaced === "I") return false;
if (wordToBeReplaced === wordToBeReplaced.toUpperCase()) return true;
return false;
}

0 comments on commit 04077fa

Please sign in to comment.