12
12
// License for the specific language governing permissions and limitations
13
13
// under the License.
14
14
15
- package ini_test
15
+ package ini
16
16
17
17
import (
18
18
"bytes"
@@ -22,12 +22,10 @@ import (
22
22
23
23
"github.com/stretchr/testify/assert"
24
24
"github.com/stretchr/testify/require"
25
-
26
- "gopkg.in/ini.v1"
27
25
)
28
26
29
27
func TestEmpty (t * testing.T ) {
30
- f := ini . Empty ()
28
+ f := Empty ()
31
29
require .NotNil (t , f )
32
30
33
31
// Should only have the default section
@@ -38,23 +36,23 @@ func TestEmpty(t *testing.T) {
38
36
}
39
37
40
38
func TestFile_NewSection (t * testing.T ) {
41
- f := ini . Empty ()
39
+ f := Empty ()
42
40
require .NotNil (t , f )
43
41
44
42
sec , err := f .NewSection ("author" )
45
43
require .NoError (t , err )
46
44
require .NotNil (t , sec )
47
45
assert .Equal (t , "author" , sec .Name ())
48
46
49
- assert .Equal (t , []string {ini . DefaultSection , "author" }, f .SectionStrings ())
47
+ assert .Equal (t , []string {DefaultSection , "author" }, f .SectionStrings ())
50
48
51
49
t .Run ("with duplicated name" , func (t * testing.T ) {
52
50
sec , err := f .NewSection ("author" )
53
51
require .NoError (t , err )
54
52
require .NotNil (t , sec )
55
53
56
54
// Does nothing if section already exists
57
- assert .Equal (t , []string {ini . DefaultSection , "author" }, f .SectionStrings ())
55
+ assert .Equal (t , []string {DefaultSection , "author" }, f .SectionStrings ())
58
56
})
59
57
60
58
t .Run ("with empty string" , func (t * testing.T ) {
@@ -65,7 +63,7 @@ func TestFile_NewSection(t *testing.T) {
65
63
66
64
func TestFile_NonUniqueSection (t * testing.T ) {
67
65
t .Run ("read and write non-unique sections" , func (t * testing.T ) {
68
- f , err := ini . LoadSources (ini. LoadOptions {
66
+ f , err := LoadSources (LoadOptions {
69
67
AllowNonUniqueSections : true ,
70
68
}, []byte (`[Interface]
71
69
Address = 192.168.2.1
@@ -114,7 +112,7 @@ AllowedIPs = 192.168.2.4/32
114
112
})
115
113
116
114
t .Run ("delete non-unique section" , func (t * testing.T ) {
117
- f , err := ini . LoadSources (ini. LoadOptions {
115
+ f , err := LoadSources (LoadOptions {
118
116
AllowNonUniqueSections : true ,
119
117
}, []byte (`[Interface]
120
118
Address = 192.168.2.1
@@ -161,20 +159,20 @@ AllowedIPs = 192.168.2.4/32
161
159
})
162
160
163
161
t .Run ("delete all sections" , func (t * testing.T ) {
164
- f := ini . Empty (ini. LoadOptions {
162
+ f := Empty (LoadOptions {
165
163
AllowNonUniqueSections : true ,
166
164
})
167
165
require .NotNil (t , f )
168
166
169
167
_ = f .NewSections ("Interface" , "Peer" , "Peer" )
170
- assert .Equal (t , []string {ini . DefaultSection , "Interface" , "Peer" , "Peer" }, f .SectionStrings ())
168
+ assert .Equal (t , []string {DefaultSection , "Interface" , "Peer" , "Peer" }, f .SectionStrings ())
171
169
f .DeleteSection ("Peer" )
172
- assert .Equal (t , []string {ini . DefaultSection , "Interface" }, f .SectionStrings ())
170
+ assert .Equal (t , []string {DefaultSection , "Interface" }, f .SectionStrings ())
173
171
})
174
172
}
175
173
176
174
func TestFile_NewRawSection (t * testing.T ) {
177
- f := ini . Empty ()
175
+ f := Empty ()
178
176
require .NotNil (t , f )
179
177
180
178
sec , err := f .NewRawSection ("comments" , `1111111111111111111000000000000000001110000
@@ -183,15 +181,15 @@ func TestFile_NewRawSection(t *testing.T) {
183
181
require .NotNil (t , sec )
184
182
assert .Equal (t , "comments" , sec .Name ())
185
183
186
- assert .Equal (t , []string {ini . DefaultSection , "comments" }, f .SectionStrings ())
184
+ assert .Equal (t , []string {DefaultSection , "comments" }, f .SectionStrings ())
187
185
assert .Equal (t , `1111111111111111111000000000000000001110000
188
186
111111111111111111100000000000111000000000` , f .Section ("comments" ).Body ())
189
187
190
188
t .Run ("with duplicated name" , func (t * testing.T ) {
191
189
sec , err := f .NewRawSection ("comments" , `1111111111111111111000000000000000001110000` )
192
190
require .NoError (t , err )
193
191
require .NotNil (t , sec )
194
- assert .Equal (t , []string {ini . DefaultSection , "comments" }, f .SectionStrings ())
192
+ assert .Equal (t , []string {DefaultSection , "comments" }, f .SectionStrings ())
195
193
196
194
// Overwrite previous existed section
197
195
assert .Equal (t , `1111111111111111111000000000000000001110000` , f .Section ("comments" ).Body ())
@@ -204,17 +202,17 @@ func TestFile_NewRawSection(t *testing.T) {
204
202
}
205
203
206
204
func TestFile_NewSections (t * testing.T ) {
207
- f := ini . Empty ()
205
+ f := Empty ()
208
206
require .NotNil (t , f )
209
207
210
208
assert .NoError (t , f .NewSections ("package" , "author" ))
211
- assert .Equal (t , []string {ini . DefaultSection , "package" , "author" }, f .SectionStrings ())
209
+ assert .Equal (t , []string {DefaultSection , "package" , "author" }, f .SectionStrings ())
212
210
213
211
t .Run ("with duplicated name" , func (t * testing.T ) {
214
212
assert .NoError (t , f .NewSections ("author" , "features" ))
215
213
216
214
// Ignore section already exists
217
- assert .Equal (t , []string {ini . DefaultSection , "package" , "author" , "features" }, f .SectionStrings ())
215
+ assert .Equal (t , []string {DefaultSection , "package" , "author" , "features" }, f .SectionStrings ())
218
216
})
219
217
220
218
t .Run ("with empty string" , func (t * testing.T ) {
@@ -223,7 +221,7 @@ func TestFile_NewSections(t *testing.T) {
223
221
}
224
222
225
223
func TestFile_GetSection (t * testing.T ) {
226
- f , err := ini . Load (fullConf )
224
+ f , err := Load (fullConf )
227
225
require .NoError (t , err )
228
226
require .NotNil (t , f )
229
227
@@ -240,7 +238,7 @@ func TestFile_GetSection(t *testing.T) {
240
238
241
239
func TestFile_Section (t * testing.T ) {
242
240
t .Run ("get a section" , func (t * testing.T ) {
243
- f , err := ini . Load (fullConf )
241
+ f , err := Load (fullConf )
244
242
require .NoError (t , err )
245
243
require .NotNil (t , f )
246
244
@@ -256,7 +254,7 @@ func TestFile_Section(t *testing.T) {
256
254
})
257
255
258
256
t .Run ("get default section in lower case with insensitive load" , func (t * testing.T ) {
259
- f , err := ini . InsensitiveLoad ([]byte (`
257
+ f , err := InsensitiveLoad ([]byte (`
260
258
[default]
261
259
NAME = ini
262
260
VERSION = v1` ))
@@ -269,20 +267,20 @@ VERSION = v1`))
269
267
}
270
268
271
269
func TestFile_Sections (t * testing.T ) {
272
- f , err := ini . Load (fullConf )
270
+ f , err := Load (fullConf )
273
271
require .NoError (t , err )
274
272
require .NotNil (t , f )
275
273
276
274
secs := f .Sections ()
277
- names := []string {ini . DefaultSection , "author" , "package" , "package.sub" , "features" , "types" , "array" , "note" , "comments" , "string escapes" , "advance" }
275
+ names := []string {DefaultSection , "author" , "package" , "package.sub" , "features" , "types" , "array" , "note" , "comments" , "string escapes" , "advance" }
278
276
assert .Len (t , secs , len (names ))
279
277
for i , name := range names {
280
278
assert .Equal (t , name , secs [i ].Name ())
281
279
}
282
280
}
283
281
284
282
func TestFile_ChildSections (t * testing.T ) {
285
- f , err := ini . Load ([]byte (`
283
+ f , err := Load ([]byte (`
286
284
[node]
287
285
[node.biz1]
288
286
[node.biz2]
@@ -301,16 +299,16 @@ func TestFile_ChildSections(t *testing.T) {
301
299
}
302
300
303
301
func TestFile_SectionStrings (t * testing.T ) {
304
- f , err := ini . Load (fullConf )
302
+ f , err := Load (fullConf )
305
303
require .NoError (t , err )
306
304
require .NotNil (t , f )
307
305
308
- assert .Equal (t , []string {ini . DefaultSection , "author" , "package" , "package.sub" , "features" , "types" , "array" , "note" , "comments" , "string escapes" , "advance" }, f .SectionStrings ())
306
+ assert .Equal (t , []string {DefaultSection , "author" , "package" , "package.sub" , "features" , "types" , "array" , "note" , "comments" , "string escapes" , "advance" }, f .SectionStrings ())
309
307
}
310
308
311
309
func TestFile_DeleteSection (t * testing.T ) {
312
310
t .Run ("delete a section" , func (t * testing.T ) {
313
- f := ini . Empty ()
311
+ f := Empty ()
314
312
require .NotNil (t , f )
315
313
316
314
_ = f .NewSections ("author" , "package" , "features" )
@@ -320,7 +318,7 @@ func TestFile_DeleteSection(t *testing.T) {
320
318
})
321
319
322
320
t .Run ("delete default section" , func (t * testing.T ) {
323
- f := ini . Empty ()
321
+ f := Empty ()
324
322
require .NotNil (t , f )
325
323
326
324
f .Section ("" ).Key ("foo" ).SetValue ("bar" )
@@ -339,7 +337,7 @@ key1 = value1
339
337
})
340
338
341
339
t .Run ("delete a section with InsensitiveSections" , func (t * testing.T ) {
342
- f := ini . Empty (ini. LoadOptions {InsensitiveSections : true })
340
+ f := Empty (LoadOptions {InsensitiveSections : true })
343
341
require .NotNil (t , f )
344
342
345
343
_ = f .NewSections ("author" , "package" , "features" )
@@ -350,7 +348,7 @@ key1 = value1
350
348
}
351
349
352
350
func TestFile_Append (t * testing.T ) {
353
- f := ini . Empty ()
351
+ f := Empty ()
354
352
require .NotNil (t , f )
355
353
356
354
assert .NoError (t , f .Append (minimalConf , []byte (`
@@ -369,7 +367,7 @@ func TestFile_WriteTo(t *testing.T) {
369
367
}
370
368
371
369
t .Run ("write content to somewhere" , func (t * testing.T ) {
372
- f , err := ini . Load (fullConf )
370
+ f , err := Load (fullConf )
373
371
require .NoError (t , err )
374
372
require .NotNil (t , f )
375
373
@@ -394,7 +392,7 @@ func TestFile_WriteTo(t *testing.T) {
394
392
})
395
393
396
394
t .Run ("support multiline comments" , func (t * testing.T ) {
397
- f , err := ini . Load ([]byte (`
395
+ f , err := Load ([]byte (`
398
396
#
399
397
# general.domain
400
398
#
@@ -423,7 +421,7 @@ test =
423
421
})
424
422
425
423
t .Run ("keep leading and trailing spaces in value" , func (t * testing.T ) {
426
- f , _ := ini . Load ([]byte (`[foo]
424
+ f , _ := Load ([]byte (`[foo]
427
425
bar1 = ' val ue1 '
428
426
bar2 = """ val ue2 """
429
427
bar3 = " val ue3 "
@@ -443,7 +441,7 @@ bar3 = " val ue3 "
443
441
}
444
442
445
443
func TestFile_SaveTo (t * testing.T ) {
446
- f , err := ini . Load (fullConf )
444
+ f , err := Load (fullConf )
447
445
require .NoError (t , err )
448
446
require .NotNil (t , f )
449
447
@@ -452,7 +450,7 @@ func TestFile_SaveTo(t *testing.T) {
452
450
}
453
451
454
452
func TestFile_WriteToWithOutputDelimiter (t * testing.T ) {
455
- f , err := ini . LoadSources (ini. LoadOptions {
453
+ f , err := LoadSources (LoadOptions {
456
454
KeyValueDelimiterOnWrite : "->" ,
457
455
}, []byte (`[Others]
458
456
Cities = HangZhou|Boston
@@ -488,7 +486,7 @@ Note -> Hello world!
488
486
489
487
// Inspired by https://github.com/go-ini/ini/issues/207
490
488
func TestReloadAfterShadowLoad (t * testing.T ) {
491
- f , err := ini . ShadowLoad ([]byte (`
489
+ f , err := ShadowLoad ([]byte (`
492
490
[slice]
493
491
v = 1
494
492
v = 2
0 commit comments