@@ -5,7 +5,7 @@ import ftl from "@fluent/dedent";
55
66import { FluentBundle } from '../esm/bundle' ;
77import { FluentResource } from '../esm/resource' ;
8- import { FluentType } from '../esm/types' ;
8+ import { FluentType , FluentNumber , FluentDateTime } from '../esm/types' ;
99
1010suite ( 'Variables' , function ( ) {
1111 let bundle , errs ;
@@ -171,45 +171,54 @@ suite('Variables', function() {
171171 } ) ;
172172
173173 suite ( 'and numbers' , function ( ) {
174- let args ;
175-
176174 suiteSetup ( function ( ) {
177175 bundle = new FluentBundle ( 'en-US' , { useIsolating : false } ) ;
178176 bundle . addResource ( new FluentResource ( ftl `
179177 foo = { $arg }
180178 ` ) ) ;
181- args = {
182- arg : 1
183- } ;
184179 } ) ;
185180
186181 test ( 'can be a number' , function ( ) {
187182 const msg = bundle . getMessage ( 'foo' ) ;
188- const val = bundle . formatPattern ( msg . value , args , errs ) ;
183+ const val = bundle . formatPattern ( msg . value , { arg : 1 } , errs ) ;
189184 assert . strictEqual ( val , '1' ) ;
190185 assert . strictEqual ( errs . length , 0 ) ;
191186 } ) ;
187+
188+ test ( 'can be a FluentNumber' , function ( ) {
189+ const arg = new FluentNumber ( 1 , { minimumFractionDigits : 2 } ) ;
190+ const msg = bundle . getMessage ( 'foo' ) ;
191+ const val = bundle . formatPattern ( msg . value , { arg} , errs ) ;
192+ assert . strictEqual ( val , '1.00' ) ;
193+ assert . strictEqual ( errs . length , 0 ) ;
194+ } ) ;
192195 } ) ;
193196
194197 suite ( 'and dates' , function ( ) {
195- let args , dtf ;
198+ let dtf ;
196199
197200 suiteSetup ( function ( ) {
198201 dtf = new Intl . DateTimeFormat ( 'en-US' ) ;
199202 bundle = new FluentBundle ( 'en-US' , { useIsolating : false } ) ;
200203 bundle . addResource ( new FluentResource ( ftl `
201204 foo = { $arg }
202205 ` ) ) ;
203- args = {
204- arg : new Date ( '2016-09-29' )
205- } ;
206206 } ) ;
207207
208208 test ( 'can be a date' , function ( ) {
209+ const arg = new Date ( '2016-09-29' ) ;
209210 const msg = bundle . getMessage ( 'foo' ) ;
210- const val = bundle . formatPattern ( msg . value , args , errs ) ;
211+ const val = bundle . formatPattern ( msg . value , { arg } , errs ) ;
211212 // format the date argument to account for the testrunner's timezone
212- assert . strictEqual ( val , dtf . format ( args . arg ) ) ;
213+ assert . strictEqual ( val , dtf . format ( arg ) ) ;
214+ assert . strictEqual ( errs . length , 0 ) ;
215+ } ) ;
216+
217+ test ( 'can be a FluentDateTime' , function ( ) {
218+ const arg = new FluentDateTime ( new Date ( '2016-09-29' ) , { weekday : "long" } ) ;
219+ const msg = bundle . getMessage ( 'foo' ) ;
220+ const val = bundle . formatPattern ( msg . value , { arg} , errs ) ;
221+ assert . strictEqual ( val , 'Thursday' ) ;
213222 assert . strictEqual ( errs . length , 0 ) ;
214223 } ) ;
215224 } ) ;
0 commit comments