11import { compileMessage as compile } from "@lingui/message-utils/compileMessage"
2- import { mockEnv , mockConsole } from "@lingui/jest-mocks"
32import { interpolate } from "./interpolate"
43import { Locale , Locales } from "./i18n"
54
@@ -9,15 +8,6 @@ describe("interpolate", () => {
98 return interpolate ( tokens , locale || "en" , locales )
109 }
1110
12- it ( "should handle an error if message has syntax errors" , ( ) => {
13- mockConsole ( ( console ) => {
14- expect ( compile ( "Invalid {message" ) ) . toEqual ( "Invalid {message" )
15- expect ( console . error ) . toBeCalledWith (
16- expect . stringMatching ( "Unexpected message end at line" )
17- )
18- } )
19- } )
20-
2111 it ( "should process string chunks with provided map fn" , ( ) => {
2212 const tokens = compile (
2313 "Message {value, plural, one {{value} Book} other {# Books}}" ,
@@ -36,28 +26,18 @@ describe("interpolate", () => {
3626 ] )
3727 } )
3828
39- it ( "should compile static message" , ( ) => {
40- const cache = compile ( "Static message" )
41- expect ( cache ) . toEqual ( "Static message" )
42-
43- mockEnv ( "production" , ( ) => {
44- const cache = compile ( "Static message" )
45- expect ( cache ) . toEqual ( "Static message" )
46- } )
47- } )
48-
49- it ( "should compile message with variable" , ( ) => {
29+ it ( "should interpolate message with variable" , ( ) => {
5030 const cache = compile ( "Hey {name}!" )
5131 expect ( interpolate ( cache , "en" , [ ] ) ( { name : "Joe" } ) ) . toEqual ( "Hey Joe!" )
5232 } )
5333
5434 it ( "should not interpolate escaped placeholder" , ( ) => {
5535 const msg = prepare ( "Hey '{name}'!" )
5636
57- expect ( msg ( { } ) ) . toEqual ( "Hey {name}!" )
37+ expect ( msg ( { name : "Joe" } ) ) . toEqual ( "Hey {name}!" )
5838 } )
5939
60- it ( "should compile plurals" , ( ) => {
40+ it ( "should interpolate plurals" , ( ) => {
6141 const plural = prepare (
6242 "{value, plural, one {{value} Book} other {# Books}}"
6343 )
@@ -72,7 +52,7 @@ describe("interpolate", () => {
7252 expect ( offset ( { value : 3 } ) ) . toEqual ( "2 Books" )
7353 } )
7454
75- it ( "should compile plurals with falsy value choice" , ( ) => {
55+ it ( "should interpolate plurals with falsy value choice" , ( ) => {
7656 const plural = prepare ( "{value, plural, one {} other {# Books}}" )
7757 expect ( plural ( { value : 1 } ) ) . toEqual ( "" )
7858 expect ( plural ( { value : 2 } ) ) . toEqual ( "2 Books" )
@@ -85,7 +65,7 @@ describe("interpolate", () => {
8565 expect ( plural ( { value : 30 } ) ) . toEqual ( "30% discount" )
8666 } )
8767
88- it ( "should compile selectordinal" , ( ) => {
68+ it ( "should interpolate selectordinal" , ( ) => {
8969 const cache = prepare (
9070 "{value, selectordinal, one {#st Book} two {#nd Book}}"
9171 )
@@ -119,7 +99,7 @@ describe("interpolate", () => {
11999 )
120100 } )
121101
122- it ( "should compile select" , ( ) => {
102+ it ( "should interpolate select" , ( ) => {
123103 const cache = prepare ( "{value, select, female {She} other {They}}" )
124104 expect ( cache ( { value : "female" } ) ) . toEqual ( "She" )
125105 expect ( cache ( { value : "n/a" } ) ) . toEqual ( "They" )
@@ -161,7 +141,7 @@ describe("interpolate", () => {
161141 expectedCurrency2 ,
162142 ] = tc
163143
164- it ( `should compile custom format for locale=${ locale } and locales=${ locales } ` , ( ) => {
144+ it ( `should interpolate custom format for locale=${ locale } and locales=${ locales } ` , ( ) => {
165145 const number = prepare ( "{value, number}" , locale , locales )
166146 expect ( number ( { value : 0.1 } ) ) . toEqual ( expectedNumber )
167147
0 commit comments