1
1
import * as fs from 'node:fs/promises'
2
+
2
3
import properties from '.'
3
4
4
5
describe ( 'parse' , ( ) => {
5
6
it ( 'should parse all lines' , ( ) => {
6
7
// Data
7
- const sample = 'registry=https://abcd\n#foo bar\r\n@scope:test=avx\rextra\r\n'
8
+ const sample =
9
+ 'registry=https://abcd\n#foo bar\r\n@scope:test=avx\rextra\r\n'
8
10
9
11
// Test
10
12
const result = properties . parse ( sample )
@@ -108,21 +110,17 @@ describe('data access', () => {
108
110
expect ( result ) . toBe ( expected )
109
111
} )
110
112
111
- it . each ( [
112
- [ 'foo6' ] ,
113
- [ 'foo7' ]
114
- ] ) ( 'should not get commented property "%s"' , ( key ) => {
115
- const result = properties . get ( sample , key )
116
- expect ( result ) . toBeUndefined ( )
117
- } )
113
+ it . each ( [ [ 'foo6' ] , [ 'foo7' ] ] ) (
114
+ 'should not get commented property "%s"' ,
115
+ key => {
116
+ const result = properties . get ( sample , key )
117
+ expect ( result ) . toBeUndefined ( )
118
+ }
119
+ )
118
120
119
121
it ( 'should return last value of duplicate key' , ( ) => {
120
122
const config : properties . Properties = {
121
- lines : [
122
- 'key1=foo1' ,
123
- 'key2=foo2' ,
124
- 'key1=foo3'
125
- ]
123
+ lines : [ 'key1=foo1' , 'key2=foo2' , 'key1=foo3' ]
126
124
}
127
125
128
126
const result = properties . get ( config , 'key1' )
@@ -137,16 +135,16 @@ describe('data access', () => {
137
135
expect ( ( ) => properties . get ( config , 'foo' ) ) . toThrowError ( )
138
136
} )
139
137
140
- it . each ( [
141
- [ 'foo=bar\\u23a' ] ,
142
- [ 'foo=bar\\u23ax5' ]
143
- ] ) ( 'should throw on invalid unicode sequence in value %s' , ( line ) => {
144
- const config : properties . Properties = {
145
- lines : [ line ]
146
- }
138
+ it . each ( [ [ 'foo=bar\\u23a' ] , [ 'foo=bar\\u23ax5' ] ] ) (
139
+ 'should throw on invalid unicode sequence in value %s' ,
140
+ line => {
141
+ const config : properties . Properties = {
142
+ lines : [ line ]
143
+ }
147
144
148
- expect ( ( ) => properties . get ( config , 'foo' ) ) . toThrowError ( )
149
- } )
145
+ expect ( ( ) => properties . get ( config , 'foo' ) ) . toThrowError ( )
146
+ }
147
+ )
150
148
151
149
it . each ( [
152
150
[ 'foo=bar' , 'bar' ] ,
@@ -259,33 +257,20 @@ describe('data access', () => {
259
257
260
258
it ( 'should use custom separator' , ( ) => {
261
259
const config : properties . Properties = {
262
- lines : [
263
- 'key1=foo1' ,
264
- 'key2=foo2'
265
- ]
260
+ lines : [ 'key1=foo1' , 'key2=foo2' ]
266
261
}
267
262
268
263
properties . set ( config , 'key1' , 'test' , { separator : ': ' } )
269
- expect ( config . lines ) . toEqual ( [
270
- 'key1: test' ,
271
- 'key2=foo2'
272
- ] )
264
+ expect ( config . lines ) . toEqual ( [ 'key1: test' , 'key2=foo2' ] )
273
265
} )
274
266
275
267
it ( 'should remove duplicate keys on set' , ( ) => {
276
268
const config : properties . Properties = {
277
- lines : [
278
- 'key1=foo1' ,
279
- 'key2=foo2' ,
280
- 'key1=foo3'
281
- ]
269
+ lines : [ 'key1=foo1' , 'key2=foo2' , 'key1=foo3' ]
282
270
}
283
271
284
272
properties . set ( config , 'key1' , 'test' )
285
- expect ( config . lines ) . toEqual ( [
286
- 'key1=test' ,
287
- 'key2=foo2'
288
- ] )
273
+ expect ( config . lines ) . toEqual ( [ 'key1=test' , 'key2=foo2' ] )
289
274
} )
290
275
} )
291
276
@@ -308,11 +293,7 @@ describe('data access', () => {
308
293
309
294
it ( 'should remove all duplicate keys with remove' , ( ) => {
310
295
const config : properties . Properties = {
311
- lines : [
312
- 'key1=foo1' ,
313
- 'key2=foo2' ,
314
- 'key1=foo3'
315
- ]
296
+ lines : [ 'key1=foo1' , 'key2=foo2' , 'key1=foo3' ]
316
297
}
317
298
318
299
properties . remove ( config , 'key1' )
@@ -381,7 +362,10 @@ describe('data access', () => {
381
362
} )
382
363
383
364
it ( 'should parse test file' , async ( ) => {
384
- const contents = await fs . readFile ( require . resolve ( '../fixtures/test-all.properties' ) , 'utf-8' )
365
+ const contents = await fs . readFile (
366
+ require . resolve ( '../fixtures/test-all.properties' ) ,
367
+ 'utf-8'
368
+ )
385
369
386
370
// Parse
387
371
const result = properties . toObject ( properties . parse ( contents ) )
@@ -397,19 +381,22 @@ describe('data access', () => {
397
381
'evenLikeThis\\' : '' ,
398
382
hello : 'hello' ,
399
383
helloInJapanese : 'こんにちは' ,
400
- ' こんにちは' : 'hello' ,
384
+ こんにちは : 'hello' ,
401
385
keyWithBackslashes : 'This has random backslashes' ,
402
- 'keyWithDelimiters:= ' : 'This is the value for the key "keyWithDelimiters:= "' ,
386
+ 'keyWithDelimiters:= ' :
387
+ 'This is the value for the key "keyWithDelimiters:= "' ,
403
388
'keyWitheven\\' : 'this colon is not escaped' ,
404
389
language : 'English' ,
405
390
multiline : 'This line continues on 3 lines' ,
406
391
multilineKey : 'this is a multiline key' ,
407
- noWhiteSpace : 'The key will be "noWhiteSpace" without any whitespace. ' ,
392
+ noWhiteSpace :
393
+ 'The key will be "noWhiteSpace" without any whitespace. ' ,
408
394
oddKey : 'This is line one and\\# This is line two' ,
409
395
orLikeThis : '' ,
410
396
path : 'c:\\wiki\\templates' ,
411
397
topic : '.properties file' ,
412
- valueWithEscapes : 'This is a newline\n, a carriage return\r, a tab\t and a formfeed\f.' ,
398
+ valueWithEscapes :
399
+ 'This is a newline\n, a carriage return\r, a tab\t and a formfeed\f.' ,
413
400
website : 'https://en.wikipedia.org/' ,
414
401
welcome : 'Welcome to Wikipedia! '
415
402
} )
0 commit comments