]> git.ardis.lu - csvio/commitdiff
Refactor CSVNormalizer.fixExcelBigInt suite to vectors
authorArdis Lu <ardisglu@gmail.com>
Tue, 21 Jan 2025 05:23:46 +0000 (21:23 -0800)
committerArdis Lu <ardisglu@gmail.com>
Tue, 21 Jan 2025 05:23:46 +0000 (21:23 -0800)
test/normalization.test.js

index 0e9c94d99ccc65751285f4c3ee144c1caa347474..dfd9cee95c2b2b79b8819c31f3eee19db1a3bad3 100644 (file)
@@ -84,27 +84,22 @@ suite('CSVNormalizer.fixExcelNumber', { concurrency: true }, () => {
 });
 
 suite('CSVNormalizer.fixExcelBigInt', { concurrency: true }, () => {
-  test('parses BigInt', { concurrency: true }, () => {
-    deepStrictEqual(CSVNormalizer.fixExcelBigInt('123'), '123');
-    deepStrictEqual(CSVNormalizer.fixExcelBigInt('123456'), '123456');
-    deepStrictEqual(CSVNormalizer.fixExcelBigInt('123456789123456789123456789'), '123456789123456789123456789');
-  });
-  test('fixes BigInt mangled to scientific notation', { concurrency: true }, () => {
-    deepStrictEqual(CSVNormalizer.fixExcelBigInt('1E+18'), '1000000000000000000');
-    deepStrictEqual(CSVNormalizer.fixExcelBigInt('1.123456789123456789E18'), '1123456789123456789');
-    deepStrictEqual(CSVNormalizer.fixExcelBigInt('1.1234567891234567891234E18'), '1123456789123456789');
-  });
-  test('fixes BigInt mangled to accounting format', { concurrency: true }, () => {
-    deepStrictEqual(CSVNormalizer.fixExcelBigInt(' $123.00 '), '123');
-    deepStrictEqual(CSVNormalizer.fixExcelBigInt(' $123.45 '), '123');
-    deepStrictEqual(CSVNormalizer.fixExcelBigInt('  $1,123,123,123,123,123,123.12  '), '1123123123123123123');
-  });
-  test('passes through non-BigInt values', { concurrency: true }, () => {
-    deepStrictEqual(CSVNormalizer.fixExcelBigInt('abc'), 'abc');
-  });
-  test('passes through blank value', { concurrency: true }, () => {
-    deepStrictEqual(CSVNormalizer.fixExcelBigInt(''), '');
-  });
+  const vectors = [
+    { name: 'parses BigInt', input: '123456789123456789123456789', output: '123456789123456789123456789' },
+    { name: 'fixes scientific notation mangling', input: '1E+18', output: '1000000000000000000' },
+    { name: 'fixes scientific notation mangling with decimal', input: '1.123456789123456789E18', output: '1123456789123456789' },
+    { name: 'fixes scientific notation mangling with decimal (truncated)', input: '1.1234567891234567891234E18', output: '1123456789123456789' },
+    { name: 'fixes accounting mangling integer', input: ' $123.00 ', output: '123' },
+    { name: 'fixes accounting mangling number (truncated)', input: ' $123.45 ', output: '123' },
+    { name: 'fixes accounting mangling BigInt with commas', input: '  $1,123,123,123,123,123,123.12  ', output: '1123123123123123123' },
+    { name: 'passes through non-BigInt values', input: 'abc', output: 'abc' },
+    { name: 'passes through blank value', input: '', output: '' },
+  ];
+  for (const { name, input, output } of vectors) {
+    test(name, { concurrency: true }, () => {
+      deepStrictEqual(CSVNormalizer.fixExcelBigInt(input), output);
+    });
+  }
 });
 
 suite('CSVNormalizer.fixExcelDate', { concurrency: true }, () => {
This page took 0.050087 seconds and 4 git commands to generate.