generated from PrismarineJS/prismarine-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic.test.js
64 lines (56 loc) · 2.03 KB
/
basic.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
/* eslint-env mocha */
const dumbcsv = require('dumb-csv')
const assert = require('assert')
describe('basic', () => {
it('works', () => {
const json = dumbcsv
.fromCSV({ data: 'hello,world', headerFields: ['a', 'b'] })
.toJSON()
assert.deepEqual(json, [{ a: 'hello', b: 'world' }])
})
it('tsv works', () => {
const json = dumbcsv
.fromCSV({ data: 'hello\tworld', separator: '\t', headerFields: ['a', 'b'] })
.toJSON()
assert.deepEqual(json, [{ a: 'hello', b: 'world' }])
})
it('works with quotes', () => {
const json = dumbcsv
.fromCSV({ data: 'hello,"world"', headerFields: ['a', 'b'] })
.toJSON()
assert.deepEqual(json, [{ a: 'hello', b: 'world' }])
})
it('escapes with backticks', () => {
const json = dumbcsv
.fromCSV({ data: 'hello,"\\"world\\""', separator: ',', headerFields: ['a', 'b'] })
.toJSON()
assert.deepEqual(json, [{ a: 'hello', b: '"world"' }])
})
it('escapes with double quotes', () => {
const json = dumbcsv
.fromCSV({ data: 'hello,"""world"""', separator: ',', headerFields: ['a', 'b'] })
.toJSON()
assert.deepEqual(json, [{ a: 'hello', b: '"world"' }])
})
it('parses floats', () => {
const json = dumbcsv
.fromCSV({ data: 'hello,world,3.14159', headerFields: ['a', 'b', 'c'] })
.toJSON()
console.log(json)
assert.deepStrictEqual(json, [{ a: 'hello', b: 'world', c: 3.14159 }])
})
it('NOT parses bad floats', () => {
const json = dumbcsv
.fromCSV({ data: '436E0248,3.141592653589793238462643383279502884197,3.14159', headerFields: ['a', 'b', 'c'] })
.toJSON()
console.log(json)
assert.deepStrictEqual(json, [{ a: '436E0248', b: '3.141592653589793238462643383279502884197', c: 3.14159 }])
})
it('NOT parses floats', () => {
const json = dumbcsv
.fromCSV({ data: 'hello,world,3.14159', headerFields: ['a', 'b', 'c'], parseFloats: false })
.toJSON()
console.log(json)
assert.deepStrictEqual(json, [{ a: 'hello', b: 'world', c: '3.14159' }])
})
})