Skip to content

Commit 5b3b6a8

Browse files
author
Sharon Yogev
committed
CR & more tests
1 parent 9bda58f commit 5b3b6a8

3 files changed

Lines changed: 46 additions & 10 deletions

File tree

packages/cli/src/api/__snapshots__/compile.test.ts.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ exports[`createCompiledCatalog options.pseudoLocale should return catalog with p
2626
2727
exports[`createCompiledCatalog options.pseudoLocale should return compiled catalog when pseudoLocale doesn't match current locale 1`] = `/*eslint-disable*/module.exports={messages:{"Hello":"Ahoj"}};`;
2828
29+
exports[`createCompiledCatalog options.pure should return code catalog 1`] = `/*eslint-disable*/module.exports={messages:{"Hello":"Ahoj"}};`;
30+
31+
exports[`createCompiledCatalog options.pure should return pure catalog 1`] = `
32+
Object {
33+
Hello: Ahoj,
34+
}
35+
`;
36+
2937
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:"____"}]]}};`;
3038
3139
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:"____"}]]}};`;

packages/cli/src/api/compile.test.ts

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import generate from "@babel/generator"
22
import { compile, createCompiledCatalog } from "./compile"
33

44
describe("compile", () => {
5-
const getSource = (message: string, shouldPseudolocalize: boolean = false) =>
6-
generate(compile(message, shouldPseudolocalize) as any, {
5+
const getSource = (message: string) =>
6+
generate(compile(message) as any, {
77
compact: true,
88
minified: true,
99
jsescOption: { minimal: true },
@@ -85,16 +85,21 @@ describe("compile", () => {
8585
})
8686

8787
describe("with pseudo-localization", () => {
88-
const getPSource = (message: string) => getSource(message, true)
88+
const getPSource = (message: string) =>
89+
generate(compile(message, true) as any, {
90+
compact: true,
91+
minified: true,
92+
jsescOption: { minimal: true },
93+
}).code
8994

9095
it("should pseudolocalize strings", () => {
9196
expect(getPSource("Martin Černý")).toEqual('"Màŕţĩń Čēŕńý"')
9297
})
9398

9499
it("should pseudolocalize escaping syntax characters", () => {
95100
// TODO: should this turn into pseudoLocale string?
96-
expect(getSource("'{name}'", true)).toEqual('"{name}"')
97-
// expect(getSource("'{name}'", true)).toEqual('"{ńàmē}"')
101+
expect(getPSource("'{name}'")).toEqual('"{name}"')
102+
// expect(getPSource("'{name}'")).toEqual('"{ńàmē}"')
98103
})
99104

100105
it("should not pseudolocalize arguments", () => {
@@ -111,16 +116,18 @@ describe("compile", () => {
111116

112117
it("should not pseudolocalize HTML tags", () => {
113118
expect(getPSource('Martin <span id="spanId">Černý</span>')).toEqual(
114-
'"Màŕţĩń <span id=\\"spanId\\">Čēŕńý</span>"'
119+
JSON.stringify('Màŕţĩń <span id="spanId">Čēŕńý</span>')
115120
)
116121
expect(
117122
getPSource("Martin Cerny 123a<span id='id'>Černý</span>")
118-
).toEqual('"Màŕţĩń Ćēŕńŷ 123à<span id=\'id\'>Čēŕńý</span>"')
123+
).toEqual(
124+
JSON.stringify("Màŕţĩń Ćēŕńŷ 123à<span id='id'>Čēŕńý</span>")
125+
)
119126
expect(getPSource("Martin <a title='>>a'>a</a>")).toEqual(
120-
'"Màŕţĩń <a title=\'>>a\'>à</a>"'
127+
JSON.stringify("Màŕţĩń <a title='>>a'>à</a>")
121128
)
122129
expect(getPSource("<a title=TITLE>text</a>")).toEqual(
123-
'"<a title=TITLE>ţēxţ</a>"'
130+
JSON.stringify("<a title=TITLE>ţēxţ</a>")
124131
)
125132
})
126133

@@ -302,6 +309,27 @@ describe("createCompiledCatalog", () => {
302309
})
303310
})
304311

312+
describe("options.pure", () => {
313+
const getCompiledCatalog = (pure) =>
314+
createCompiledCatalog(
315+
"ps",
316+
{
317+
Hello: "Ahoj",
318+
},
319+
{
320+
pure,
321+
}
322+
)
323+
324+
it("should return pure catalog", () => {
325+
expect(getCompiledCatalog(true)).toMatchSnapshot()
326+
})
327+
328+
it("should return code catalog", () => {
329+
expect(getCompiledCatalog(false)).toMatchSnapshot()
330+
})
331+
})
332+
305333
describe("options.compilerBabelOptions", () => {
306334
const getCompiledCatalog = (opts = {}) =>
307335
createCompiledCatalog(

packages/cli/src/api/pseudoLocalize.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe("PseudoLocalization", () => {
9393
expect(pseudoLocalize("replace { count }")).toEqual("ŕēƥĺàćē { count }")
9494
})
9595

96-
it("multiple plurals is wrong45", () => {
96+
it("multiple plurals pseudolocalize gives wrong ICU message", () => {
9797
expect(
9898
pseudoLocalize(
9999
"{bcount, plural, one {boy} other {# boys}} {gcount, plural, one {girl} other {# girls}}"

0 commit comments

Comments
 (0)