|
| 1 | +import fs from "fs" |
| 2 | +import path from "path" |
| 3 | + |
| 4 | +const localesDir = path.join(__dirname, "..", "locales") |
| 5 | + |
| 6 | +const languages = fs |
| 7 | + .readdirSync(localesDir, { withFileTypes: true }) |
| 8 | + .filter((dirent) => dirent.isDirectory() && !dirent.name.startsWith(".")) |
| 9 | + .map((dirent) => dirent.name) |
| 10 | + |
| 11 | +function loadTools(language: string): Record<string, string> { |
| 12 | + return JSON.parse(fs.readFileSync(path.join(localesDir, language, "tools.json"), "utf8")) |
| 13 | +} |
| 14 | + |
| 15 | +describe("tools:missingToolParameter locales", () => { |
| 16 | + it("covers every shipped locale", () => { |
| 17 | + expect(languages.length).toBeGreaterThan(0) |
| 18 | + for (const language of languages) { |
| 19 | + const tools = loadTools(language) |
| 20 | + expect(tools.missingToolParameter, `missingToolParameter missing in ${language}`).toBeTruthy() |
| 21 | + expect( |
| 22 | + tools.missingToolParameterWithPath, |
| 23 | + `missingToolParameterWithPath missing in ${language}`, |
| 24 | + ).toBeTruthy() |
| 25 | + } |
| 26 | + }) |
| 27 | + |
| 28 | + it("keeps all interpolation placeholders in every locale", () => { |
| 29 | + for (const language of languages) { |
| 30 | + const tools = loadTools(language) |
| 31 | + expect(tools.missingToolParameter, `placeholders missing in ${language}`).toContain("{{toolName}}") |
| 32 | + expect(tools.missingToolParameter, `placeholders missing in ${language}`).toContain("{{paramName}}") |
| 33 | + expect(tools.missingToolParameterWithPath, `placeholders missing in ${language}`).toContain("{{toolName}}") |
| 34 | + expect(tools.missingToolParameterWithPath, `placeholders missing in ${language}`).toContain("{{relPath}}") |
| 35 | + expect(tools.missingToolParameterWithPath, `placeholders missing in ${language}`).toContain("{{paramName}}") |
| 36 | + } |
| 37 | + }) |
| 38 | + |
| 39 | + it("brands the English messages as Zoo, not Roo", () => { |
| 40 | + const tools = loadTools("en") |
| 41 | + expect(tools.missingToolParameter).toContain("Zoo") |
| 42 | + expect(tools.missingToolParameter).not.toContain("Roo") |
| 43 | + expect(tools.missingToolParameterWithPath).toContain("Zoo") |
| 44 | + expect(tools.missingToolParameterWithPath).not.toContain("Roo") |
| 45 | + }) |
| 46 | +}) |
0 commit comments