2
2
3
3
var test = require ( 'tape' )
4
4
var cept = require ( 'cept' )
5
- var toJSON = require ( '.' )
5
+ var toJson = require ( '.' )
6
6
7
- test ( 'toJSON ' , function ( t ) {
8
- t . equal ( typeof toJSON , 'function' , 'should be a `function`' )
7
+ test ( 'toJson ' , function ( t ) {
8
+ t . equal ( typeof toJson , 'function' , 'should be a `function`' )
9
9
t . end ( )
10
10
} )
11
11
12
12
test ( 'Comments' , function ( t ) {
13
13
t . deepEqual (
14
- toJSON ( [ '% This is a completely commented line.' , 'unicorn' ] . join ( '\n' ) ) ,
14
+ toJson ( [ '% This is a completely commented line.' , 'unicorn' ] . join ( '\n' ) ) ,
15
15
[ 'unicorn' ] ,
16
16
'should strip line comments'
17
17
)
18
18
19
19
t . deepEqual (
20
- toJSON ( 'unicorn % This is a partially commented line.' ) ,
20
+ toJson ( 'unicorn % This is a partially commented line.' ) ,
21
21
[ 'unicorn' ] ,
22
22
'should strip partial line comments'
23
23
)
24
24
25
25
t . deepEqual (
26
- toJSON ( 'unicorn % This is a partially commented line.' , {
26
+ toJson ( 'unicorn % This is a partially commented line.' , {
27
27
comment : false
28
28
} ) ,
29
29
[ 'unicorn % This is a partially commented line.' ] ,
30
30
'should honour `comment: false`'
31
31
)
32
32
33
33
t . deepEqual (
34
- toJSON ( [ '# This is a completely commented line.' , 'unicorn' ] . join ( '\n' ) , {
34
+ toJson ( [ '# This is a completely commented line.' , 'unicorn' ] . join ( '\n' ) , {
35
35
comment : '#'
36
36
} ) ,
37
37
[ 'unicorn' ] ,
38
38
'should strip line comments based on a given token'
39
39
)
40
40
41
41
t . deepEqual (
42
- toJSON ( 'unicorn # This is a partially commented line.' , {
42
+ toJson ( 'unicorn # This is a partially commented line.' , {
43
43
comment : '#'
44
44
} ) ,
45
45
[ 'unicorn' ] ,
@@ -51,7 +51,7 @@ test('Comments', function(t) {
51
51
52
52
test ( 'White space' , function ( t ) {
53
53
t . deepEqual (
54
- toJSON ( ' \tunicorn \t' ) ,
54
+ toJson ( ' \tunicorn \t' ) ,
55
55
[ 'unicorn' ] ,
56
56
'should trim prefixed and suffixed white space'
57
57
)
@@ -61,7 +61,7 @@ test('White space', function(t) {
61
61
62
62
test ( 'Blank lines' , function ( t ) {
63
63
t . deepEqual (
64
- toJSON ( '\n \t \ndoge\n\nunicorn\r\n' ) ,
64
+ toJson ( '\n \t \ndoge\n\nunicorn\r\n' ) ,
65
65
[ 'doge' , 'unicorn' ] ,
66
66
'should remove empty / blank lines'
67
67
)
@@ -70,22 +70,22 @@ test('Blank lines', function(t) {
70
70
} )
71
71
72
72
test ( 'EOF' , function ( t ) {
73
- t . deepEqual ( toJSON ( 'unicorn' ) , [ 'unicorn' ] , 'No EOL' )
74
- t . deepEqual ( toJSON ( 'unicorn\n' ) , [ 'unicorn' ] , 'LF' )
75
- t . deepEqual ( toJSON ( 'unicorn\r\n' ) , [ 'unicorn' ] , 'CR+LF' )
73
+ t . deepEqual ( toJson ( 'unicorn' ) , [ 'unicorn' ] , 'No EOL' )
74
+ t . deepEqual ( toJson ( 'unicorn\n' ) , [ 'unicorn' ] , 'LF' )
75
+ t . deepEqual ( toJson ( 'unicorn\r\n' ) , [ 'unicorn' ] , 'CR+LF' )
76
76
77
77
t . end ( )
78
78
} )
79
79
80
80
test ( 'Property-value pairs' , function ( t ) {
81
81
t . deepEqual (
82
- toJSON ( 'unicorn: magic creature' ) ,
82
+ toJson ( 'unicorn: magic creature' ) ,
83
83
{ unicorn : 'magic creature' } ,
84
84
'should support pair delimiters'
85
85
)
86
86
87
87
t . deepEqual (
88
- toJSON (
88
+ toJson (
89
89
[
90
90
'unicorn : magic creature' ,
91
91
'\trainbow:double\t' ,
@@ -101,7 +101,7 @@ test('Property-value pairs', function(t) {
101
101
)
102
102
103
103
t . deepEqual (
104
- toJSON ( 'unicorn\tmagic creature' , { delimiter : '\t' } ) ,
104
+ toJson ( 'unicorn\tmagic creature' , { delimiter : '\t' } ) ,
105
105
{ unicorn : 'magic creature' } ,
106
106
'given delimiters'
107
107
)
@@ -110,10 +110,10 @@ test('Property-value pairs', function(t) {
110
110
} )
111
111
112
112
test ( 'Values' , function ( t ) {
113
- t . deepEqual ( toJSON ( 'unicorn' ) , [ 'unicorn' ] , 'one value' )
113
+ t . deepEqual ( toJson ( 'unicorn' ) , [ 'unicorn' ] , 'one value' )
114
114
115
115
t . deepEqual (
116
- toJSON ( 'unicorn \n doge\n\trainbow' ) ,
116
+ toJson ( 'unicorn \n doge\n\trainbow' ) ,
117
117
[ 'doge' , 'rainbow' , 'unicorn' ] ,
118
118
'multiple values'
119
119
)
@@ -124,7 +124,7 @@ test('Values', function(t) {
124
124
test ( 'Mixed values' , function ( t ) {
125
125
t . throws (
126
126
function ( ) {
127
- toJSON ( 'unicorn\nrainbow: double' )
127
+ toJson ( 'unicorn\nrainbow: double' )
128
128
} ,
129
129
/ ^ E r r o r : E r r o r a t ` r a i n b o w , d o u b l e ` / ,
130
130
'should throw when both property-value pairs and values are provided'
@@ -136,14 +136,14 @@ test('Mixed values', function(t) {
136
136
test ( 'Invalid lists' , function ( t ) {
137
137
t . throws (
138
138
function ( ) {
139
- toJSON ( 'unicorn\nrainbow\nunicorn' )
139
+ toJson ( 'unicorn\nrainbow\nunicorn' )
140
140
} ,
141
141
/ ^ E r r o r : E r r o r a t ` u n i c o r n ` : D u p l i c a t e d a t a f o u n d / ,
142
142
'should throw when duplicate values exist'
143
143
)
144
144
145
145
t . deepEqual (
146
- toJSON ( 'unicorn\nrainbow\nunicorn' , { forgiving : true } ) ,
146
+ toJson ( 'unicorn\nrainbow\nunicorn' , { forgiving : true } ) ,
147
147
[ 'rainbow' , 'unicorn' , 'unicorn' ] ,
148
148
'should honour forgiving'
149
149
)
@@ -152,7 +152,7 @@ test('Invalid lists', function(t) {
152
152
var stop = cept ( console , 'log' , hoist )
153
153
var params
154
154
155
- toJSON ( 'unicorn\nrainbow\nunicorn' , { forgiving : true } )
155
+ toJson ( 'unicorn\nrainbow\nunicorn' , { forgiving : true } )
156
156
157
157
stop ( )
158
158
@@ -168,7 +168,7 @@ test('Invalid lists', function(t) {
168
168
var stop = cept ( console , 'log' , hoist )
169
169
var params
170
170
171
- toJSON ( 'unicorn\nrainbow\nunicorn' , { forgiving : true , log : false } )
171
+ toJson ( 'unicorn\nrainbow\nunicorn' , { forgiving : true , log : false } )
172
172
173
173
stop ( )
174
174
@@ -186,14 +186,14 @@ test('Invalid lists', function(t) {
186
186
test ( 'Invalid objects' , function ( t ) {
187
187
t . throws (
188
188
function ( ) {
189
- toJSON ( 'doge: so scare\nunicorn: magic\ndoge: double' )
189
+ toJson ( 'doge: so scare\nunicorn: magic\ndoge: double' )
190
190
} ,
191
191
/ ^ E r r o r : E r r o r a t ` d o g e , d o u b l e ` : D u p l i c a t e d a t a f o u n d / ,
192
192
'should throw when duplicate values exist'
193
193
)
194
194
195
195
t . deepEqual (
196
- toJSON ( 'doge: so scare\nunicorn: magic creature\ndoge: so scare\n' , {
196
+ toJson ( 'doge: so scare\nunicorn: magic creature\ndoge: so scare\n' , {
197
197
forgiving : true
198
198
} ) ,
199
199
{ doge : 'so scare' , unicorn : 'magic creature' } ,
@@ -204,7 +204,7 @@ test('Invalid objects', function(t) {
204
204
var stop = cept ( console , 'log' , hoist )
205
205
var params
206
206
207
- toJSON ( 'doge: so scare\nunicorn: magic creature\ndoge: so scare\n' , {
207
+ toJson ( 'doge: so scare\nunicorn: magic creature\ndoge: so scare\n' , {
208
208
forgiving : true
209
209
} )
210
210
@@ -222,7 +222,7 @@ test('Invalid objects', function(t) {
222
222
var stop = cept ( console , 'log' , hoist )
223
223
var params
224
224
225
- toJSON ( 'doge: so scare\nunicorn: magic creature\ndoge: so scare\n' , {
225
+ toJson ( 'doge: so scare\nunicorn: magic creature\ndoge: so scare\n' , {
226
226
forgiving : true ,
227
227
log : false
228
228
} )
@@ -238,15 +238,15 @@ test('Invalid objects', function(t) {
238
238
} )
239
239
240
240
t . deepEqual (
241
- toJSON ( 'doge: so scare\nunicorn: magic creature\ndoge: so scare\n' , {
241
+ toJson ( 'doge: so scare\nunicorn: magic creature\ndoge: so scare\n' , {
242
242
forgiving : 'fix'
243
243
} ) ,
244
244
{ doge : 'so scare' , unicorn : 'magic creature' } ,
245
245
"should honour `forgiving: 'fix'`"
246
246
)
247
247
248
248
t . deepEqual (
249
- toJSON ( 'doge: so scare\nunicorn: magic creature\ndoge: rainbows\n' , {
249
+ toJson ( 'doge: so scare\nunicorn: magic creature\ndoge: rainbows\n' , {
250
250
forgiving : 'fix'
251
251
} ) ,
252
252
{ doge : 'rainbows' , unicorn : 'magic creature' } ,
@@ -259,7 +259,7 @@ test('Invalid objects', function(t) {
259
259
var stop = cept ( console , 'log' , hoist )
260
260
var params
261
261
262
- toJSON ( 'doge: so scare\nunicorn: magic creature\ndoge: so scare\n' , {
262
+ toJson ( 'doge: so scare\nunicorn: magic creature\ndoge: so scare\n' , {
263
263
forgiving : true
264
264
} )
265
265
0 commit comments