|
| 1 | +import {outdent} from 'outdent'; |
1 | 2 | import {test} from './utils/test.js'; |
2 | 3 |
|
3 | 4 | const error = { |
@@ -104,6 +105,123 @@ test({ |
104 | 105 | { |
105 | 106 | code: 'const foo = 0b111', |
106 | 107 | options: [{number: {minimumDigits: 3, groupLength: 1}}] |
| 108 | + }, |
| 109 | + { |
| 110 | + code: outdent` |
| 111 | + const binary = 0b10101010; |
| 112 | + const octal = 0o76543210; |
| 113 | + const hexadecimal = 0xfedcba97; |
| 114 | + const number = 12345678.12345678e12345678; |
| 115 | + `, |
| 116 | + options: [{ |
| 117 | + onlyIfContainsSeparator: true |
| 118 | + }] |
| 119 | + }, |
| 120 | + { |
| 121 | + code: outdent` |
| 122 | + const binary = 0b1010_1010; |
| 123 | + const octal = 0o76543210; |
| 124 | + const hexadecimal = 0xfedcba97; |
| 125 | + const number = 12345678.12345678e12345678; |
| 126 | + `, |
| 127 | + options: [{ |
| 128 | + onlyIfContainsSeparator: true, |
| 129 | + binary: { |
| 130 | + onlyIfContainsSeparator: false |
| 131 | + } |
| 132 | + }] |
| 133 | + }, |
| 134 | + { |
| 135 | + code: outdent` |
| 136 | + const binary = 0b10_10_10_10; |
| 137 | + const octal = 0o76543210; |
| 138 | + const hexadecimal = 0xfedcba97; |
| 139 | + const number = 12345678.12345678e12345678; |
| 140 | + `, |
| 141 | + options: [{ |
| 142 | + onlyIfContainsSeparator: true, |
| 143 | + binary: { |
| 144 | + onlyIfContainsSeparator: false, |
| 145 | + groupLength: 2 |
| 146 | + } |
| 147 | + }] |
| 148 | + }, |
| 149 | + { |
| 150 | + code: outdent` |
| 151 | + const binary = 0b10101010; |
| 152 | + const octal = 0o7654_3210; |
| 153 | + const hexadecimal = 0xfe_dc_ba_97; |
| 154 | + const number = 12_345_678.123_456_78e12_345_678; |
| 155 | + `, |
| 156 | + options: [{ |
| 157 | + binary: { |
| 158 | + onlyIfContainsSeparator: true |
| 159 | + } |
| 160 | + }] |
| 161 | + }, |
| 162 | + { |
| 163 | + code: 'const foo = 12345', |
| 164 | + options: [{number: {onlyIfContainsSeparator: true}}] |
| 165 | + }, |
| 166 | + { |
| 167 | + code: 'const foo = 12345678', |
| 168 | + options: [{number: {onlyIfContainsSeparator: true}}] |
| 169 | + }, |
| 170 | + { |
| 171 | + code: 'const foo = 12_345', |
| 172 | + options: [{number: {onlyIfContainsSeparator: true}}] |
| 173 | + }, |
| 174 | + { |
| 175 | + code: 'const foo = 1789.123_432_42', |
| 176 | + options: [{number: {onlyIfContainsSeparator: true}}] |
| 177 | + }, |
| 178 | + { |
| 179 | + code: 'const foo = -100_000e+100_000', |
| 180 | + options: [{number: {onlyIfContainsSeparator: true}}] |
| 181 | + }, |
| 182 | + { |
| 183 | + code: 'const foo = -100000e+100000', |
| 184 | + options: [{number: {onlyIfContainsSeparator: true}}] |
| 185 | + }, |
| 186 | + { |
| 187 | + code: 'const foo = -282_932 - (1938 / 10_000) * .1 + 18.100_000_2', |
| 188 | + options: [{number: {onlyIfContainsSeparator: true}}] |
| 189 | + }, |
| 190 | + { |
| 191 | + code: 'const foo = 0xA_B_C_D_E', |
| 192 | + options: [{hexadecimal: {onlyIfContainsSeparator: true, groupLength: 1}}] |
| 193 | + }, |
| 194 | + { |
| 195 | + code: 'const foo = 0o7777', |
| 196 | + options: [{octal: {onlyIfContainsSeparator: true, minimumDigits: 4}}] |
| 197 | + }, |
| 198 | + { |
| 199 | + code: 'const foo = 0xABCDEF012', |
| 200 | + options: [{hexadecimal: {onlyIfContainsSeparator: true}}] |
| 201 | + }, |
| 202 | + { |
| 203 | + code: 'const foo = 0o777777', |
| 204 | + options: [{octal: {onlyIfContainsSeparator: true, minimumDigits: 3}}] |
| 205 | + }, |
| 206 | + { |
| 207 | + code: 'const foo = 0o777777', |
| 208 | + options: [{octal: {onlyIfContainsSeparator: true, minimumDigits: 3, groupLength: 2}}] |
| 209 | + }, |
| 210 | + { |
| 211 | + code: 'const foo = 0o777_777', |
| 212 | + options: [{octal: {onlyIfContainsSeparator: true, minimumDigits: 2, groupLength: 3}}] |
| 213 | + }, |
| 214 | + { |
| 215 | + code: 'const foo = 0b01010101', |
| 216 | + options: [{onlyIfContainsSeparator: true, binary: {onlyIfContainsSeparator: true}}] |
| 217 | + }, |
| 218 | + { |
| 219 | + code: 'const foo = 0b0101_0101', |
| 220 | + options: [{onlyIfContainsSeparator: false, binary: {onlyIfContainsSeparator: true}}] |
| 221 | + }, |
| 222 | + { |
| 223 | + code: 'const foo = 0b0101_0101', |
| 224 | + options: [{onlyIfContainsSeparator: false, binary: {onlyIfContainsSeparator: false}}] |
107 | 225 | } |
108 | 226 | ], |
109 | 227 | invalid: [ |
@@ -327,6 +445,93 @@ test({ |
327 | 445 | options: [{number: {minimumDigits: 3, groupLength: 2}}], |
328 | 446 | errors: [error], |
329 | 447 | output: 'const foo = 0b111' |
| 448 | + }, |
| 449 | + { |
| 450 | + code: 'const foo = -100000e+100000', |
| 451 | + options: [{number: {onlyIfContainsSeparator: false}}], |
| 452 | + errors: [error], |
| 453 | + output: 'const foo = -100_000e+100_000' |
| 454 | + }, |
| 455 | + { |
| 456 | + code: outdent` |
| 457 | + const binary = 0b10_101010; |
| 458 | + const octal = 0o76_543210; |
| 459 | + const hexadecimal = 0xfe_dcba97; |
| 460 | + const number = 12_345678.12345678e12345678; |
| 461 | + `, |
| 462 | + output: outdent` |
| 463 | + const binary = 0b1010_1010; |
| 464 | + const octal = 0o7654_3210; |
| 465 | + const hexadecimal = 0xfe_dc_ba_97; |
| 466 | + const number = 12_345_678.123_456_78e12_345_678; |
| 467 | + `, |
| 468 | + options: [{ |
| 469 | + onlyIfContainsSeparator: true |
| 470 | + }], |
| 471 | + errors: 4 |
| 472 | + }, |
| 473 | + { |
| 474 | + code: outdent` |
| 475 | + const binary = 0b10101010; |
| 476 | + const octal = 0o76_543210; |
| 477 | + const hexadecimal = 0xfe_dcba97; |
| 478 | + const number = 12_345678.12345678e12345678; |
| 479 | + `, |
| 480 | + output: outdent` |
| 481 | + const binary = 0b1010_1010; |
| 482 | + const octal = 0o7654_3210; |
| 483 | + const hexadecimal = 0xfe_dc_ba_97; |
| 484 | + const number = 12_345_678.123_456_78e12_345_678; |
| 485 | + `, |
| 486 | + options: [{ |
| 487 | + onlyIfContainsSeparator: true, |
| 488 | + binary: { |
| 489 | + onlyIfContainsSeparator: false |
| 490 | + } |
| 491 | + }], |
| 492 | + errors: 4 |
| 493 | + }, |
| 494 | + { |
| 495 | + code: outdent` |
| 496 | + const binary = 0b10101010; |
| 497 | + const octal = 0o76_543210; |
| 498 | + const hexadecimal = 0xfe_dcba97; |
| 499 | + const number = 12_345678.12345678e12345678; |
| 500 | + `, |
| 501 | + output: outdent` |
| 502 | + const binary = 0b10_10_10_10; |
| 503 | + const octal = 0o7654_3210; |
| 504 | + const hexadecimal = 0xfe_dc_ba_97; |
| 505 | + const number = 12_345_678.123_456_78e12_345_678; |
| 506 | + `, |
| 507 | + options: [{ |
| 508 | + onlyIfContainsSeparator: true, |
| 509 | + binary: { |
| 510 | + onlyIfContainsSeparator: false, |
| 511 | + groupLength: 2 |
| 512 | + } |
| 513 | + }], |
| 514 | + errors: 4 |
| 515 | + }, |
| 516 | + { |
| 517 | + code: outdent` |
| 518 | + const binary = 0b10_101010; |
| 519 | + const octal = 0o76543210; |
| 520 | + const hexadecimal = 0xfedcba97; |
| 521 | + const number = 12345678.12345678e12345678; |
| 522 | + `, |
| 523 | + output: outdent` |
| 524 | + const binary = 0b1010_1010; |
| 525 | + const octal = 0o7654_3210; |
| 526 | + const hexadecimal = 0xfe_dc_ba_97; |
| 527 | + const number = 12_345_678.123_456_78e12_345_678; |
| 528 | + `, |
| 529 | + options: [{ |
| 530 | + binary: { |
| 531 | + onlyIfContainsSeparator: true |
| 532 | + } |
| 533 | + }], |
| 534 | + errors: 4 |
330 | 535 | } |
331 | 536 | ] |
332 | 537 | }); |
|
0 commit comments