5
5
*
6
6
* Copyright Oxide Computer Company
7
7
*/
8
- import { afterAll , beforeAll , describe , expect , it } from 'vitest'
9
-
10
- import {
11
- displayBigNum ,
12
- nearest10 ,
13
- percentage ,
14
- round ,
15
- splitDecimal ,
16
- toEngNotation ,
17
- } from './math'
8
+ import { describe , expect , it } from 'vitest'
9
+
10
+ import { displayBigNum , nearest10 , percentage , round , splitDecimal } from './math'
18
11
import { GiB } from './units'
19
12
20
13
function roundTest ( ) {
@@ -119,15 +112,6 @@ describe('with default locale', () => {
119
112
} )
120
113
121
114
describe ( 'with de-DE locale' , ( ) => {
122
- const originalLanguage = global . navigator . language
123
-
124
- beforeAll ( ( ) => {
125
- Object . defineProperty ( global . navigator , 'language' , {
126
- value : 'de-DE' ,
127
- writable : true ,
128
- } )
129
- } )
130
-
131
115
it . each ( [
132
116
[ 0.23 , [ '0' , ',23' ] ] ,
133
117
[ 0.236 , [ '0' , ',24' ] ] ,
@@ -150,17 +134,14 @@ describe('with de-DE locale', () => {
150
134
[ - 50.2 , [ '-50' , ',2' ] ] , // should correctly not round down to -51
151
135
[ 1000.5 , [ '1.000' , ',5' ] ] , // test localeString grouping
152
136
] ) ( 'splitDecimal %d -> %s' , ( input , output ) => {
153
- expect ( splitDecimal ( input ) ) . toEqual ( output )
137
+ expect ( splitDecimal ( input , 'de-DE' ) ) . toEqual ( output )
154
138
} )
155
139
156
- // rounding must work the same irrespective of locale
157
- it ( 'round' , roundTest )
158
-
159
140
it . each ( [
160
141
[ 0n , [ '0' , false ] ] ,
161
142
[ 1n , [ '1' , false ] ] ,
162
143
[ 155n , [ '155' , false ] ] ,
163
- [ 999999n , [ '999, 999' , false ] ] ,
144
+ [ 999999n , [ '999. 999' , false ] ] ,
164
145
[ 1000000n , [ '1 Mio.' , true ] ] ,
165
146
[ 1234567n , [ '1,2 Mio.' , true ] ] ,
166
147
[ 9999999n , [ '10 Mio.' , true ] ] , // note non-breaking space
@@ -169,14 +150,7 @@ describe('with de-DE locale', () => {
169
150
[ 1293859032098219 , [ '1,3e15' , true ] ] ,
170
151
[ 23094304823948203952304920342n , [ '23,1e27' , true ] ] ,
171
152
] ) ( 'displayBigNum %d -> %s' , ( input , output ) => {
172
- expect ( displayBigNum ( input ) ) . toEqual ( output )
173
- } )
174
-
175
- afterAll ( ( ) => {
176
- Object . defineProperty ( global . navigator , 'language' , {
177
- value : originalLanguage ,
178
- writable : true ,
179
- } )
153
+ expect ( displayBigNum ( input , 'de-DE' ) ) . toEqual ( output )
180
154
} )
181
155
} )
182
156
@@ -195,8 +169,8 @@ it.each([
195
169
[ 'en-CA' ] ,
196
170
[ 'en-IN' ] ,
197
171
[ 'ko-KR' ] ,
198
- ] ) ( 'toEngNotation dots %s' , ( locale ) => {
199
- expect ( toEngNotation ( n , locale ) ) . toEqual ( '23.1e27' )
172
+ ] ) ( 'displayBigNum dots %s' , ( locale ) => {
173
+ expect ( displayBigNum ( n , locale ) ) . toEqual ( [ '23.1e27' , true ] )
200
174
} )
201
175
202
176
it . each ( [
@@ -212,8 +186,8 @@ it.each([
212
186
[ 'tr-TR' ] ,
213
187
[ 'pt-PT' ] ,
214
188
// ['ar-SA'], // saudi arabia, arabic script
215
- ] ) ( 'toEngNotation commas %s' , ( locale ) => {
216
- expect ( toEngNotation ( n , locale ) ) . toEqual ( '23,1e27' )
189
+ ] ) ( 'displayBigNum commas %s' , ( locale ) => {
190
+ expect ( displayBigNum ( n , locale ) ) . toEqual ( [ '23,1e27' , true ] )
217
191
} )
218
192
219
193
it . each ( [
0 commit comments