Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(macro): snapshot testing #1912

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
},
}
);

`;
Loading
Loading