Skip to content

Commit

Permalink
CR & more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharon Yogev committed Oct 20, 2022
1 parent 9bda58f commit 7097313
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
8 changes: 8 additions & 0 deletions packages/cli/src/api/__snapshots__/compile.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ exports[`createCompiledCatalog options.pseudoLocale should return catalog with p
exports[`createCompiledCatalog options.pseudoLocale should return compiled catalog when pseudoLocale doesn't match current locale 1`] = `/*eslint-disable*/module.exports={messages:{"Hello":"Ahoj"}};`;
exports[`createCompiledCatalog options.pure should return code catalog 1`] = `/*eslint-disable*/module.exports={messages:{"Hello":"Ahoj"}};`;
exports[`createCompiledCatalog options.pure should return pure catalog 1`] = `
Object {
Hello: Ahoj,
}
`;
exports[`createCompiledCatalog options.strict should return message key as a fallback translation 1`] = `/*eslint-disable*/module.exports={messages:{"Hello":"Ahoj","Missing":"Missing","Select":[["id","select",{Gen:"Genesis","1John":"1 John",other:"____"}]]}};`;
exports[`createCompiledCatalog options.strict should't return message key as a fallback in strict mode 1`] = `/*eslint-disable*/module.exports={messages:{"Hello":"Ahoj","Missing":"","Select":[["id","select",{Gen:"Genesis","1John":"1 John",other:"____"}]]}};`;
42 changes: 35 additions & 7 deletions packages/cli/src/api/compile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import generate from "@babel/generator"
import { compile, createCompiledCatalog } from "./compile"

describe("compile", () => {
const getSource = (message: string, shouldPseudolocalize: boolean = false) =>
generate(compile(message, shouldPseudolocalize) as any, {
const getSource = (message: string) =>
generate(compile(message) as any, {
compact: true,
minified: true,
jsescOption: { minimal: true },
Expand Down Expand Up @@ -85,7 +85,12 @@ describe("compile", () => {
})

describe("with pseudo-localization", () => {
const getPSource = (message: string) => getSource(message, true)
const getPSource = (message: string) =>
generate(compile(message, true) as any, {
compact: true,
minified: true,
jsescOption: { minimal: true },
}).code

it("should pseudolocalize strings", () => {
expect(getPSource("Martin Černý")).toEqual('"Màŕţĩń Čēŕńý"')
Expand All @@ -111,16 +116,18 @@ describe("compile", () => {

it("should not pseudolocalize HTML tags", () => {
expect(getPSource('Martin <span id="spanId">Černý</span>')).toEqual(
'"Màŕţĩń <span id=\\"spanId\\">Čēŕńý</span>"'
JSON.stringify('Màŕţĩń <span id="spanId">Čēŕńý</span>')
)
expect(
getPSource("Martin Cerny 123a<span id='id'>Černý</span>")
).toEqual('"Màŕţĩń Ćēŕńŷ 123à<span id=\'id\'>Čēŕńý</span>"')
).toEqual(
JSON.stringify("Màŕţĩń Ćēŕńŷ 123à<span id='id'>Čēŕńý</span>")
)
expect(getPSource("Martin <a title='>>a'>a</a>")).toEqual(
'"Màŕţĩń <a title=\'>>a\'>à</a>"'
JSON.stringify("Màŕţĩń <a title='>>a'>à</a>")
)
expect(getPSource("<a title=TITLE>text</a>")).toEqual(
'"<a title=TITLE>ţēxţ</a>"'
JSON.stringify("<a title=TITLE>ţēxţ</a>")
)
})

Expand Down Expand Up @@ -302,6 +309,27 @@ describe("createCompiledCatalog", () => {
})
})

describe("options.pure", () => {
const getCompiledCatalog = (pure) =>
createCompiledCatalog(
"ps",
{
Hello: "Ahoj",
},
{
pure,
}
)

it("should return pure catalog", () => {
expect(getCompiledCatalog(true)).toMatchSnapshot()
})

it("should return code catalog", () => {
expect(getCompiledCatalog(false)).toMatchSnapshot()
})
})

describe("options.compilerBabelOptions", () => {
const getCompiledCatalog = (opts = {}) =>
createCompiledCatalog(
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/api/pseudoLocalize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe("PseudoLocalization", () => {
expect(pseudoLocalize("replace { count }")).toEqual("ŕēƥĺàćē { count }")
})

it("multiple plurals is wrong45", () => {
it("multiple plurals pseudolocalize gives wrong ICU message", () => {
expect(
pseudoLocalize(
"{bcount, plural, one {boy} other {# boys}} {gcount, plural, one {girl} other {# girls}}"
Expand Down

0 comments on commit 7097313

Please sign in to comment.