@@ -112,16 +112,16 @@ describe('data access', () => {
112
112
[ 'foo23' , 'bar23' ]
113
113
]
114
114
115
- describe ( 'get value ' , ( ) => {
115
+ describe ( 'getProperty ' , ( ) => {
116
116
it . each ( samplePairs ) ( 'should get property "%s"' , ( key , expected ) => {
117
- const result = properties . get ( sample , key )
117
+ const result = properties . getProperty ( sample , key )
118
118
expect ( result ) . toBe ( expected )
119
119
} )
120
120
121
121
it . each ( [ [ 'foo6' ] , [ 'foo7' ] ] ) (
122
122
'should not get commented property "%s"' ,
123
123
key => {
124
- const result = properties . get ( sample , key )
124
+ const result = properties . getProperty ( sample , key )
125
125
expect ( result ) . toBeUndefined ( )
126
126
}
127
127
)
@@ -131,7 +131,7 @@ describe('data access', () => {
131
131
lines : [ 'key1=foo1' , 'key2=foo2' , 'key1=foo3' ]
132
132
}
133
133
134
- const result = properties . get ( config , 'key1' )
134
+ const result = properties . getProperty ( config , 'key1' )
135
135
expect ( result ) . toBe ( 'foo3' )
136
136
} )
137
137
@@ -140,7 +140,7 @@ describe('data access', () => {
140
140
lines : [ 'foo\\u23a=bar' ]
141
141
}
142
142
143
- expect ( ( ) => properties . get ( config , 'foo' ) ) . toThrowError ( )
143
+ expect ( ( ) => properties . getProperty ( config , 'foo' ) ) . toThrowError ( )
144
144
} )
145
145
146
146
it . each ( [ [ 'foo=bar\\u23a' ] , [ 'foo=bar\\u23ax5' ] ] ) (
@@ -150,7 +150,7 @@ describe('data access', () => {
150
150
lines : [ line ]
151
151
}
152
152
153
- expect ( ( ) => properties . get ( config , 'foo' ) ) . toThrowError ( )
153
+ expect ( ( ) => properties . getProperty ( config , 'foo' ) ) . toThrowError ( )
154
154
}
155
155
)
156
156
@@ -165,12 +165,12 @@ describe('data access', () => {
165
165
lines : [ line ]
166
166
}
167
167
168
- const result = properties . get ( config , 'foo' )
168
+ const result = properties . getProperty ( config , 'foo' )
169
169
expect ( result ) . toBe ( value )
170
170
} )
171
171
} )
172
172
173
- describe ( 'set value ' , ( ) => {
173
+ describe ( 'setProperty ' , ( ) => {
174
174
it . each ( [
175
175
[ 'foo1' , 'bar' , 'foo1=bar' ] ,
176
176
[ 'foo8:' , 'bar8' , 'foo8\\:=bar8' ] ,
@@ -187,7 +187,7 @@ describe('data access', () => {
187
187
[ 'foo22' , '\\' , 'foo22=\\\\' ]
188
188
] ) ( 'should format key pair for "%s"' , ( key , value , expected ) => {
189
189
const config = properties . empty ( )
190
- properties . set ( config , key , value )
190
+ properties . setProperty ( config , key , value )
191
191
expect ( config . lines ) . toEqual ( [ expected ] )
192
192
} )
193
193
@@ -202,7 +202,7 @@ describe('data access', () => {
202
202
const config : properties . Properties = {
203
203
lines : [ line ]
204
204
}
205
- properties . set ( config , 'a' , 'b' )
205
+ properties . setProperty ( config , 'a' , 'b' )
206
206
expect ( config . lines ) . toEqual ( [ line , expected ] )
207
207
} )
208
208
@@ -232,7 +232,7 @@ describe('data access', () => {
232
232
'foo22' ,
233
233
'foo23'
234
234
]
235
- keys . forEach ( key => properties . set ( sample , key , 'x' ) )
235
+ keys . forEach ( key => properties . setProperty ( sample , key , 'x' ) )
236
236
237
237
expect ( sample . lines ) . toEqual ( [
238
238
'foo0=x' ,
@@ -268,7 +268,7 @@ describe('data access', () => {
268
268
lines : [ 'key1=foo1' , 'key2=foo2' ]
269
269
}
270
270
271
- properties . set ( config , 'key1' , 'test' , { separator : ': ' } )
271
+ properties . setProperty ( config , 'key1' , 'test' , { separator : ': ' } )
272
272
expect ( config . lines ) . toEqual ( [ 'key1: test' , 'key2=foo2' ] )
273
273
} )
274
274
@@ -277,25 +277,25 @@ describe('data access', () => {
277
277
lines : [ 'key1=foo1' , 'key2=foo2' , 'key1=foo3' ]
278
278
}
279
279
280
- properties . set ( config , 'key1' , 'test' )
280
+ properties . setProperty ( config , 'key1' , 'test' )
281
281
expect ( config . lines ) . toEqual ( [ 'key1=test' , 'key2=foo2' ] )
282
282
} )
283
- } )
284
283
285
- describe ( 'remove value' , ( ) => {
286
284
it ( 'should remove existing key with set undefined' , ( ) => {
287
285
const config : properties . Properties = {
288
286
lines : [ 'foo=bar' ]
289
287
}
290
- properties . set ( config , 'foo' , undefined )
288
+ properties . setProperty ( config , 'foo' , undefined )
291
289
expect ( config . lines ) . toEqual ( [ ] )
292
290
} )
291
+ } )
293
292
293
+ describe ( 'removeProperty' , ( ) => {
294
294
it ( 'should remove existing key with remove' , ( ) => {
295
295
const config : properties . Properties = {
296
296
lines : [ 'foo=bar' ]
297
297
}
298
- properties . remove ( config , 'foo' )
298
+ properties . removeProperty ( config , 'foo' )
299
299
expect ( config . lines ) . toEqual ( [ ] )
300
300
} )
301
301
@@ -304,14 +304,14 @@ describe('data access', () => {
304
304
lines : [ 'key1=foo1' , 'key2=foo2' , 'key1=foo3' ]
305
305
}
306
306
307
- properties . remove ( config , 'key1' )
307
+ properties . removeProperty ( config , 'key1' )
308
308
expect ( config . lines ) . toEqual ( [ 'key2=foo2' ] )
309
309
} )
310
310
} )
311
311
312
- describe ( 'list ' , ( ) => {
312
+ describe ( 'listProperties ' , ( ) => {
313
313
it ( 'should list all key-value pairs' , ( ) => {
314
- const result = [ ...properties . list ( sample ) ]
314
+ const result = [ ...properties . listProperties ( sample ) ]
315
315
const resultAsArrays = result . map ( ( { key, value} ) => [ key , value ] )
316
316
317
317
expect ( resultAsArrays ) . toEqual ( samplePairs )
@@ -322,7 +322,7 @@ describe('data access', () => {
322
322
lines : [ 'foo=bar1' , 'foo=bar2' ]
323
323
}
324
324
325
- const result = [ ...properties . list ( config ) ]
325
+ const result = [ ...properties . listProperties ( config ) ]
326
326
expect ( result ) . toEqual ( [
327
327
{ key : 'foo' , value : 'bar1' } ,
328
328
{ key : 'foo' , value : 'bar2' }
@@ -368,46 +368,46 @@ describe('data access', () => {
368
368
[ 'c' , 'd' ]
369
369
] )
370
370
} )
371
+ } )
372
+
373
+ it ( 'should parse test file' , async ( ) => {
374
+ const contents = await fs . readFile (
375
+ require . resolve ( '../fixtures/test-all.properties' ) ,
376
+ 'utf-8'
377
+ )
371
378
372
- it ( 'should parse test file' , async ( ) => {
373
- const contents = await fs . readFile (
374
- require . resolve ( '../fixtures/test-all.properties' ) ,
375
- 'utf-8'
376
- )
377
-
378
- // Parse
379
- const result = properties . toObject ( properties . parse ( contents ) )
380
-
381
- // Verify
382
- expect ( result ) . toEqual ( {
383
- '' : 'So does this line.' ,
384
- category : 'file format' ,
385
- duplicateKey : 'second' ,
386
- empty : '' ,
387
- encodedHelloInJapanese : 'こんにちは' ,
388
- evenKey : 'This is on one line\\' ,
389
- 'evenLikeThis\\' : '' ,
390
- hello : 'hello' ,
391
- helloInJapanese : 'こんにちは' ,
392
- こんにちは : 'hello' ,
393
- keyWithBackslashes : 'This has random backslashes' ,
394
- 'keyWithDelimiters:= ' :
395
- 'This is the value for the key "keyWithDelimiters:= "' ,
396
- 'keyWitheven\\' : 'this colon is not escaped' ,
397
- language : 'English' ,
398
- multiline : 'This line continues on 3 lines' ,
399
- multilineKey : 'this is a multiline key' ,
400
- noWhiteSpace :
401
- 'The key will be "noWhiteSpace" without any whitespace. ' ,
402
- oddKey : 'This is line one and\\# This is line two' ,
403
- orLikeThis : '' ,
404
- path : 'c:\\wiki\\templates' ,
405
- topic : '.properties file' ,
406
- valueWithEscapes :
407
- 'This is a newline\n, a carriage return\r, a tab\t and a formfeed\f.' ,
408
- website : 'https://en.wikipedia.org/' ,
409
- welcome : 'Welcome to Wikipedia! '
410
- } )
379
+ // Parse
380
+ const result = properties . toObject ( properties . parse ( contents ) )
381
+
382
+ // Verify
383
+ expect ( result ) . toEqual ( {
384
+ '' : 'So does this line.' ,
385
+ category : 'file format' ,
386
+ duplicateKey : 'second' ,
387
+ empty : '' ,
388
+ encodedHelloInJapanese : 'こんにちは' ,
389
+ evenKey : 'This is on one line\\' ,
390
+ 'evenLikeThis\\' : '' ,
391
+ hello : 'hello' ,
392
+ helloInJapanese : 'こんにちは' ,
393
+ '\u3053\u3093\u306B\u3061\u306F' : 'hello' ,
394
+ keyWithBackslashes : 'This has random backslashes' ,
395
+ 'keyWithDelimiters:= ' :
396
+ 'This is the value for the key "keyWithDelimiters:= "' ,
397
+ 'keyWitheven\\' : 'this colon is not escaped' ,
398
+ language : 'English' ,
399
+ multiline : 'This line continues on 3 lines' ,
400
+ multilineKey : 'this is a multiline key' ,
401
+ noWhiteSpace :
402
+ 'The key will be "noWhiteSpace" without any whitespace. ' ,
403
+ oddKey : 'This is line one and\\# This is line two' ,
404
+ orLikeThis : '' ,
405
+ path : 'c:\\wiki\\templates' ,
406
+ topic : '.properties file' ,
407
+ valueWithEscapes :
408
+ 'This is a newline\n, a carriage return\r, a tab\t and a formfeed\f.' ,
409
+ website : 'https://en.wikipedia.org/' ,
410
+ welcome : 'Welcome to Wikipedia! '
411
411
} )
412
412
} )
413
413
} )
0 commit comments