-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.js
62 lines (53 loc) · 1.86 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
var test = require('tape')
var index = require('.')
test('line', function (t) {
t.deepEqual(index.line('FOO=BAR'), {name: 'FOO', value: 'BAR'})
t.deepEqual(index.line('FOO=\'BAR\''), {name: 'FOO', value: '\'BAR\''})
t.deepEqual(index.line('FOO="BAR"'), {name: 'FOO', value: '"BAR"'})
t.deepEqual(index.line('export FOO=BAR'), {name: 'FOO', value: 'BAR'})
t.deepEqual(index.line('#export FOO=BAR'), undefined)
t.deepEqual(index.line(' # export FOO = BAR '), undefined)
t.deepEqual(index.line('FOO = BAR '), {name: 'FOO', value: 'BAR'})
t.deepEqual(index.line(' FOO = BAR'), {name: 'FOO', value: 'BAR'})
t.deepEqual(index.line('exported = Yes '), {name: 'exported', value: 'Yes'})
t.deepEqual(index.line('export ed = Yes '), {name: 'ed', value: 'Yes'})
t.deepEqual(index.line('export A='), {name: 'A', value: ''})
t.deepEqual(index.line('MULTILINE_VAR="I\\nlike\\ntrains"'), {name: 'MULTILINE_VAR', value: '"I\\nlike\\ntrains"'})
t.end()
})
test('text', function (t) {
t.equal(
index.outText([
'FOO=BAR',
' BAZ = "BING" ',
' export ROO = TOO '
].join('\n')),
[
'export FOO=BAR',
'export BAZ="BING"',
'export ROO=TOO'
].join('\n')
)
t.end()
})
test('escapes', function (t) {
t.equal(
index.outText([
'DB_PASS="some`password"',
'DB_PASS2="some${foo}password"',
'DB_PASS3="some$password"',
'DB_PASS4="some{password"',
'DB_PASS5="some}password"',
'MULTILINE_VAR="I\\nlike\\ntrains"'
].join('\n')),
[
'export DB_PASS="some\\`password"',
'export DB_PASS2="some\\$\\{foo\\}password"',
'export DB_PASS3="some\\$password"',
'export DB_PASS4="some\\{password"',
'export DB_PASS5="some\\}password"',
'export MULTILINE_VAR="I\\nlike\\ntrains"'
].join('\n')
)
t.end()
})