1+ import { test } from "tap" ;
12import { FormattingContext } from "../impl/context.js" ;
23import { Argument , Message , Parameter } from "../impl/model.js" ;
34import { REGISTRY } from "../impl/registry.js" ;
@@ -104,9 +105,7 @@ REGISTRY["ACTOR"] = function get_noun(
104105 }
105106} ;
106107
107- console . log ( "==== English ====" ) ;
108-
109- {
108+ test ( "NOUN is ADJECTIVE (English)" , ( tap ) => {
110109 let message : Message = {
111110 lang : "en" ,
112111 id : "accord" ,
@@ -135,159 +134,227 @@ console.log("==== English ====");
135134 } ,
136135 ] ,
137136 } ;
138- console . log (
137+
138+ tap . equal (
139139 formatMessage ( message , {
140140 item : new StringValue ( "t-shirt" ) ,
141141 color : new StringValue ( "red" ) ,
142- } )
142+ } ) ,
143+ "The T-shirt is red."
143144 ) ;
144145
145- console . log (
146- Array . of (
147- ...formatToParts ( message , {
148- item : new StringValue ( "t-shirt" ) ,
149- color : new StringValue ( "red" ) ,
150- } )
151- )
146+ tap . same (
147+ formatToParts ( message , {
148+ item : new StringValue ( "t-shirt" ) ,
149+ color : new StringValue ( "red" ) ,
150+ } ) ,
151+ [
152+ { type : "literal" , value : "The " } ,
153+ { type : "literal" , value : "T-shirt" } ,
154+ { type : "literal" , value : " is " } ,
155+ { type : "literal" , value : "red" } ,
156+ { type : "literal" , value : "." } ,
157+ ]
152158 ) ;
153- }
154159
155- {
160+ tap . end ( ) ;
161+ } ) ;
162+
163+ test ( "NOUN is ADJECTIVE (Polish; requires according the gender of the adjective)" , ( tap ) => {
156164 let message : Message = {
157- lang : "en " ,
158- id : "you-see " ,
165+ lang : "pl " ,
166+ id : "accord " ,
159167 phrases : { } ,
160168 selectors : [ ] ,
161169 variants : [
162170 {
163171 keys : [ ] ,
164172 value : [
165- { type : "StringLiteral" , value : "You see " } ,
166173 {
167174 type : "FunctionCall" ,
168- name : "ACTOR " ,
169- args : [ { type : "VariableReference" , name : "monster " } ] ,
175+ name : "NOUN " ,
176+ args : [ { type : "VariableReference" , name : "item " } ] ,
170177 opts : {
171- INDEFINITE : { type : "BooleanLiteral" , value : true } ,
178+ CAPITALIZED : { type : "BooleanLiteral" , value : true } ,
172179 } ,
173180 } ,
174- { type : "StringLiteral" , value : "!" } ,
181+ { type : "StringLiteral" , value : " jest " } ,
182+ {
183+ type : "FunctionCall" ,
184+ name : "ADJECTIVE" ,
185+ args : [ { type : "VariableReference" , name : "color" } ] ,
186+ opts : {
187+ ACCORD_WITH : { type : "VariableReference" , name : "item" } ,
188+ } ,
189+ } ,
190+ { type : "StringLiteral" , value : "." } ,
175191 ] ,
176192 } ,
177193 ] ,
178194 } ;
179- console . log (
195+
196+ tap . equal (
180197 formatMessage ( message , {
181- monster : new StringValue ( "dinosaur" ) ,
182- } )
198+ item : new StringValue ( "t-shirt" ) ,
199+ color : new StringValue ( "red" ) ,
200+ } ) ,
201+ "Tiszert jest czerwony."
183202 ) ;
184- }
185203
186- {
204+ tap . same (
205+ formatToParts ( message , {
206+ item : new StringValue ( "t-shirt" ) ,
207+ color : new StringValue ( "red" ) ,
208+ } ) ,
209+ [
210+ { type : "literal" , value : "Tiszert" } ,
211+ { type : "literal" , value : " jest " } ,
212+ { type : "literal" , value : "czerwony" } ,
213+ { type : "literal" , value : "." } ,
214+ ]
215+ ) ;
216+
217+ tap . end ( ) ;
218+ } ) ;
219+
220+ test ( "Subject verb OBJECT (English)" , ( tap ) => {
187221 let message : Message = {
188222 lang : "en" ,
189- id : "they-wave " ,
223+ id : "you-see " ,
190224 phrases : { } ,
191225 selectors : [ ] ,
192226 variants : [
193227 {
194228 keys : [ ] ,
195229 value : [
230+ { type : "StringLiteral" , value : "You see " } ,
196231 {
197232 type : "FunctionCall" ,
198233 name : "ACTOR" ,
199234 args : [ { type : "VariableReference" , name : "monster" } ] ,
200235 opts : {
201- DEFINITE : { type : "BooleanLiteral" , value : true } ,
202- CAPITALIZED : { type : "BooleanLiteral" , value : true } ,
236+ INDEFINITE : { type : "BooleanLiteral" , value : true } ,
203237 } ,
204238 } ,
205- { type : "StringLiteral" , value : " waves at you !" } ,
239+ { type : "StringLiteral" , value : "!" } ,
206240 ] ,
207241 } ,
208242 ] ,
209243 } ;
210- console . log (
244+
245+ tap . equal (
211246 formatMessage ( message , {
212- monster : new StringValue ( "ogre" ) ,
213- } )
247+ monster : new StringValue ( "dinosaur" ) ,
248+ } ) ,
249+ "You see a dinosaur!"
250+ ) ;
251+
252+ tap . same (
253+ formatToParts ( message , {
254+ monster : new StringValue ( "dinosaur" ) ,
255+ } ) ,
256+ [
257+ { type : "literal" , value : "You see " } ,
258+ { type : "literal" , value : "a dinosaur" } ,
259+ { type : "literal" , value : "!" } ,
260+ ]
214261 ) ;
215- }
216262
217- console . log ( "==== polski ====" ) ;
263+ tap . end ( ) ;
264+ } ) ;
218265
219- {
266+ test ( "Subject verb OBJECT (Polish; requires the accusative case)" , ( tap ) => {
220267 let message : Message = {
221268 lang : "pl" ,
222- id : "accord " ,
269+ id : "you-see " ,
223270 phrases : { } ,
224271 selectors : [ ] ,
225272 variants : [
226273 {
227274 keys : [ ] ,
228275 value : [
276+ { type : "StringLiteral" , value : "Widzisz " } ,
229277 {
230278 type : "FunctionCall" ,
231- name : "NOUN" ,
232- args : [ { type : "VariableReference" , name : "item" } ] ,
233- opts : {
234- CAPITALIZED : { type : "BooleanLiteral" , value : true } ,
235- } ,
236- } ,
237- { type : "StringLiteral" , value : " jest " } ,
238- {
239- type : "FunctionCall" ,
240- name : "ADJECTIVE" ,
241- args : [ { type : "VariableReference" , name : "color" } ] ,
279+ name : "ACTOR" ,
280+ args : [ { type : "VariableReference" , name : "monster" } ] ,
242281 opts : {
243- ACCORD_WITH : { type : "VariableReference " , name : "item " } ,
282+ CASE : { type : "StringLiteral " , value : "accusative " } ,
244283 } ,
245284 } ,
246- { type : "StringLiteral" , value : ". " } ,
285+ { type : "StringLiteral" , value : "! " } ,
247286 ] ,
248287 } ,
249288 ] ,
250289 } ;
251- console . log (
290+
291+ tap . equal (
252292 formatMessage ( message , {
253- item : new StringValue ( "t-shirt " ) ,
254- color : new StringValue ( "red" ) ,
255- } )
293+ monster : new StringValue ( "dinosaur " ) ,
294+ } ) ,
295+ "Widzisz dinozaura!"
256296 ) ;
257- }
258297
259- {
298+ tap . same (
299+ formatToParts ( message , {
300+ monster : new StringValue ( "dinosaur" ) ,
301+ } ) ,
302+ [
303+ { type : "literal" , value : "Widzisz " } ,
304+ { type : "literal" , value : "dinozaura" } ,
305+ { type : "literal" , value : "!" } ,
306+ ]
307+ ) ;
308+
309+ tap . end ( ) ;
310+ } ) ;
311+
312+ test ( "SUBJECT verb (English)" , ( tap ) => {
260313 let message : Message = {
261- lang : "pl " ,
262- id : "you-see " ,
314+ lang : "en " ,
315+ id : "they-wave " ,
263316 phrases : { } ,
264317 selectors : [ ] ,
265318 variants : [
266319 {
267320 keys : [ ] ,
268321 value : [
269- { type : "StringLiteral" , value : "Widzisz " } ,
270322 {
271323 type : "FunctionCall" ,
272324 name : "ACTOR" ,
273325 args : [ { type : "VariableReference" , name : "monster" } ] ,
274326 opts : {
275- CASE : { type : "StringLiteral" , value : "accusative" } ,
327+ DEFINITE : { type : "BooleanLiteral" , value : true } ,
328+ CAPITALIZED : { type : "BooleanLiteral" , value : true } ,
276329 } ,
277330 } ,
278- { type : "StringLiteral" , value : "!" } ,
331+ { type : "StringLiteral" , value : " waves at you !" } ,
279332 ] ,
280333 } ,
281334 ] ,
282335 } ;
283- console . log (
336+
337+ tap . equal (
284338 formatMessage ( message , {
285- monster : new StringValue ( "dinosaur" ) ,
286- } )
339+ monster : new StringValue ( "ogre" ) ,
340+ } ) ,
341+ "The ogre waves at you!"
342+ ) ;
343+
344+ tap . same (
345+ formatToParts ( message , {
346+ monster : new StringValue ( "ogre" ) ,
347+ } ) ,
348+ [
349+ { type : "literal" , value : "The ogre" } ,
350+ { type : "literal" , value : " waves at you!" } ,
351+ ]
287352 ) ;
288- }
289353
290- {
354+ tap . end ( ) ;
355+ } ) ;
356+
357+ test ( "SUBJECT verb (Polish)" , ( tap ) => {
291358 let message : Message = {
292359 lang : "pl" ,
293360 id : "they-wave" ,
@@ -312,9 +379,22 @@ console.log("==== polski ====");
312379 ] ,
313380 } ;
314381
315- console . log (
382+ tap . equal (
316383 formatMessage ( message , {
317384 monster : new StringValue ( "ogre" ) ,
318- } )
385+ } ) ,
386+ "Ogr macha do ciebie!"
387+ ) ;
388+
389+ tap . same (
390+ formatToParts ( message , {
391+ monster : new StringValue ( "ogre" ) ,
392+ } ) ,
393+ [
394+ { type : "literal" , value : "Ogr" } ,
395+ { type : "literal" , value : " macha do ciebie!" } ,
396+ ]
319397 ) ;
320- }
398+
399+ tap . end ( ) ;
400+ } ) ;
0 commit comments