@@ -114,17 +114,64 @@ test('formatBreakpointMods', () => {
114114 expect ( formatBreakpointMods ( { default : 'column' , lg : 'row' } , styles ) ) . toEqual ( 'pf-m-column pf-m-row-on-lg' ) ;
115115} ) ;
116116
117- test ( 'parseLocalizedDecimal accepts dot and comma decimal separators ' , ( ) => {
117+ test ( 'parseLocalizedDecimal accepts locale-formatted decimals ' , ( ) => {
118118 const enFormatter = new Intl . NumberFormat ( 'en' ) ;
119119 const esFormatter = new Intl . NumberFormat ( 'es' ) ;
120+ const deFormatter = new Intl . NumberFormat ( 'de-DE' ) ;
120121
121122 expect ( parseLocalizedDecimal ( '50.2' , enFormatter ) ) . toBe ( 50.2 ) ;
122123 expect ( parseLocalizedDecimal ( '50,2' , esFormatter ) ) . toBe ( 50.2 ) ;
123- expect ( parseLocalizedDecimal ( '1.234,56 ' , esFormatter ) ) . toBe ( 1234.56 ) ;
124+ expect ( parseLocalizedDecimal ( '12.345,67 ' , esFormatter ) ) . toBe ( 12345.67 ) ;
124125 expect ( parseLocalizedDecimal ( '1,234.56' , enFormatter ) ) . toBe ( 1234.56 ) ;
126+ expect ( parseLocalizedDecimal ( '1.234,56' , deFormatter ) ) . toBe ( 1234.56 ) ;
125127 expect ( parseLocalizedDecimal ( '' , enFormatter ) ) . toBeNaN ( ) ;
126128} ) ;
127129
130+ test ( 'parseLocalizedDecimal rejects mismatched separators' , ( ) => {
131+ const enFormatter = new Intl . NumberFormat ( 'en-US' ) ;
132+ const deFormatter = new Intl . NumberFormat ( 'de-DE' ) ;
133+ const deNoGrouping = new Intl . NumberFormat ( 'de-DE' , { useGrouping : false } ) ;
134+
135+ // Comma used as decimal in en-US would otherwise silently merge to 502
136+ expect ( parseLocalizedDecimal ( '50,2' , enFormatter ) ) . toBeNaN ( ) ;
137+ // Dot used as decimal in de-DE would otherwise silently merge to 502
138+ expect ( parseLocalizedDecimal ( '50.2' , deFormatter ) ) . toBeNaN ( ) ;
139+ // Mixed separators for de-DE
140+ expect ( parseLocalizedDecimal ( '1,234.56' , deFormatter ) ) . toBeNaN ( ) ;
141+ // Without a reported group separator, alternate '.' must not be stripped/merged
142+ expect ( parseLocalizedDecimal ( '1.234,56' , deNoGrouping ) ) . toBeNaN ( ) ;
143+ expect ( parseLocalizedDecimal ( '50,2' , deNoGrouping ) ) . toBe ( 50.2 ) ;
144+ } ) ;
145+
146+ test ( 'parseLocalizedDecimal accepts locale-specific grouping patterns' , ( ) => {
147+ const enINFormatter = new Intl . NumberFormat ( 'en-IN' ) ;
148+ const enUSFormatter = new Intl . NumberFormat ( 'en-US' ) ;
149+ const esFormatter = new Intl . NumberFormat ( 'es' ) ;
150+
151+ expect ( parseLocalizedDecimal ( '12,34,567' , enINFormatter ) ) . toBe ( 1234567 ) ;
152+ expect ( parseLocalizedDecimal ( '12,345' , enINFormatter ) ) . toBe ( 12345 ) ;
153+ expect ( parseLocalizedDecimal ( '1,234' , enINFormatter ) ) . toBe ( 1234 ) ;
154+ expect ( parseLocalizedDecimal ( '1,23,4567' , enINFormatter ) ) . toBeNaN ( ) ;
155+ expect ( parseLocalizedDecimal ( '50,2' , enUSFormatter ) ) . toBeNaN ( ) ;
156+ expect ( parseLocalizedDecimal ( '1.234,56' , esFormatter ) ) . toBeNaN ( ) ;
157+ } ) ;
158+
159+ test ( 'parseLocalizedDecimal rejects malformed numeric tokens' , ( ) => {
160+ const enFormatter = new Intl . NumberFormat ( 'en-US' ) ;
161+
162+ expect ( parseLocalizedDecimal ( '12abc' , enFormatter ) ) . toBeNaN ( ) ;
163+ expect ( parseLocalizedDecimal ( '1,2abc' , enFormatter ) ) . toBeNaN ( ) ;
164+ expect ( parseLocalizedDecimal ( '12-3' , enFormatter ) ) . toBeNaN ( ) ;
165+ expect ( parseLocalizedDecimal ( '--12' , enFormatter ) ) . toBeNaN ( ) ;
166+ expect ( parseLocalizedDecimal ( '+-12' , enFormatter ) ) . toBeNaN ( ) ;
167+ expect ( parseLocalizedDecimal ( '12.3.4' , enFormatter ) ) . toBeNaN ( ) ;
168+ expect ( parseLocalizedDecimal ( 'abc' , enFormatter ) ) . toBeNaN ( ) ;
169+
170+ expect ( parseLocalizedDecimal ( '-50.2' , enFormatter ) ) . toBe ( - 50.2 ) ;
171+ expect ( parseLocalizedDecimal ( '+12' , enFormatter ) ) . toBe ( 12 ) ;
172+ expect ( parseLocalizedDecimal ( '1,234.56' , enFormatter ) ) . toBe ( 1234.56 ) ;
173+ } ) ;
174+
128175test ( 'formatLocalizedDecimal uses locale decimal separator' , ( ) => {
129176 expect ( formatLocalizedDecimal ( 50.2 , new Intl . NumberFormat ( 'en-US' ) ) ) . toBe ( '50.2' ) ;
130177 expect ( formatLocalizedDecimal ( 50.2 , new Intl . NumberFormat ( 'de-DE' ) ) ) . toBe ( '50,2' ) ;
0 commit comments