From: Ardis Lu Date: Tue, 11 Feb 2025 06:33:25 +0000 (-0800) Subject: Add additional tests for uncovered branches X-Git-Tag: v0.1.0~58 X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=fe3acfbc2bdf465a24ca0ffcd569b17b566040fa;p=csvio Add additional tests for uncovered branches --- diff --git a/test/core.test.js b/test/core.test.js index a02e4bd..3f0099f 100644 --- a/test/core.test.js +++ b/test/core.test.js @@ -212,6 +212,17 @@ suite('CSVTransformer', { concurrency: true }, () => { .pipeThrough(new CSVTransformer(r => r)) .pipeTo(csvStreamEqualWritable(csv)); }); + test('passes through raw input', { concurrency: true }, async () => { + await ReadableStream.from((function* () { + yield '["headerA","headerB"]'; + yield '["111","222"]'; + })()) + .pipeThrough(new CSVTransformer(r => r, { handleHeaders: true, rawInput: true })) + .pipeTo(csvStreamEqualWritable([ + ['headerA', 'headerB'], + ['111', '222'] + ])); + }); test('passes through raw output', { concurrency: true }, async () => { await createCSVMockStream([ ['columnA', 'columnB'], diff --git a/test/normalization.test.js b/test/normalization.test.js index 3463a23..1f01b8f 100644 --- a/test/normalization.test.js +++ b/test/normalization.test.js @@ -207,6 +207,51 @@ suite('CSVNormalizer', { concurrency: true }, () => { ['a', 'b'] ])); }); + test('can pass through numbers', { concurrency: true }, async () => { + await createCSVMockStream([ + ['columnA', 'columnB'], + ['123', '456'] + ]) + .pipeThrough(new CSVNormalizer([ + { name: 'columnA', type: 'number' }, + { name: 'columnB', type: 'number' } + ], { passthroughNumber: true })) + .pipeThrough(new CSVDenormalizer()) + .pipeTo(csvStreamEqualWritable([ + ['columnA', 'columnB'], + ['123', '456'] + ])); + }); + test('can pass through BigInt', { concurrency: true }, async () => { + await createCSVMockStream([ + ['columnA', 'columnB'], + ['123', '456'] + ]) + .pipeThrough(new CSVNormalizer([ + { name: 'columnA', type: 'bigint' }, + { name: 'columnB', type: 'bigint' } + ], { passthroughBigInt: true })) + .pipeThrough(new CSVDenormalizer()) + .pipeTo(csvStreamEqualWritable([ + ['columnA', 'columnB'], + ['123', '456'] + ])); + }); + test('can pass through date', { concurrency: true }, async () => { + await createCSVMockStream([ + ['columnA', 'columnB'], + ['2025-02-10', '2025-02-09'] + ]) + .pipeThrough(new CSVNormalizer([ + { name: 'columnA', type: 'date' }, + { name: 'columnB', type: 'date' } + ], { passthroughDate: true })) + .pipeThrough(new CSVDenormalizer()) + .pipeTo(csvStreamEqualWritable([ + ['columnA', 'columnB'], + ['2025-02-10', '2025-02-09'] + ])); + }); test('can ignore incorrect data types', { concurrency: true }, async (t) => { assertConsole(t, { warn: 2 }); await createCSVMockStream([