@@ -14,7 +14,8 @@ suite("Built-in functions", function () {
1414 bundle . addResource (
1515 new FluentResource ( ftl `
1616 num-bare = { NUMBER($arg) }
17- num-fraction-valid = { NUMBER($arg, minimumFractionDigits: 1) }
17+ num-fraction-literal = { NUMBER($arg, minimumFractionDigits: 1) }
18+ num-fraction-variable = { NUMBER($arg, minimumFractionDigits: $mfd) }
1819 num-fraction-bad = { NUMBER($arg, minimumFractionDigits: "oops") }
1920 num-style = { NUMBER($arg, style: "percent") }
2021 num-currency = { NUMBER($arg, currency: "EUR") }
@@ -35,7 +36,7 @@ suite("Built-in functions", function () {
3536 assert . strictEqual ( errors [ 0 ] . message , "Unknown variable: $arg" ) ;
3637
3738 errors = [ ] ;
38- msg = bundle . getMessage ( "num-fraction-valid " ) ;
39+ msg = bundle . getMessage ( "num-fraction-literal " ) ;
3940 assert . strictEqual (
4041 bundle . formatPattern ( msg . value , { } , errors ) ,
4142 "{NUMBER($arg)}"
@@ -44,6 +45,18 @@ suite("Built-in functions", function () {
4445 assert . ok ( errors [ 0 ] instanceof ReferenceError ) ;
4546 assert . strictEqual ( errors [ 0 ] . message , "Unknown variable: $arg" ) ;
4647
48+ errors = [ ] ;
49+ msg = bundle . getMessage ( "num-fraction-variable" ) ;
50+ assert . strictEqual (
51+ bundle . formatPattern ( msg . value , { } , errors ) ,
52+ "{NUMBER($arg)}"
53+ ) ;
54+ assert . strictEqual ( errors . length , 2 ) ;
55+ assert . ok ( errors [ 0 ] instanceof ReferenceError ) ;
56+ assert . strictEqual ( errors [ 0 ] . message , "Unknown variable: $arg" ) ;
57+ assert . ok ( errors [ 1 ] instanceof ReferenceError ) ;
58+ assert . strictEqual ( errors [ 1 ] . message , "Unknown variable: $mfd" ) ;
59+
4760 errors = [ ] ;
4861 msg = bundle . getMessage ( "num-fraction-bad" ) ;
4962 assert . strictEqual (
@@ -97,13 +110,21 @@ suite("Built-in functions", function () {
97110 assert . strictEqual ( errors . length , 0 ) ;
98111
99112 errors = [ ] ;
100- msg = bundle . getMessage ( "num-fraction-valid " ) ;
113+ msg = bundle . getMessage ( "num-fraction-literal " ) ;
101114 assert . strictEqual (
102115 bundle . formatPattern ( msg . value , { arg } , errors ) ,
103116 "1,234.0"
104117 ) ;
105118 assert . strictEqual ( errors . length , 0 ) ;
106119
120+ errors = [ ] ;
121+ msg = bundle . getMessage ( "num-fraction-variable" ) ;
122+ assert . strictEqual (
123+ bundle . formatPattern ( msg . value , { arg, mfd : 1 } , errors ) ,
124+ "1,234.0"
125+ ) ;
126+ assert . strictEqual ( errors . length , 0 ) ;
127+
107128 errors = [ ] ;
108129 msg = bundle . getMessage ( "num-fraction-bad" ) ;
109130 assert . strictEqual (
@@ -152,13 +173,22 @@ suite("Built-in functions", function () {
152173 assert . strictEqual ( errors . length , 0 ) ;
153174
154175 errors = [ ] ;
155- msg = bundle . getMessage ( "num-fraction-valid " ) ;
176+ msg = bundle . getMessage ( "num-fraction-literal " ) ;
156177 assert . strictEqual (
157178 bundle . formatPattern ( msg . value , { arg } , errors ) ,
158179 "1,234.0"
159180 ) ;
160181 assert . strictEqual ( errors . length , 0 ) ;
161182
183+ errors = [ ] ;
184+ msg = bundle . getMessage ( "num-fraction-variable" ) ;
185+ const mfd = new FluentNumber ( 1 ) ;
186+ assert . strictEqual (
187+ bundle . formatPattern ( msg . value , { arg, mfd } , errors ) ,
188+ "1,234.0"
189+ ) ;
190+ assert . strictEqual ( errors . length , 0 ) ;
191+
162192 errors = [ ] ;
163193 msg = bundle . getMessage ( "num-fraction-bad" ) ;
164194 assert . strictEqual (
@@ -208,13 +238,22 @@ suite("Built-in functions", function () {
208238 assert . strictEqual ( errors . length , 0 ) ;
209239
210240 errors = [ ] ;
211- msg = bundle . getMessage ( "num-fraction-valid " ) ;
241+ msg = bundle . getMessage ( "num-fraction-literal " ) ;
212242 assert . strictEqual (
213243 bundle . formatPattern ( msg . value , { arg } , errors ) ,
214244 "$1,234.0"
215245 ) ;
216246 assert . strictEqual ( errors . length , 0 ) ;
217247
248+ errors = [ ] ;
249+ msg = bundle . getMessage ( "num-fraction-variable" ) ;
250+ const mfd = new FluentNumber ( 1 , { style : "currency" , currency : "USD" } ) ;
251+ assert . strictEqual (
252+ bundle . formatPattern ( msg . value , { arg, mfd } , errors ) ,
253+ "$1,234.0"
254+ ) ;
255+ assert . strictEqual ( errors . length , 0 ) ;
256+
218257 errors = [ ] ;
219258 msg = bundle . getMessage ( "num-fraction-bad" ) ;
220259 assert . strictEqual (
@@ -266,7 +305,7 @@ suite("Built-in functions", function () {
266305 assert . strictEqual ( errors . length , 0 ) ;
267306
268307 errors = [ ] ;
269- msg = bundle . getMessage ( "num-fraction-valid " ) ;
308+ msg = bundle . getMessage ( "num-fraction-literal " ) ;
270309 assert . strictEqual (
271310 bundle . formatPattern ( msg . value , { arg } , errors ) ,
272311 "1,475,107,200,000.0"
@@ -288,7 +327,7 @@ suite("Built-in functions", function () {
288327 assert . strictEqual ( errors [ 0 ] . message , "Invalid argument to NUMBER" ) ;
289328
290329 errors = [ ] ;
291- msg = bundle . getMessage ( "num-fraction-valid " ) ;
330+ msg = bundle . getMessage ( "num-fraction-literal " ) ;
292331 assert . strictEqual (
293332 bundle . formatPattern ( msg . value , { arg } , errors ) ,
294333 "{NUMBER()}"
@@ -297,6 +336,14 @@ suite("Built-in functions", function () {
297336 assert . ok ( errors [ 0 ] instanceof TypeError ) ;
298337 assert . strictEqual ( errors [ 0 ] . message , "Invalid argument to NUMBER" ) ;
299338
339+ errors = [ ] ;
340+ msg = bundle . getMessage ( "num-fraction-variable" ) ;
341+ assert . strictEqual (
342+ bundle . formatPattern ( msg . value , { arg : 10 , mfd : " 1 " } , errors ) ,
343+ "10.0"
344+ ) ;
345+ assert . strictEqual ( errors . length , 0 ) ;
346+
300347 errors = [ ] ;
301348 msg = bundle . getMessage ( "num-fraction-bad" ) ;
302349 assert . strictEqual (
@@ -350,7 +397,7 @@ suite("Built-in functions", function () {
350397 assert . strictEqual ( errors . length , 0 ) ;
351398
352399 errors = [ ] ;
353- msg = bundle . getMessage ( "num-fraction-valid " ) ;
400+ msg = bundle . getMessage ( "num-fraction-literal " ) ;
354401 assert . strictEqual (
355402 bundle . formatPattern ( msg . value , { arg } , errors ) ,
356403 "1,475,107,200,000.0"
@@ -408,7 +455,7 @@ suite("Built-in functions", function () {
408455 ) ;
409456
410457 errors = [ ] ;
411- msg = bundle . getMessage ( "num-fraction-valid " ) ;
458+ msg = bundle . getMessage ( "num-fraction-literal " ) ;
412459 assert . strictEqual (
413460 bundle . formatPattern ( msg . value , { arg } , errors ) ,
414461 "{NUMBER($arg)}"
@@ -420,6 +467,20 @@ suite("Built-in functions", function () {
420467 "Variable type not supported: $arg, object"
421468 ) ;
422469
470+ errors = [ ] ;
471+ msg = bundle . getMessage ( "num-fraction-variable" ) ;
472+ assert . strictEqual (
473+ bundle . formatPattern ( msg . value , { arg : 10 , mfd : [ ] } , errors ) ,
474+ "10"
475+ ) ;
476+ assert . strictEqual ( errors . length , 2 ) ;
477+ assert . ok ( errors [ 0 ] instanceof TypeError ) ;
478+ assert . strictEqual (
479+ errors [ 0 ] . message ,
480+ "Variable type not supported: $mfd, object"
481+ ) ;
482+ assert . ok ( errors [ 1 ] instanceof RangeError ) ;
483+
423484 errors = [ ] ;
424485 msg = bundle . getMessage ( "num-fraction-bad" ) ;
425486 assert . strictEqual (
0 commit comments