forked from lingui/js-lingui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(macro): snapshot testing (lingui#1912)
- Loading branch information
1 parent
6bb8983
commit afc962c
Showing
32 changed files
with
3,400 additions
and
2,336 deletions.
There are no files selected for viewing
203 changes: 203 additions & 0 deletions
203
packages/babel-plugin-lingui-macro/test/__snapshots__/js-defineMessage.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}; | ||
`; |
99 changes: 99 additions & 0 deletions
99
packages/babel-plugin-lingui-macro/test/__snapshots__/js-plural.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
} | ||
); | ||
`; |
60 changes: 60 additions & 0 deletions
60
packages/babel-plugin-lingui-macro/test/__snapshots__/js-select.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
} | ||
); | ||
`; |
26 changes: 26 additions & 0 deletions
26
packages/babel-plugin-lingui-macro/test/__snapshots__/js-selectOrdinal.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
} | ||
); | ||
`; |
Oops, something went wrong.