Skip to content

Commit afc962c

Browse files
chore(macro): snapshot testing (#1912)
1 parent 6bb8983 commit afc962c

32 files changed

+3400
-2336
lines changed
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Production - only essential props are kept 1`] = `
4+
import { defineMessage } from "@lingui/core/macro";
5+
const msg = defineMessage({
6+
message: \`Hello \${name}\`,
7+
id: "msgId",
8+
comment: "description for translators",
9+
context: "My Context",
10+
});
11+
12+
↓ ↓ ↓ ↓ ↓ ↓
13+
14+
const msg =
15+
/*i18n*/
16+
{
17+
id: "msgId",
18+
values: {
19+
name: name,
20+
},
21+
};
22+
23+
`;
24+
25+
exports[`Production - only essential props are kept, without id 1`] = `
26+
import { defineMessage } from "@lingui/core/macro";
27+
const msg = defineMessage({
28+
message: \`Hello \${name}\`,
29+
comment: "description for translators",
30+
context: "My Context",
31+
});
32+
33+
↓ ↓ ↓ ↓ ↓ ↓
34+
35+
const msg =
36+
/*i18n*/
37+
{
38+
values: {
39+
name: name,
40+
},
41+
id: "oT92lS",
42+
};
43+
44+
`;
45+
46+
exports[`defineMessage can be called by alias \`msg\` 1`] = `
47+
import { msg } from "@lingui/core/macro";
48+
const message1 = msg\`Message\`;
49+
const message2 = msg({ message: "Message" });
50+
51+
↓ ↓ ↓ ↓ ↓ ↓
52+
53+
const message1 =
54+
/*i18n*/
55+
{
56+
id: "xDAtGP",
57+
message: "Message",
58+
};
59+
const message2 =
60+
/*i18n*/
61+
{
62+
message: "Message",
63+
id: "xDAtGP",
64+
};
65+
66+
`;
67+
68+
exports[`defineMessage macro could be renamed 1`] = `
69+
import {
70+
defineMessage as defineMessage2,
71+
plural as plural2,
72+
} from "@lingui/core/macro";
73+
const message = defineMessage2({
74+
comment: "Description",
75+
message: plural2(value, { one: "book", other: "books" }),
76+
});
77+
78+
↓ ↓ ↓ ↓ ↓ ↓
79+
80+
const message =
81+
/*i18n*/
82+
{
83+
values: {
84+
value: value,
85+
},
86+
message: "{value, plural, one {book} other {books}}",
87+
id: "SlmyxX",
88+
comment: "Description",
89+
};
90+
91+
`;
92+
93+
exports[`defineMessage should support template literal 1`] = `
94+
import { defineMessage } from "@lingui/core/macro";
95+
const message = defineMessage\`Message\`;
96+
97+
↓ ↓ ↓ ↓ ↓ ↓
98+
99+
const message =
100+
/*i18n*/
101+
{
102+
id: "xDAtGP",
103+
message: "Message",
104+
};
105+
106+
`;
107+
108+
exports[`should expand macros in message property 1`] = `
109+
import { defineMessage, plural, arg } from "@lingui/core/macro";
110+
const message = defineMessage({
111+
comment: "Description",
112+
message: plural(value, { one: "book", other: "books" }),
113+
});
114+
115+
↓ ↓ ↓ ↓ ↓ ↓
116+
117+
const message =
118+
/*i18n*/
119+
{
120+
values: {
121+
value: value,
122+
},
123+
message: "{value, plural, one {book} other {books}}",
124+
id: "SlmyxX",
125+
comment: "Description",
126+
};
127+
128+
`;
129+
130+
exports[`should left string message intact 1`] = `
131+
import { defineMessage } from "@lingui/core/macro";
132+
const message = defineMessage({
133+
message: "Message",
134+
});
135+
136+
↓ ↓ ↓ ↓ ↓ ↓
137+
138+
const message =
139+
/*i18n*/
140+
{
141+
message: "Message",
142+
id: "xDAtGP",
143+
};
144+
145+
`;
146+
147+
exports[`should preserve custom id 1`] = `
148+
import { defineMessage } from "@lingui/core/macro";
149+
const message = defineMessage({
150+
id: "msg.id",
151+
message: "Message",
152+
});
153+
154+
↓ ↓ ↓ ↓ ↓ ↓
155+
156+
const message =
157+
/*i18n*/
158+
{
159+
id: "msg.id",
160+
message: "Message",
161+
};
162+
163+
`;
164+
165+
exports[`should preserve values 1`] = `
166+
import { defineMessage, t } from "@lingui/core/macro";
167+
const message = defineMessage({
168+
message: t\`Hello \${name}\`,
169+
});
170+
171+
↓ ↓ ↓ ↓ ↓ ↓
172+
173+
const message =
174+
/*i18n*/
175+
{
176+
values: {
177+
name: name,
178+
},
179+
message: "Hello {name}",
180+
id: "OVaF9k",
181+
};
182+
183+
`;
184+
185+
exports[`should transform template literals 1`] = `
186+
import { defineMessage } from "@lingui/core/macro";
187+
const message = defineMessage({
188+
message: \`Message \${name}\`,
189+
});
190+
191+
↓ ↓ ↓ ↓ ↓ ↓
192+
193+
const message =
194+
/*i18n*/
195+
{
196+
values: {
197+
name: name,
198+
},
199+
message: "Message {name}",
200+
id: "A2aVLF",
201+
};
202+
203+
`;
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Macro is used in expression assignment 1`] = `
4+
import { plural } from "@lingui/core/macro";
5+
const a = plural(count, {
6+
one: \`# book\`,
7+
other: "# books",
8+
});
9+
10+
↓ ↓ ↓ ↓ ↓ ↓
11+
12+
import { i18n as _i18n } from "@lingui/core";
13+
const a = _i18n._(
14+
/*i18n*/
15+
{
16+
id: "esnaQO",
17+
message: "{count, plural, one {# book} other {# books}}",
18+
values: {
19+
count: count,
20+
},
21+
}
22+
);
23+
24+
`;
25+
26+
exports[`Macro with expression only choice 1`] = `
27+
import { plural } from "@lingui/core/macro";
28+
plural(users.length, {
29+
offset: 1,
30+
0: "No books",
31+
1: "1 book",
32+
other: someOtherExp,
33+
});
34+
35+
↓ ↓ ↓ ↓ ↓ ↓
36+
37+
import { i18n as _i18n } from "@lingui/core";
38+
_i18n._(
39+
/*i18n*/
40+
{
41+
id: "0mcXIe",
42+
message:
43+
"{0, plural, offset:1 =0 {No books} =1 {1 book} other {{someOtherExp}}}",
44+
values: {
45+
0: users.length,
46+
someOtherExp: someOtherExp,
47+
},
48+
}
49+
);
50+
51+
`;
52+
53+
exports[`Macro with offset and exact matches 1`] = `
54+
import { plural } from "@lingui/core/macro";
55+
plural(users.length, {
56+
offset: 1,
57+
0: "No books",
58+
1: "1 book",
59+
other: "# books",
60+
});
61+
62+
↓ ↓ ↓ ↓ ↓ ↓
63+
64+
import { i18n as _i18n } from "@lingui/core";
65+
_i18n._(
66+
/*i18n*/
67+
{
68+
id: "CF5t+7",
69+
message: "{0, plural, offset:1 =0 {No books} =1 {1 book} other {# books}}",
70+
values: {
71+
0: users.length,
72+
},
73+
}
74+
);
75+
76+
`;
77+
78+
exports[`plural macro could be renamed 1`] = `
79+
import { plural as plural2 } from "@lingui/core/macro";
80+
const a = plural2(count, {
81+
one: \`# book\`,
82+
other: "# books",
83+
});
84+
85+
↓ ↓ ↓ ↓ ↓ ↓
86+
87+
import { i18n as _i18n } from "@lingui/core";
88+
const a = _i18n._(
89+
/*i18n*/
90+
{
91+
id: "esnaQO",
92+
message: "{count, plural, one {# book} other {# books}}",
93+
values: {
94+
count: count,
95+
},
96+
}
97+
);
98+
99+
`;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Nested macros 1`] = `
4+
import { select, plural } from "@lingui/core/macro";
5+
select(gender, {
6+
male: plural(numOfGuests, {
7+
one: "He invites one guest",
8+
other: "He invites # guests",
9+
}),
10+
female: \`She is \${gender}\`,
11+
other: \`They is \${gender}\`,
12+
});
13+
14+
↓ ↓ ↓ ↓ ↓ ↓
15+
16+
import { i18n as _i18n } from "@lingui/core";
17+
_i18n._(
18+
/*i18n*/
19+
{
20+
id: "G8xqGf",
21+
message:
22+
"{gender, select, male {{numOfGuests, plural, one {He invites one guest} other {He invites # guests}}} female {She is {gender}} other {They is {gender}}}",
23+
values: {
24+
gender: gender,
25+
numOfGuests: numOfGuests,
26+
},
27+
}
28+
);
29+
30+
`;
31+
32+
exports[`Nested macros with pure expressions option 1`] = `
33+
import { select, plural } from "@lingui/core/macro";
34+
select(gender, {
35+
male: plural(numOfGuests, {
36+
one: "He invites one guest",
37+
other: "He invites # guests",
38+
}),
39+
female: \`She is \${gender}\`,
40+
other: someOtherExp,
41+
});
42+
43+
↓ ↓ ↓ ↓ ↓ ↓
44+
45+
import { i18n as _i18n } from "@lingui/core";
46+
_i18n._(
47+
/*i18n*/
48+
{
49+
id: "j9PNNm",
50+
message:
51+
"{gender, select, male {{numOfGuests, plural, one {He invites one guest} other {He invites # guests}}} female {She is {gender}} other {{someOtherExp}}}",
52+
values: {
53+
gender: gender,
54+
numOfGuests: numOfGuests,
55+
someOtherExp: someOtherExp,
56+
},
57+
}
58+
);
59+
60+
`;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`#1 1`] = `
4+
import { t, selectOrdinal } from "@lingui/core/macro";
5+
t\`This is my \${selectOrdinal(count, {
6+
one: "#st",
7+
two: \`#nd\`,
8+
other: "#rd",
9+
})} cat\`;
10+
11+
↓ ↓ ↓ ↓ ↓ ↓
12+
13+
import { i18n as _i18n } from "@lingui/core";
14+
_i18n._(
15+
/*i18n*/
16+
{
17+
id: "dJXd3T",
18+
message:
19+
"This is my {count, selectordinal, one {#st} two {#nd} other {#rd}} cat",
20+
values: {
21+
count: count,
22+
},
23+
}
24+
);
25+
26+
`;

0 commit comments

Comments
 (0)