-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
65 lines (50 loc) · 1.31 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { build, iter, parse } from './index.js';
import test from 'node:test';
import * as assert from 'node:assert';
test('basic', t => {
const b = `a,b,c\n"f"oo","bar""?",zin""g\n"what""""x"`;
const out = parse(b);
assert.deepStrictEqual(out, [
['a', 'b', 'c'],
['f"oo', 'bar"?', 'zin""g'],
['what""x'],
]);
});
test('quote forever', t => {
const b = `"hello tehre lol,what\nzing`;
const out = parse(b);
assert.deepStrictEqual(out, [
['hello tehre lol,what\nzing'],
]);
});
test('check newline use', t => {
const out = parse(`"hello
there",123
456`);
assert.deepStrictEqual(out, [
['hello\nthere', '123'],
['456'],
]);
});
test('newline behavior', t => {
const b = `\n`;
const out = parse(b);
assert.deepStrictEqual(out, [
[],
[],
]);
});
test('enc', t => {
assert.strictEqual(build([['1', '2', '3']]), '1,2,3');
assert.strictEqual(build([['1,', '2\n', '3']]), '"1,","2\n",3');
assert.strictEqual(build([[1,2,3.25]]), '1,2,3.25');
const x = { toString() { return 'but,t'; }};
assert.strictEqual(build([[x, {}]]), '"but,t",[object Object]');
});
test('string', t => {
for (const row of iter('hello')) {
assert.deepStrictEqual(row, ['hello']);
}
const outAll = [...iter('hello\nthere')];
assert.deepStrictEqual(outAll, [['hello'], ['there']]);
});