Skip to content

Commit

Permalink
chore(macro): snapshot testing (#1912)
Browse files Browse the repository at this point in the history
  • Loading branch information
thekip committed Apr 12, 2024
1 parent 6bb8983 commit afc962c
Show file tree
Hide file tree
Showing 32 changed files with 3,400 additions and 2,336 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Production - only essential props are kept 1`] = `
import { defineMessage } from "@lingui/core/macro";
const msg = defineMessage({
message: \`Hello \${name}\`,
id: "msgId",
comment: "description for translators",
context: "My Context",
});
↓ ↓ ↓ ↓ ↓ ↓
const msg =
/*i18n*/
{
id: "msgId",
values: {
name: name,
},
};
`;
exports[`Production - only essential props are kept, without id 1`] = `
import { defineMessage } from "@lingui/core/macro";
const msg = defineMessage({
message: \`Hello \${name}\`,
comment: "description for translators",
context: "My Context",
});
↓ ↓ ↓ ↓ ↓ ↓
const msg =
/*i18n*/
{
values: {
name: name,
},
id: "oT92lS",
};
`;
exports[`defineMessage can be called by alias \`msg\` 1`] = `
import { msg } from "@lingui/core/macro";
const message1 = msg\`Message\`;
const message2 = msg({ message: "Message" });
↓ ↓ ↓ ↓ ↓ ↓
const message1 =
/*i18n*/
{
id: "xDAtGP",
message: "Message",
};
const message2 =
/*i18n*/
{
message: "Message",
id: "xDAtGP",
};
`;
exports[`defineMessage macro could be renamed 1`] = `
import {
defineMessage as defineMessage2,
plural as plural2,
} from "@lingui/core/macro";
const message = defineMessage2({
comment: "Description",
message: plural2(value, { one: "book", other: "books" }),
});
↓ ↓ ↓ ↓ ↓ ↓
const message =
/*i18n*/
{
values: {
value: value,
},
message: "{value, plural, one {book} other {books}}",
id: "SlmyxX",
comment: "Description",
};
`;
exports[`defineMessage should support template literal 1`] = `
import { defineMessage } from "@lingui/core/macro";
const message = defineMessage\`Message\`;
↓ ↓ ↓ ↓ ↓ ↓
const message =
/*i18n*/
{
id: "xDAtGP",
message: "Message",
};
`;
exports[`should expand macros in message property 1`] = `
import { defineMessage, plural, arg } from "@lingui/core/macro";
const message = defineMessage({
comment: "Description",
message: plural(value, { one: "book", other: "books" }),
});
↓ ↓ ↓ ↓ ↓ ↓
const message =
/*i18n*/
{
values: {
value: value,
},
message: "{value, plural, one {book} other {books}}",
id: "SlmyxX",
comment: "Description",
};
`;
exports[`should left string message intact 1`] = `
import { defineMessage } from "@lingui/core/macro";
const message = defineMessage({
message: "Message",
});
↓ ↓ ↓ ↓ ↓ ↓
const message =
/*i18n*/
{
message: "Message",
id: "xDAtGP",
};
`;
exports[`should preserve custom id 1`] = `
import { defineMessage } from "@lingui/core/macro";
const message = defineMessage({
id: "msg.id",
message: "Message",
});
↓ ↓ ↓ ↓ ↓ ↓
const message =
/*i18n*/
{
id: "msg.id",
message: "Message",
};
`;
exports[`should preserve values 1`] = `
import { defineMessage, t } from "@lingui/core/macro";
const message = defineMessage({
message: t\`Hello \${name}\`,
});
↓ ↓ ↓ ↓ ↓ ↓
const message =
/*i18n*/
{
values: {
name: name,
},
message: "Hello {name}",
id: "OVaF9k",
};
`;
exports[`should transform template literals 1`] = `
import { defineMessage } from "@lingui/core/macro";
const message = defineMessage({
message: \`Message \${name}\`,
});
↓ ↓ ↓ ↓ ↓ ↓
const message =
/*i18n*/
{
values: {
name: name,
},
message: "Message {name}",
id: "A2aVLF",
};
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Macro is used in expression assignment 1`] = `
import { plural } from "@lingui/core/macro";
const a = plural(count, {
one: \`# book\`,
other: "# books",
});
↓ ↓ ↓ ↓ ↓ ↓
import { i18n as _i18n } from "@lingui/core";
const a = _i18n._(
/*i18n*/
{
id: "esnaQO",
message: "{count, plural, one {# book} other {# books}}",
values: {
count: count,
},
}
);
`;
exports[`Macro with expression only choice 1`] = `
import { plural } from "@lingui/core/macro";
plural(users.length, {
offset: 1,
0: "No books",
1: "1 book",
other: someOtherExp,
});
↓ ↓ ↓ ↓ ↓ ↓
import { i18n as _i18n } from "@lingui/core";
_i18n._(
/*i18n*/
{
id: "0mcXIe",
message:
"{0, plural, offset:1 =0 {No books} =1 {1 book} other {{someOtherExp}}}",
values: {
0: users.length,
someOtherExp: someOtherExp,
},
}
);
`;
exports[`Macro with offset and exact matches 1`] = `
import { plural } from "@lingui/core/macro";
plural(users.length, {
offset: 1,
0: "No books",
1: "1 book",
other: "# books",
});
↓ ↓ ↓ ↓ ↓ ↓
import { i18n as _i18n } from "@lingui/core";
_i18n._(
/*i18n*/
{
id: "CF5t+7",
message: "{0, plural, offset:1 =0 {No books} =1 {1 book} other {# books}}",
values: {
0: users.length,
},
}
);
`;
exports[`plural macro could be renamed 1`] = `
import { plural as plural2 } from "@lingui/core/macro";
const a = plural2(count, {
one: \`# book\`,
other: "# books",
});
↓ ↓ ↓ ↓ ↓ ↓
import { i18n as _i18n } from "@lingui/core";
const a = _i18n._(
/*i18n*/
{
id: "esnaQO",
message: "{count, plural, one {# book} other {# books}}",
values: {
count: count,
},
}
);
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Nested macros 1`] = `
import { select, plural } from "@lingui/core/macro";
select(gender, {
male: plural(numOfGuests, {
one: "He invites one guest",
other: "He invites # guests",
}),
female: \`She is \${gender}\`,
other: \`They is \${gender}\`,
});
↓ ↓ ↓ ↓ ↓ ↓
import { i18n as _i18n } from "@lingui/core";
_i18n._(
/*i18n*/
{
id: "G8xqGf",
message:
"{gender, select, male {{numOfGuests, plural, one {He invites one guest} other {He invites # guests}}} female {She is {gender}} other {They is {gender}}}",
values: {
gender: gender,
numOfGuests: numOfGuests,
},
}
);
`;
exports[`Nested macros with pure expressions option 1`] = `
import { select, plural } from "@lingui/core/macro";
select(gender, {
male: plural(numOfGuests, {
one: "He invites one guest",
other: "He invites # guests",
}),
female: \`She is \${gender}\`,
other: someOtherExp,
});
↓ ↓ ↓ ↓ ↓ ↓
import { i18n as _i18n } from "@lingui/core";
_i18n._(
/*i18n*/
{
id: "j9PNNm",
message:
"{gender, select, male {{numOfGuests, plural, one {He invites one guest} other {He invites # guests}}} female {She is {gender}} other {{someOtherExp}}}",
values: {
gender: gender,
numOfGuests: numOfGuests,
someOtherExp: someOtherExp,
},
}
);
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`#1 1`] = `
import { t, selectOrdinal } from "@lingui/core/macro";
t\`This is my \${selectOrdinal(count, {
one: "#st",
two: \`#nd\`,
other: "#rd",
})} cat\`;
↓ ↓ ↓ ↓ ↓ ↓
import { i18n as _i18n } from "@lingui/core";
_i18n._(
/*i18n*/
{
id: "dJXd3T",
message:
"This is my {count, selectordinal, one {#st} two {#nd} other {#rd}} cat",
values: {
count: count,
},
}
);
`;

0 comments on commit afc962c

Please sign in to comment.