From 14e9811b1643cf01ea36277e44dffef4f119fa31 Mon Sep 17 00:00:00 2001 From: Joe Chen Date: Thu, 16 Sep 2021 13:34:39 +0800 Subject: [PATCH] test: rename package to be same as the main (#304) --- .github/workflows/go.yml | 4 +- bench_test.go | 8 +- file_test.go | 70 ++++++------ ini_python_multiline_test.go | 67 ------------ ini_test.go | 207 ++++++++++++++++++++++------------- key_test.go | 24 ++-- parser_test.go | 24 ++-- section_test.go | 30 +++-- struct_test.go | 66 ++++++----- 9 files changed, 238 insertions(+), 262 deletions(-) delete mode 100644 ini_python_multiline_test.go diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index c907f84..ea1947f 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -25,7 +25,7 @@ jobs: uses: actions/checkout@v2 - name: Init Go Modules run: | - go mod init gopkg.in/ini.v1 + go mod init github.com/go-ini/ini go mod tidy - name: Run golangci-lint uses: golangci/golangci-lint-action@v2 @@ -50,7 +50,7 @@ jobs: uses: actions/checkout@v2 - name: Run tests with coverage run: | - go mod init gopkg.in/ini.v1 + go mod init github.com/go-ini/ini go mod tidy go test -v -race -coverprofile=coverage -covermode=atomic ./... - name: Upload coverage report to Codecov diff --git a/bench_test.go b/bench_test.go index a1244a7..9fd72f0 100644 --- a/bench_test.go +++ b/bench_test.go @@ -12,16 +12,14 @@ // License for the specific language governing permissions and limitations // under the License. -package ini_test +package ini import ( "testing" - - "gopkg.in/ini.v1" ) -func newTestFile(block bool) *ini.File { - c, _ := ini.Load([]byte(confData)) +func newTestFile(block bool) *File { + c, _ := Load([]byte(confData)) c.BlockMode = block return c } diff --git a/file_test.go b/file_test.go index 836a0d7..3081e99 100644 --- a/file_test.go +++ b/file_test.go @@ -12,7 +12,7 @@ // License for the specific language governing permissions and limitations // under the License. -package ini_test +package ini import ( "bytes" @@ -22,12 +22,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "gopkg.in/ini.v1" ) func TestEmpty(t *testing.T) { - f := ini.Empty() + f := Empty() require.NotNil(t, f) // Should only have the default section @@ -38,7 +36,7 @@ func TestEmpty(t *testing.T) { } func TestFile_NewSection(t *testing.T) { - f := ini.Empty() + f := Empty() require.NotNil(t, f) sec, err := f.NewSection("author") @@ -46,7 +44,7 @@ func TestFile_NewSection(t *testing.T) { require.NotNil(t, sec) assert.Equal(t, "author", sec.Name()) - assert.Equal(t, []string{ini.DefaultSection, "author"}, f.SectionStrings()) + assert.Equal(t, []string{DefaultSection, "author"}, f.SectionStrings()) t.Run("with duplicated name", func(t *testing.T) { sec, err := f.NewSection("author") @@ -54,7 +52,7 @@ func TestFile_NewSection(t *testing.T) { require.NotNil(t, sec) // Does nothing if section already exists - assert.Equal(t, []string{ini.DefaultSection, "author"}, f.SectionStrings()) + assert.Equal(t, []string{DefaultSection, "author"}, f.SectionStrings()) }) t.Run("with empty string", func(t *testing.T) { @@ -65,7 +63,7 @@ func TestFile_NewSection(t *testing.T) { func TestFile_NonUniqueSection(t *testing.T) { t.Run("read and write non-unique sections", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ + f, err := LoadSources(LoadOptions{ AllowNonUniqueSections: true, }, []byte(`[Interface] Address = 192.168.2.1 @@ -114,7 +112,7 @@ AllowedIPs = 192.168.2.4/32 }) t.Run("delete non-unique section", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ + f, err := LoadSources(LoadOptions{ AllowNonUniqueSections: true, }, []byte(`[Interface] Address = 192.168.2.1 @@ -161,20 +159,20 @@ AllowedIPs = 192.168.2.4/32 }) t.Run("delete all sections", func(t *testing.T) { - f := ini.Empty(ini.LoadOptions{ + f := Empty(LoadOptions{ AllowNonUniqueSections: true, }) require.NotNil(t, f) _ = f.NewSections("Interface", "Peer", "Peer") - assert.Equal(t, []string{ini.DefaultSection, "Interface", "Peer", "Peer"}, f.SectionStrings()) + assert.Equal(t, []string{DefaultSection, "Interface", "Peer", "Peer"}, f.SectionStrings()) f.DeleteSection("Peer") - assert.Equal(t, []string{ini.DefaultSection, "Interface"}, f.SectionStrings()) + assert.Equal(t, []string{DefaultSection, "Interface"}, f.SectionStrings()) }) } func TestFile_NewRawSection(t *testing.T) { - f := ini.Empty() + f := Empty() require.NotNil(t, f) sec, err := f.NewRawSection("comments", `1111111111111111111000000000000000001110000 @@ -183,7 +181,7 @@ func TestFile_NewRawSection(t *testing.T) { require.NotNil(t, sec) assert.Equal(t, "comments", sec.Name()) - assert.Equal(t, []string{ini.DefaultSection, "comments"}, f.SectionStrings()) + assert.Equal(t, []string{DefaultSection, "comments"}, f.SectionStrings()) assert.Equal(t, `1111111111111111111000000000000000001110000 111111111111111111100000000000111000000000`, f.Section("comments").Body()) @@ -191,7 +189,7 @@ func TestFile_NewRawSection(t *testing.T) { sec, err := f.NewRawSection("comments", `1111111111111111111000000000000000001110000`) require.NoError(t, err) require.NotNil(t, sec) - assert.Equal(t, []string{ini.DefaultSection, "comments"}, f.SectionStrings()) + assert.Equal(t, []string{DefaultSection, "comments"}, f.SectionStrings()) // Overwrite previous existed section assert.Equal(t, `1111111111111111111000000000000000001110000`, f.Section("comments").Body()) @@ -204,17 +202,17 @@ func TestFile_NewRawSection(t *testing.T) { } func TestFile_NewSections(t *testing.T) { - f := ini.Empty() + f := Empty() require.NotNil(t, f) assert.NoError(t, f.NewSections("package", "author")) - assert.Equal(t, []string{ini.DefaultSection, "package", "author"}, f.SectionStrings()) + assert.Equal(t, []string{DefaultSection, "package", "author"}, f.SectionStrings()) t.Run("with duplicated name", func(t *testing.T) { assert.NoError(t, f.NewSections("author", "features")) // Ignore section already exists - assert.Equal(t, []string{ini.DefaultSection, "package", "author", "features"}, f.SectionStrings()) + assert.Equal(t, []string{DefaultSection, "package", "author", "features"}, f.SectionStrings()) }) t.Run("with empty string", func(t *testing.T) { @@ -223,7 +221,7 @@ func TestFile_NewSections(t *testing.T) { } func TestFile_GetSection(t *testing.T) { - f, err := ini.Load(fullConf) + f, err := Load(fullConf) require.NoError(t, err) require.NotNil(t, f) @@ -240,7 +238,7 @@ func TestFile_GetSection(t *testing.T) { func TestFile_Section(t *testing.T) { t.Run("get a section", func(t *testing.T) { - f, err := ini.Load(fullConf) + f, err := Load(fullConf) require.NoError(t, err) require.NotNil(t, f) @@ -256,7 +254,7 @@ func TestFile_Section(t *testing.T) { }) t.Run("get default section in lower case with insensitive load", func(t *testing.T) { - f, err := ini.InsensitiveLoad([]byte(` + f, err := InsensitiveLoad([]byte(` [default] NAME = ini VERSION = v1`)) @@ -269,12 +267,12 @@ VERSION = v1`)) } func TestFile_Sections(t *testing.T) { - f, err := ini.Load(fullConf) + f, err := Load(fullConf) require.NoError(t, err) require.NotNil(t, f) secs := f.Sections() - names := []string{ini.DefaultSection, "author", "package", "package.sub", "features", "types", "array", "note", "comments", "string escapes", "advance"} + names := []string{DefaultSection, "author", "package", "package.sub", "features", "types", "array", "note", "comments", "string escapes", "advance"} assert.Len(t, secs, len(names)) for i, name := range names { assert.Equal(t, name, secs[i].Name()) @@ -282,7 +280,7 @@ func TestFile_Sections(t *testing.T) { } func TestFile_ChildSections(t *testing.T) { - f, err := ini.Load([]byte(` + f, err := Load([]byte(` [node] [node.biz1] [node.biz2] @@ -301,16 +299,16 @@ func TestFile_ChildSections(t *testing.T) { } func TestFile_SectionStrings(t *testing.T) { - f, err := ini.Load(fullConf) + f, err := Load(fullConf) require.NoError(t, err) require.NotNil(t, f) - assert.Equal(t, []string{ini.DefaultSection, "author", "package", "package.sub", "features", "types", "array", "note", "comments", "string escapes", "advance"}, f.SectionStrings()) + assert.Equal(t, []string{DefaultSection, "author", "package", "package.sub", "features", "types", "array", "note", "comments", "string escapes", "advance"}, f.SectionStrings()) } func TestFile_DeleteSection(t *testing.T) { t.Run("delete a section", func(t *testing.T) { - f := ini.Empty() + f := Empty() require.NotNil(t, f) _ = f.NewSections("author", "package", "features") @@ -320,7 +318,7 @@ func TestFile_DeleteSection(t *testing.T) { }) t.Run("delete default section", func(t *testing.T) { - f := ini.Empty() + f := Empty() require.NotNil(t, f) f.Section("").Key("foo").SetValue("bar") @@ -339,7 +337,7 @@ key1 = value1 }) t.Run("delete a section with InsensitiveSections", func(t *testing.T) { - f := ini.Empty(ini.LoadOptions{InsensitiveSections: true}) + f := Empty(LoadOptions{InsensitiveSections: true}) require.NotNil(t, f) _ = f.NewSections("author", "package", "features") @@ -350,7 +348,7 @@ key1 = value1 } func TestFile_Append(t *testing.T) { - f := ini.Empty() + f := Empty() require.NotNil(t, f) assert.NoError(t, f.Append(minimalConf, []byte(` @@ -369,7 +367,7 @@ func TestFile_WriteTo(t *testing.T) { } t.Run("write content to somewhere", func(t *testing.T) { - f, err := ini.Load(fullConf) + f, err := Load(fullConf) require.NoError(t, err) require.NotNil(t, f) @@ -394,7 +392,7 @@ func TestFile_WriteTo(t *testing.T) { }) t.Run("support multiline comments", func(t *testing.T) { - f, err := ini.Load([]byte(` + f, err := Load([]byte(` # # general.domain # @@ -423,7 +421,7 @@ test = }) t.Run("keep leading and trailing spaces in value", func(t *testing.T) { - f, _ := ini.Load([]byte(`[foo] + f, _ := Load([]byte(`[foo] bar1 = ' val ue1 ' bar2 = """ val ue2 """ bar3 = " val ue3 " @@ -443,7 +441,7 @@ bar3 = " val ue3 " } func TestFile_SaveTo(t *testing.T) { - f, err := ini.Load(fullConf) + f, err := Load(fullConf) require.NoError(t, err) require.NotNil(t, f) @@ -452,7 +450,7 @@ func TestFile_SaveTo(t *testing.T) { } func TestFile_WriteToWithOutputDelimiter(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ + f, err := LoadSources(LoadOptions{ KeyValueDelimiterOnWrite: "->", }, []byte(`[Others] Cities = HangZhou|Boston @@ -488,7 +486,7 @@ Note -> Hello world! // Inspired by https://github.com/go-ini/ini/issues/207 func TestReloadAfterShadowLoad(t *testing.T) { - f, err := ini.ShadowLoad([]byte(` + f, err := ShadowLoad([]byte(` [slice] v = 1 v = 2 diff --git a/ini_python_multiline_test.go b/ini_python_multiline_test.go deleted file mode 100644 index 14fd7ec..0000000 --- a/ini_python_multiline_test.go +++ /dev/null @@ -1,67 +0,0 @@ -package ini_test - -import ( - "path/filepath" - "runtime" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - "gopkg.in/ini.v1" -) - -type testData struct { - Value1 string `ini:"value1"` - Value2 string `ini:"value2"` - Value3 string `ini:"value3"` -} - -func TestMultiline(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("Skipping testing on Windows") - } - - path := filepath.Join("testdata", "multiline.ini") - f, err := ini.LoadSources(ini.LoadOptions{ - AllowPythonMultilineValues: true, - ReaderBufferSize: 64 * 1024, - }, path) - require.NoError(t, err) - require.NotNil(t, f) - assert.Len(t, f.Sections(), 1) - - defaultSection := f.Section("") - assert.NotNil(t, f.Section("")) - - var testData testData - err = defaultSection.MapTo(&testData) - require.NoError(t, err) - assert.Equal(t, "some text here\nsome more text here\n\nthere is an empty line above and below\n", testData.Value1) - assert.Equal(t, "there is an empty line above\nthat is not indented so it should not be part\nof the value", testData.Value2) - assert.Equal(t, `. - -Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Eu consequat ac felis donec et odio pellentesque diam volutpat. Mauris commodo quis imperdiet massa tincidunt nunc. Interdum velit euismod in pellentesque. Nisl condimentum id venenatis a condimentum vitae sapien pellentesque. Nascetur ridiculus mus mauris vitae. Posuere urna nec tincidunt praesent semper feugiat. Lorem donec massa sapien faucibus et molestie ac feugiat sed. Ipsum dolor sit amet consectetur adipiscing elit. Enim sed faucibus turpis in eu mi. A diam sollicitudin tempor id. Quam nulla porttitor massa id neque aliquam vestibulum morbi blandit. - -Lectus sit amet est placerat in egestas. At risus viverra adipiscing at in tellus integer. Tristique senectus et netus et malesuada fames ac. In hac habitasse platea dictumst. Purus in mollis nunc sed. Pellentesque sit amet porttitor eget dolor morbi. Elit at imperdiet dui accumsan sit amet nulla. Cursus in hac habitasse platea dictumst. Bibendum arcu vitae elementum curabitur. Faucibus ornare suspendisse sed nisi lacus. In vitae turpis massa sed. Libero nunc consequat interdum varius sit amet. Molestie a iaculis at erat pellentesque. - -Dui faucibus in ornare quam viverra orci sagittis eu. Purus in mollis nunc sed id semper. Sed arcu non odio euismod lacinia at. Quis commodo odio aenean sed adipiscing diam donec. Quisque id diam vel quam elementum pulvinar. Lorem ipsum dolor sit amet. Purus ut faucibus pulvinar elementum integer enim neque volutpat ac. Fermentum posuere urna nec tincidunt praesent semper feugiat nibh sed. Gravida rutrum quisque non tellus orci. Ipsum dolor sit amet consectetur adipiscing elit pellentesque habitant. Et sollicitudin ac orci phasellus egestas tellus rutrum tellus pellentesque. Eget gravida cum sociis natoque penatibus et magnis. Elementum eu facilisis sed odio morbi quis commodo. Mollis nunc sed id semper risus in hendrerit gravida rutrum. Lorem dolor sed viverra ipsum. - -Pellentesque adipiscing commodo elit at imperdiet dui accumsan sit amet. Justo eget magna fermentum iaculis eu non diam. Condimentum mattis pellentesque id nibh tortor id aliquet lectus. Tellus molestie nunc non blandit massa enim. Mauris ultrices eros in cursus turpis. Purus viverra accumsan in nisl nisi scelerisque. Quis lectus nulla at volutpat. Purus ut faucibus pulvinar elementum integer enim. In pellentesque massa placerat duis ultricies lacus sed turpis. Elit sed vulputate mi sit amet mauris commodo. Tellus elementum sagittis vitae et. Duis tristique sollicitudin nibh sit amet commodo nulla facilisi nullam. Lectus vestibulum mattis ullamcorper velit sed ullamcorper morbi tincidunt ornare. Libero id faucibus nisl tincidunt eget nullam. Mattis aliquam faucibus purus in massa tempor. Fames ac turpis egestas sed tempus urna. Gravida in fermentum et sollicitudin ac orci phasellus egestas. - -Blandit turpis cursus in hac habitasse. Sed id semper risus in. Amet porttitor eget dolor morbi non arcu. Rhoncus est pellentesque elit ullamcorper dignissim cras tincidunt. Ut morbi tincidunt augue interdum velit. Lorem mollis aliquam ut porttitor leo a. Nunc eget lorem dolor sed viverra. Scelerisque mauris pellentesque pulvinar pellentesque. Elit at imperdiet dui accumsan sit amet. Eget magna fermentum iaculis eu non diam phasellus vestibulum lorem. Laoreet non curabitur gravida arcu ac tortor dignissim. Tortor pretium viverra suspendisse potenti nullam ac tortor vitae purus. Lacus sed viverra tellus in hac habitasse platea dictumst vestibulum. Viverra adipiscing at in tellus. Duis at tellus at urna condimentum. Eget gravida cum sociis natoque penatibus et magnis dis parturient. Pharetra massa massa ultricies mi quis hendrerit. - -Mauris pellentesque pulvinar pellentesque habitant morbi tristique. Maecenas volutpat blandit aliquam etiam. Sed turpis tincidunt id aliquet. Eget duis at tellus at urna condimentum. Pellentesque habitant morbi tristique senectus et. Amet aliquam id diam maecenas. Volutpat est velit egestas dui id. Vulputate eu scelerisque felis imperdiet proin fermentum leo vel orci. Massa sed elementum tempus egestas sed sed risus pretium. Quam quisque id diam vel quam elementum pulvinar etiam non. Sapien faucibus et molestie ac. Ipsum dolor sit amet consectetur adipiscing. Viverra orci sagittis eu volutpat. Leo urna molestie at elementum. Commodo viverra maecenas accumsan lacus. Non sodales neque sodales ut etiam sit amet. Habitant morbi tristique senectus et netus et malesuada fames. Habitant morbi tristique senectus et netus et malesuada. Blandit aliquam etiam erat velit scelerisque in. Varius duis at consectetur lorem donec massa sapien faucibus et. - -Augue mauris augue neque gravida in. Odio ut sem nulla pharetra diam sit amet nisl suscipit. Nulla aliquet enim tortor at auctor urna nunc id. Morbi tristique senectus et netus et malesuada fames ac. Quam id leo in vitae turpis massa sed elementum tempus. Ipsum faucibus vitae aliquet nec ullamcorper sit amet risus nullam. Maecenas volutpat blandit aliquam etiam erat velit scelerisque in. Sagittis nisl rhoncus mattis rhoncus urna neque viverra justo. Massa tempor nec feugiat nisl pretium. Vulputate sapien nec sagittis aliquam malesuada bibendum arcu vitae elementum. Enim lobortis scelerisque fermentum dui faucibus in ornare. Faucibus ornare suspendisse sed nisi lacus. Morbi tristique senectus et netus et malesuada fames. Malesuada pellentesque elit eget gravida cum sociis natoque penatibus et. Dictum non consectetur a erat nam at. Leo urna molestie at elementum eu facilisis sed odio morbi. Quam id leo in vitae turpis massa. Neque egestas congue quisque egestas diam in arcu. Varius morbi enim nunc faucibus a pellentesque sit. Aliquet enim tortor at auctor urna. - -Elit scelerisque mauris pellentesque pulvinar pellentesque habitant morbi tristique. Luctus accumsan tortor posuere ac. Eu ultrices vitae auctor eu augue ut lectus arcu bibendum. Pretium nibh ipsum consequat nisl vel pretium lectus. Aliquam etiam erat velit scelerisque in dictum. Sem et tortor consequat id porta nibh venenatis cras sed. A scelerisque purus semper eget duis at tellus at urna. At auctor urna nunc id. Ornare quam viverra orci sagittis eu volutpat odio. Nisl purus in mollis nunc sed id semper. Ornare suspendisse sed nisi lacus sed. Consectetur lorem donec massa sapien faucibus et. Ipsum dolor sit amet consectetur adipiscing elit ut. Porta nibh venenatis cras sed. Dignissim diam quis enim lobortis scelerisque. Quam nulla porttitor massa id. Tellus molestie nunc non blandit massa. - -Malesuada fames ac turpis egestas. Suscipit tellus mauris a diam maecenas. Turpis in eu mi bibendum neque egestas. Venenatis tellus in metus vulputate eu scelerisque felis imperdiet. Quis imperdiet massa tincidunt nunc pulvinar sapien et. Urna duis convallis convallis tellus id. Velit egestas dui id ornare arcu odio. Consectetur purus ut faucibus pulvinar elementum integer enim neque. Aenean sed adipiscing diam donec adipiscing tristique. Tortor aliquam nulla facilisi cras fermentum odio eu. Diam in arcu cursus euismod quis viverra nibh cras. - -Id ornare arcu odio ut sem. Arcu dictum varius duis at consectetur lorem donec massa sapien. Proin libero nunc consequat interdum varius sit. Ut eu sem integer vitae justo. Vitae elementum curabitur vitae nunc. Diam quam nulla porttitor massa. Lectus mauris ultrices eros in cursus turpis massa tincidunt dui. Natoque penatibus et magnis dis parturient montes. Pellentesque habitant morbi tristique senectus et netus et malesuada fames. Libero nunc consequat interdum varius sit. Rhoncus dolor purus non enim praesent. Pellentesque sit amet porttitor eget. Nibh tortor id aliquet lectus proin nibh. Fermentum iaculis eu non diam phasellus vestibulum lorem sed. - -Eu feugiat pretium nibh ipsum consequat nisl vel pretium lectus. Habitant morbi tristique senectus et netus et malesuada fames ac. Urna condimentum mattis pellentesque id. Lorem sed risus ultricies tristique nulla aliquet enim tortor at. Ipsum dolor sit amet consectetur adipiscing elit. Convallis a cras semper auctor neque vitae tempus quam. A diam sollicitudin tempor id eu nisl nunc mi ipsum. Maecenas sed enim ut sem viverra aliquet eget. Massa enim nec dui nunc mattis enim. Nam aliquam sem et tortor consequat. Adipiscing commodo elit at imperdiet dui accumsan sit amet nulla. Nullam eget felis eget nunc lobortis. Mauris a diam maecenas sed enim ut sem viverra. Ornare massa eget egestas purus. In hac habitasse platea dictumst. Ut tortor pretium viverra suspendisse potenti nullam ac tortor. Nisl nunc mi ipsum faucibus. At varius vel pharetra vel. Mauris ultrices eros in cursus turpis massa tincidunt.`, - testData.Value3, - ) -} diff --git a/ini_test.go b/ini_test.go index aba6052..e058a21 100644 --- a/ini_test.go +++ b/ini_test.go @@ -12,18 +12,18 @@ // License for the specific language governing permissions and limitations // under the License. -package ini_test +package ini import ( "bytes" "flag" "io/ioutil" + "path/filepath" + "runtime" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "gopkg.in/ini.v1" ) const ( @@ -54,7 +54,7 @@ var update = flag.Bool("update", false, "Update .golden files") func TestLoad(t *testing.T) { t.Run("load from good data sources", func(t *testing.T) { - f, err := ini.Load( + f, err := Load( "testdata/minimal.ini", []byte("NAME = ini\nIMPORT_PATH = gopkg.in/%(NAME)s.%(VERSION)s"), bytes.NewReader([]byte(`VERSION = v1`)), @@ -76,18 +76,18 @@ func TestLoad(t *testing.T) { t.Run("load from bad data sources", func(t *testing.T) { t.Run("invalid input", func(t *testing.T) { - _, err := ini.Load(notFoundConf) + _, err := Load(notFoundConf) require.Error(t, err) }) t.Run("unsupported type", func(t *testing.T) { - _, err := ini.Load(123) + _, err := Load(123) require.Error(t, err) }) }) t.Run("cannot properly parse INI files containing `#` or `;` in value", func(t *testing.T) { - f, err := ini.Load([]byte(` + f, err := Load([]byte(` [author] NAME = U#n#k#n#w#o#n GITHUB = U;n;k;n;w;o;n @@ -103,7 +103,7 @@ func TestLoad(t *testing.T) { }) t.Run("cannot parse small python-compatible INI files", func(t *testing.T) { - f, err := ini.Load([]byte(` + f, err := Load([]byte(` [long] long_rsa_private_key = -----BEGIN RSA PRIVATE KEY----- foo @@ -118,7 +118,7 @@ long_rsa_private_key = -----BEGIN RSA PRIVATE KEY----- }) t.Run("cannot parse big python-compatible INI files", func(t *testing.T) { - f, err := ini.Load([]byte(` + f, err := Load([]byte(` [long] long_rsa_private_key = -----BEGIN RSA PRIVATE KEY----- 1foo @@ -226,19 +226,19 @@ long_rsa_private_key = -----BEGIN RSA PRIVATE KEY----- } func TestLooseLoad(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{Loose: true}, notFoundConf, minimalConf) + f, err := LoadSources(LoadOptions{Loose: true}, notFoundConf, minimalConf) require.NoError(t, err) require.NotNil(t, f) t.Run("inverse case", func(t *testing.T) { - _, err = ini.Load(notFoundConf) + _, err = Load(notFoundConf) require.Error(t, err) }) } func TestInsensitiveLoad(t *testing.T) { t.Run("insensitive to section and key names", func(t *testing.T) { - f, err := ini.InsensitiveLoad(minimalConf) + f, err := InsensitiveLoad(minimalConf) require.NoError(t, err) require.NotNil(t, f) @@ -257,7 +257,7 @@ e-mail = u@gogs.io }) t.Run("inverse case", func(t *testing.T) { - f, err := ini.Load(minimalConf) + f, err := Load(minimalConf) require.NoError(t, err) require.NotNil(t, f) @@ -267,7 +267,7 @@ e-mail = u@gogs.io // Ref: https://github.com/go-ini/ini/issues/198 t.Run("insensitive load with default section", func(t *testing.T) { - f, err := ini.InsensitiveLoad([]byte(` + f, err := InsensitiveLoad([]byte(` user = unknwon [profile] email = unknwon@local @@ -275,25 +275,25 @@ email = unknwon@local require.NoError(t, err) require.NotNil(t, f) - assert.Equal(t, "unknwon", f.Section(ini.DefaultSection).Key("user").String()) + assert.Equal(t, "unknwon", f.Section(DefaultSection).Key("user").String()) }) } func TestLoadSources(t *testing.T) { t.Run("with true `AllowPythonMultilineValues`", func(t *testing.T) { t.Run("ignore nonexistent files", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: true, Loose: true}, notFoundConf, minimalConf) + f, err := LoadSources(LoadOptions{AllowPythonMultilineValues: true, Loose: true}, notFoundConf, minimalConf) require.NoError(t, err) require.NotNil(t, f) t.Run("inverse case", func(t *testing.T) { - _, err = ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: true}, notFoundConf) + _, err = LoadSources(LoadOptions{AllowPythonMultilineValues: true}, notFoundConf) require.Error(t, err) }) }) t.Run("insensitive to section and key names", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: true, Insensitive: true}, minimalConf) + f, err := LoadSources(LoadOptions{AllowPythonMultilineValues: true, Insensitive: true}, minimalConf) require.NoError(t, err) require.NotNil(t, f) @@ -312,7 +312,7 @@ e-mail = u@gogs.io }) t.Run("inverse case", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: true}, minimalConf) + f, err := LoadSources(LoadOptions{AllowPythonMultilineValues: true}, minimalConf) require.NoError(t, err) require.NotNil(t, f) @@ -321,7 +321,7 @@ e-mail = u@gogs.io }) t.Run("insensitive to sections and sensitive to key names", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{InsensitiveSections: true}, minimalConf) + f, err := LoadSources(LoadOptions{InsensitiveSections: true}, minimalConf) require.NoError(t, err) require.NotNil(t, f) @@ -340,7 +340,7 @@ E-MAIL = u@gogs.io }) t.Run("inverse case", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{}, minimalConf) + f, err := LoadSources(LoadOptions{}, minimalConf) require.NoError(t, err) require.NotNil(t, f) @@ -349,7 +349,7 @@ E-MAIL = u@gogs.io }) t.Run("sensitive to sections and insensitive to key names", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{InsensitiveKeys: true}, minimalConf) + f, err := LoadSources(LoadOptions{InsensitiveKeys: true}, minimalConf) require.NoError(t, err) require.NotNil(t, f) @@ -368,7 +368,7 @@ e-mail = u@gogs.io }) t.Run("inverse case", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{}, minimalConf) + f, err := LoadSources(LoadOptions{}, minimalConf) require.NoError(t, err) require.NotNil(t, f) @@ -377,7 +377,7 @@ e-mail = u@gogs.io }) t.Run("ignore continuation lines", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ + f, err := LoadSources(LoadOptions{ AllowPythonMultilineValues: true, IgnoreContinuation: true, }, []byte(` @@ -392,7 +392,7 @@ key3=value`)) assert.Equal(t, "value", f.Section("").Key("key3").String()) t.Run("inverse case", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: true}, []byte(` + f, err := LoadSources(LoadOptions{AllowPythonMultilineValues: true}, []byte(` key1=a\b\ key2=c\d\`)) require.NoError(t, err) @@ -403,7 +403,7 @@ key2=c\d\`)) }) t.Run("ignore inline comments", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ + f, err := LoadSources(LoadOptions{ AllowPythonMultilineValues: true, IgnoreInlineComment: true, }, []byte(` @@ -418,7 +418,7 @@ key3=val#ue #comment3`)) assert.Equal(t, `val#ue #comment3`, f.Section("").Key("key3").String()) t.Run("inverse case", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: true}, []byte(` + f, err := LoadSources(LoadOptions{AllowPythonMultilineValues: true}, []byte(` key1=value ;comment key2=value2 #comment2`)) require.NoError(t, err) @@ -432,7 +432,7 @@ key2=value2 #comment2`)) }) t.Run("skip unrecognizable lines", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ + f, err := LoadSources(LoadOptions{ SkipUnrecognizableLines: true, }, []byte(` GenerationDepth: 13 @@ -455,7 +455,7 @@ BiomeGroup(IceBiomes, 4, 85, Ice Plains) }) t.Run("allow boolean type keys", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ + f, err := LoadSources(LoadOptions{ AllowPythonMultilineValues: true, AllowBooleanKeys: true, }, []byte(` @@ -481,7 +481,7 @@ key3 }) t.Run("inverse case", func(t *testing.T) { - _, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: true}, []byte(` + _, err := LoadSources(LoadOptions{AllowPythonMultilineValues: true}, []byte(` key1=hello #key2 key3`)) @@ -490,7 +490,7 @@ key3`)) }) t.Run("allow shadow keys", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{AllowShadows: true, AllowPythonMultilineValues: true}, []byte(` + f, err := LoadSources(LoadOptions{AllowShadows: true, AllowPythonMultilineValues: true}, []byte(` [remote "origin"] url = https://github.com/Antergone/test1.git url = https://github.com/Antergone/test2.git @@ -524,7 +524,7 @@ fetch = +refs/heads/*:refs/remotes/origin/* }) t.Run("inverse case", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: true}, []byte(` + f, err := LoadSources(LoadOptions{AllowPythonMultilineValues: true}, []byte(` [remote "origin"] url = https://github.com/Antergone/test1.git url = https://github.com/Antergone/test2.git`)) @@ -536,7 +536,7 @@ url = https://github.com/Antergone/test2.git`)) }) t.Run("unescape double quotes inside value", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ + f, err := LoadSources(LoadOptions{ AllowPythonMultilineValues: true, UnescapeValueDoubleQuotes: true, }, []byte(` @@ -547,7 +547,7 @@ create_repo="创建了仓库 %s"`)) assert.Equal(t, `创建了仓库 %s`, f.Section("").Key("create_repo").String()) t.Run("inverse case", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: true}, []byte(` + f, err := LoadSources(LoadOptions{AllowPythonMultilineValues: true}, []byte(` create_repo="创建了仓库 %s"`)) require.NoError(t, err) require.NotNil(t, f) @@ -557,7 +557,7 @@ create_repo="创建了仓库 %s"`)) }) t.Run("unescape comment symbols inside value", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ + f, err := LoadSources(LoadOptions{ AllowPythonMultilineValues: true, IgnoreInlineComment: true, UnescapeValueCommentSymbols: true, @@ -571,7 +571,7 @@ key = test value more text }) t.Run("can parse small python-compatible INI files", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ + f, err := LoadSources(LoadOptions{ AllowPythonMultilineValues: true, Insensitive: true, UnparseableSections: []string{"core_lesson", "comments"}, @@ -596,7 +596,7 @@ multiline_list = }) t.Run("can parse big python-compatible INI files", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ + f, err := LoadSources(LoadOptions{ AllowPythonMultilineValues: true, Insensitive: true, UnparseableSections: []string{"core_lesson", "comments"}, @@ -807,7 +807,7 @@ long_rsa_private_key = -----BEGIN RSA PRIVATE KEY----- }) t.Run("allow unparsable sections", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ + f, err := LoadSources(LoadOptions{ AllowPythonMultilineValues: true, Insensitive: true, UnparseableSections: []string{"core_lesson", "comments"}, @@ -855,7 +855,7 @@ my lesson state data – 1111111111111111111000000000000000001110000 }) t.Run("inverse case", func(t *testing.T) { - _, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: true}, []byte(` + _, err := LoadSources(LoadOptions{AllowPythonMultilineValues: true}, []byte(` [CORE_LESSON] my lesson state data – 1111111111111111111000000000000000001110000 111111111111111111100000000000111000000000 – end my lesson state data`)) @@ -865,8 +865,8 @@ my lesson state data – 1111111111111111111000000000000000001110000 t.Run("and false `SpaceBeforeInlineComment`", func(t *testing.T) { t.Run("cannot parse INI files containing `#` or `;` in value", func(t *testing.T) { - f, err := ini.LoadSources( - ini.LoadOptions{AllowPythonMultilineValues: false, SpaceBeforeInlineComment: false}, + f, err := LoadSources( + LoadOptions{AllowPythonMultilineValues: false, SpaceBeforeInlineComment: false}, []byte(` [author] NAME = U#n#k#n#w#o#n @@ -884,8 +884,8 @@ GITHUB = U;n;k;n;w;o;n t.Run("and true `SpaceBeforeInlineComment`", func(t *testing.T) { t.Run("can parse INI files containing `#` or `;` in value", func(t *testing.T) { - f, err := ini.LoadSources( - ini.LoadOptions{AllowPythonMultilineValues: false, SpaceBeforeInlineComment: true}, + f, err := LoadSources( + LoadOptions{AllowPythonMultilineValues: false, SpaceBeforeInlineComment: true}, []byte(` [author] NAME = U#n#k#n#w#o#n @@ -904,7 +904,7 @@ GITHUB = U;n;k;n;w;o;n t.Run("with false `AllowPythonMultilineValues`", func(t *testing.T) { t.Run("ignore nonexistent files", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ + f, err := LoadSources(LoadOptions{ AllowPythonMultilineValues: false, Loose: true, }, notFoundConf, minimalConf) @@ -912,7 +912,7 @@ GITHUB = U;n;k;n;w;o;n require.NotNil(t, f) t.Run("inverse case", func(t *testing.T) { - _, err = ini.LoadSources(ini.LoadOptions{ + _, err = LoadSources(LoadOptions{ AllowPythonMultilineValues: false, }, notFoundConf) require.Error(t, err) @@ -920,7 +920,7 @@ GITHUB = U;n;k;n;w;o;n }) t.Run("insensitive to section and key names", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ + f, err := LoadSources(LoadOptions{ AllowPythonMultilineValues: false, Insensitive: true, }, minimalConf) @@ -942,7 +942,7 @@ e-mail = u@gogs.io }) t.Run("inverse case", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ + f, err := LoadSources(LoadOptions{ AllowPythonMultilineValues: false, }, minimalConf) require.NoError(t, err) @@ -953,7 +953,7 @@ e-mail = u@gogs.io }) t.Run("ignore continuation lines", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ + f, err := LoadSources(LoadOptions{ AllowPythonMultilineValues: false, IgnoreContinuation: true, }, []byte(` @@ -968,7 +968,7 @@ key3=value`)) assert.Equal(t, "value", f.Section("").Key("key3").String()) t.Run("inverse case", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: false}, []byte(` + f, err := LoadSources(LoadOptions{AllowPythonMultilineValues: false}, []byte(` key1=a\b\ key2=c\d\`)) require.NoError(t, err) @@ -979,7 +979,7 @@ key2=c\d\`)) }) t.Run("ignore inline comments", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ + f, err := LoadSources(LoadOptions{ AllowPythonMultilineValues: false, IgnoreInlineComment: true, }, []byte(` @@ -994,7 +994,7 @@ key3=val#ue #comment3`)) assert.Equal(t, `val#ue #comment3`, f.Section("").Key("key3").String()) t.Run("inverse case", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: false}, []byte(` + f, err := LoadSources(LoadOptions{AllowPythonMultilineValues: false}, []byte(` key1=value ;comment key2=value2 #comment2`)) require.NoError(t, err) @@ -1008,7 +1008,7 @@ key2=value2 #comment2`)) }) t.Run("allow boolean type keys", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ + f, err := LoadSources(LoadOptions{ AllowPythonMultilineValues: false, AllowBooleanKeys: true, }, []byte(` @@ -1034,7 +1034,7 @@ key3 }) t.Run("inverse case", func(t *testing.T) { - _, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: false}, []byte(` + _, err := LoadSources(LoadOptions{AllowPythonMultilineValues: false}, []byte(` key1=hello #key2 key3`)) @@ -1043,7 +1043,7 @@ key3`)) }) t.Run("allow shadow keys", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: false, AllowShadows: true}, []byte(` + f, err := LoadSources(LoadOptions{AllowPythonMultilineValues: false, AllowShadows: true}, []byte(` [remote "origin"] url = https://github.com/Antergone/test1.git url = https://github.com/Antergone/test2.git @@ -1077,7 +1077,7 @@ fetch = +refs/heads/*:refs/remotes/origin/* }) t.Run("inverse case", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: false}, []byte(` + f, err := LoadSources(LoadOptions{AllowPythonMultilineValues: false}, []byte(` [remote "origin"] url = https://github.com/Antergone/test1.git url = https://github.com/Antergone/test2.git`)) @@ -1089,7 +1089,7 @@ url = https://github.com/Antergone/test2.git`)) }) t.Run("unescape double quotes inside value", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ + f, err := LoadSources(LoadOptions{ AllowPythonMultilineValues: false, UnescapeValueDoubleQuotes: true, }, []byte(` @@ -1100,7 +1100,7 @@ create_repo="创建了仓库 %s"`)) assert.Equal(t, `创建了仓库 %s`, f.Section("").Key("create_repo").String()) t.Run("inverse case", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: false}, []byte(` + f, err := LoadSources(LoadOptions{AllowPythonMultilineValues: false}, []byte(` create_repo="创建了仓库 %s"`)) require.NoError(t, err) require.NotNil(t, f) @@ -1110,7 +1110,7 @@ create_repo="创建了仓库 %s"`)) }) t.Run("unescape comment symbols inside value", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ + f, err := LoadSources(LoadOptions{ AllowPythonMultilineValues: false, IgnoreInlineComment: true, UnescapeValueCommentSymbols: true, @@ -1124,7 +1124,7 @@ key = test value more text }) t.Run("cannot parse small python-compatible INI files", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: false}, []byte(` + f, err := LoadSources(LoadOptions{AllowPythonMultilineValues: false}, []byte(` [long] long_rsa_private_key = -----BEGIN RSA PRIVATE KEY----- foo @@ -1139,7 +1139,7 @@ long_rsa_private_key = -----BEGIN RSA PRIVATE KEY----- }) t.Run("cannot parse big python-compatible INI files", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: false}, []byte(` + f, err := LoadSources(LoadOptions{AllowPythonMultilineValues: false}, []byte(` [long] long_rsa_private_key = -----BEGIN RSA PRIVATE KEY----- 1foo @@ -1246,7 +1246,7 @@ long_rsa_private_key = -----BEGIN RSA PRIVATE KEY----- }) t.Run("allow unparsable sections", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ + f, err := LoadSources(LoadOptions{ AllowPythonMultilineValues: false, Insensitive: true, UnparseableSections: []string{"core_lesson", "comments"}, @@ -1294,7 +1294,7 @@ my lesson state data – 1111111111111111111000000000000000001110000 }) t.Run("inverse case", func(t *testing.T) { - _, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: false}, []byte(` + _, err := LoadSources(LoadOptions{AllowPythonMultilineValues: false}, []byte(` [CORE_LESSON] my lesson state data – 1111111111111111111000000000000000001110000 111111111111111111100000000000111000000000 – end my lesson state data`)) @@ -1304,8 +1304,8 @@ my lesson state data – 1111111111111111111000000000000000001110000 t.Run("and false `SpaceBeforeInlineComment`", func(t *testing.T) { t.Run("cannot parse INI files containing `#` or `;` in value", func(t *testing.T) { - f, err := ini.LoadSources( - ini.LoadOptions{AllowPythonMultilineValues: true, SpaceBeforeInlineComment: false}, + f, err := LoadSources( + LoadOptions{AllowPythonMultilineValues: true, SpaceBeforeInlineComment: false}, []byte(` [author] NAME = U#n#k#n#w#o#n @@ -1323,8 +1323,8 @@ GITHUB = U;n;k;n;w;o;n t.Run("and true `SpaceBeforeInlineComment`", func(t *testing.T) { t.Run("can parse INI files containing `#` or `;` in value", func(t *testing.T) { - f, err := ini.LoadSources( - ini.LoadOptions{AllowPythonMultilineValues: true, SpaceBeforeInlineComment: true}, + f, err := LoadSources( + LoadOptions{AllowPythonMultilineValues: true, SpaceBeforeInlineComment: true}, []byte(` [author] NAME = U#n#k#n#w#o#n @@ -1343,7 +1343,7 @@ GITHUB = U;n;k;n;w;o;n t.Run("with `ChildSectionDelimiter` ':'", func(t *testing.T) { t.Run("get all keys of parent sections", func(t *testing.T) { - f := ini.Empty(ini.LoadOptions{ChildSectionDelimiter: ":"}) + f := Empty(LoadOptions{ChildSectionDelimiter: ":"}) require.NotNil(t, f) k, err := f.Section("package").NewKey("NAME", "ini") @@ -1365,7 +1365,7 @@ GITHUB = U;n;k;n;w;o;n }) t.Run("getting and setting values", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ChildSectionDelimiter: ":"}, fullConf) + f, err := LoadSources(LoadOptions{ChildSectionDelimiter: ":"}, fullConf) require.NoError(t, err) require.NotNil(t, f) @@ -1384,7 +1384,7 @@ GITHUB = U;n;k;n;w;o;n }) t.Run("get child sections by parent name", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ChildSectionDelimiter: ":"}, []byte(` + f, err := LoadSources(LoadOptions{ChildSectionDelimiter: ":"}, []byte(` [node] [node:biz1] [node:biz2] @@ -1405,7 +1405,7 @@ GITHUB = U;n;k;n;w;o;n t.Run("ShortCircuit", func(t *testing.T) { t.Run("load the first available configuration, ignore other configuration", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ShortCircuit: true}, minimalConf, []byte(`key1 = value1`)) + f, err := LoadSources(LoadOptions{ShortCircuit: true}, minimalConf, []byte(`key1 = value1`)) require.NotNil(t, f) require.NoError(t, err) var buf bytes.Buffer @@ -1420,13 +1420,13 @@ E-MAIL = u@gogs.io }) t.Run("return an error when fail to load", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ShortCircuit: true}, notFoundConf, minimalConf) + f, err := LoadSources(LoadOptions{ShortCircuit: true}, notFoundConf, minimalConf) assert.Nil(t, f) require.Error(t, err) }) t.Run("used with Loose to ignore errors that the file does not exist", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ShortCircuit: true, Loose: true}, notFoundConf, minimalConf) + f, err := LoadSources(LoadOptions{ShortCircuit: true, Loose: true}, notFoundConf, minimalConf) require.NotNil(t, f) require.NoError(t, err) var buf bytes.Buffer @@ -1441,7 +1441,7 @@ E-MAIL = u@gogs.io }) t.Run("ensure all sources are loaded without ShortCircuit", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ShortCircuit: false}, minimalConf, []byte(`key1 = value1`)) + f, err := LoadSources(LoadOptions{ShortCircuit: false}, minimalConf, []byte(`key1 = value1`)) require.NotNil(t, f) require.NoError(t, err) var buf bytes.Buffer @@ -1461,7 +1461,7 @@ E-MAIL = u@gogs.io func Test_KeyValueDelimiters(t *testing.T) { t.Run("custom key-value delimiters", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ + f, err := LoadSources(LoadOptions{ KeyValueDelimiters: "?!", }, []byte(` [section] @@ -1478,7 +1478,7 @@ key2!value2 func Test_PreserveSurroundedQuote(t *testing.T) { t.Run("preserve surrounded quote test", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ + f, err := LoadSources(LoadOptions{ PreserveSurroundedQuote: true, }, []byte(` [section] @@ -1493,7 +1493,7 @@ key2 = value2 }) t.Run("preserve surrounded quote test inverse test", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ + f, err := LoadSources(LoadOptions{ PreserveSurroundedQuote: false, }, []byte(` [section] @@ -1507,3 +1507,58 @@ key2 = value2 assert.Equal(t, "value2", f.Section("section").Key("key2").String()) }) } + +type testData struct { + Value1 string `ini:"value1"` + Value2 string `ini:"value2"` + Value3 string `ini:"value3"` +} + +func TestPythonMultiline(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("Skipping testing on Windows") + } + + path := filepath.Join("testdata", "multiline.ini") + f, err := LoadSources(LoadOptions{ + AllowPythonMultilineValues: true, + ReaderBufferSize: 64 * 1024, + }, path) + require.NoError(t, err) + require.NotNil(t, f) + assert.Len(t, f.Sections(), 1) + + defaultSection := f.Section("") + assert.NotNil(t, f.Section("")) + + var testData testData + err = defaultSection.MapTo(&testData) + require.NoError(t, err) + assert.Equal(t, "some text here\nsome more text here\n\nthere is an empty line above and below\n", testData.Value1) + assert.Equal(t, "there is an empty line above\nthat is not indented so it should not be part\nof the value", testData.Value2) + assert.Equal(t, `. + +Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Eu consequat ac felis donec et odio pellentesque diam volutpat. Mauris commodo quis imperdiet massa tincidunt nunc. Interdum velit euismod in pellentesque. Nisl condimentum id venenatis a condimentum vitae sapien pellentesque. Nascetur ridiculus mus mauris vitae. Posuere urna nec tincidunt praesent semper feugiat. Lorem donec massa sapien faucibus et molestie ac feugiat sed. Ipsum dolor sit amet consectetur adipiscing elit. Enim sed faucibus turpis in eu mi. A diam sollicitudin tempor id. Quam nulla porttitor massa id neque aliquam vestibulum morbi blandit. + +Lectus sit amet est placerat in egestas. At risus viverra adipiscing at in tellus integer. Tristique senectus et netus et malesuada fames ac. In hac habitasse platea dictumst. Purus in mollis nunc sed. Pellentesque sit amet porttitor eget dolor morbi. Elit at imperdiet dui accumsan sit amet nulla. Cursus in hac habitasse platea dictumst. Bibendum arcu vitae elementum curabitur. Faucibus ornare suspendisse sed nisi lacus. In vitae turpis massa sed. Libero nunc consequat interdum varius sit amet. Molestie a iaculis at erat pellentesque. + +Dui faucibus in ornare quam viverra orci sagittis eu. Purus in mollis nunc sed id semper. Sed arcu non odio euismod lacinia at. Quis commodo odio aenean sed adipiscing diam donec. Quisque id diam vel quam elementum pulvinar. Lorem ipsum dolor sit amet. Purus ut faucibus pulvinar elementum integer enim neque volutpat ac. Fermentum posuere urna nec tincidunt praesent semper feugiat nibh sed. Gravida rutrum quisque non tellus orci. Ipsum dolor sit amet consectetur adipiscing elit pellentesque habitant. Et sollicitudin ac orci phasellus egestas tellus rutrum tellus pellentesque. Eget gravida cum sociis natoque penatibus et magnis. Elementum eu facilisis sed odio morbi quis commodo. Mollis nunc sed id semper risus in hendrerit gravida rutrum. Lorem dolor sed viverra ipsum. + +Pellentesque adipiscing commodo elit at imperdiet dui accumsan sit amet. Justo eget magna fermentum iaculis eu non diam. Condimentum mattis pellentesque id nibh tortor id aliquet lectus. Tellus molestie nunc non blandit massa enim. Mauris ultrices eros in cursus turpis. Purus viverra accumsan in nisl nisi scelerisque. Quis lectus nulla at volutpat. Purus ut faucibus pulvinar elementum integer enim. In pellentesque massa placerat duis ultricies lacus sed turpis. Elit sed vulputate mi sit amet mauris commodo. Tellus elementum sagittis vitae et. Duis tristique sollicitudin nibh sit amet commodo nulla facilisi nullam. Lectus vestibulum mattis ullamcorper velit sed ullamcorper morbi tincidunt ornare. Libero id faucibus nisl tincidunt eget nullam. Mattis aliquam faucibus purus in massa tempor. Fames ac turpis egestas sed tempus urna. Gravida in fermentum et sollicitudin ac orci phasellus egestas. + +Blandit turpis cursus in hac habitasse. Sed id semper risus in. Amet porttitor eget dolor morbi non arcu. Rhoncus est pellentesque elit ullamcorper dignissim cras tincidunt. Ut morbi tincidunt augue interdum velit. Lorem mollis aliquam ut porttitor leo a. Nunc eget lorem dolor sed viverra. Scelerisque mauris pellentesque pulvinar pellentesque. Elit at imperdiet dui accumsan sit amet. Eget magna fermentum iaculis eu non diam phasellus vestibulum lorem. Laoreet non curabitur gravida arcu ac tortor dignissim. Tortor pretium viverra suspendisse potenti nullam ac tortor vitae purus. Lacus sed viverra tellus in hac habitasse platea dictumst vestibulum. Viverra adipiscing at in tellus. Duis at tellus at urna condimentum. Eget gravida cum sociis natoque penatibus et magnis dis parturient. Pharetra massa massa ultricies mi quis hendrerit. + +Mauris pellentesque pulvinar pellentesque habitant morbi tristique. Maecenas volutpat blandit aliquam etiam. Sed turpis tincidunt id aliquet. Eget duis at tellus at urna condimentum. Pellentesque habitant morbi tristique senectus et. Amet aliquam id diam maecenas. Volutpat est velit egestas dui id. Vulputate eu scelerisque felis imperdiet proin fermentum leo vel orci. Massa sed elementum tempus egestas sed sed risus pretium. Quam quisque id diam vel quam elementum pulvinar etiam non. Sapien faucibus et molestie ac. Ipsum dolor sit amet consectetur adipiscing. Viverra orci sagittis eu volutpat. Leo urna molestie at elementum. Commodo viverra maecenas accumsan lacus. Non sodales neque sodales ut etiam sit amet. Habitant morbi tristique senectus et netus et malesuada fames. Habitant morbi tristique senectus et netus et malesuada. Blandit aliquam etiam erat velit scelerisque in. Varius duis at consectetur lorem donec massa sapien faucibus et. + +Augue mauris augue neque gravida in. Odio ut sem nulla pharetra diam sit amet nisl suscipit. Nulla aliquet enim tortor at auctor urna nunc id. Morbi tristique senectus et netus et malesuada fames ac. Quam id leo in vitae turpis massa sed elementum tempus. Ipsum faucibus vitae aliquet nec ullamcorper sit amet risus nullam. Maecenas volutpat blandit aliquam etiam erat velit scelerisque in. Sagittis nisl rhoncus mattis rhoncus urna neque viverra justo. Massa tempor nec feugiat nisl pretium. Vulputate sapien nec sagittis aliquam malesuada bibendum arcu vitae elementum. Enim lobortis scelerisque fermentum dui faucibus in ornare. Faucibus ornare suspendisse sed nisi lacus. Morbi tristique senectus et netus et malesuada fames. Malesuada pellentesque elit eget gravida cum sociis natoque penatibus et. Dictum non consectetur a erat nam at. Leo urna molestie at elementum eu facilisis sed odio morbi. Quam id leo in vitae turpis massa. Neque egestas congue quisque egestas diam in arcu. Varius morbi enim nunc faucibus a pellentesque sit. Aliquet enim tortor at auctor urna. + +Elit scelerisque mauris pellentesque pulvinar pellentesque habitant morbi tristique. Luctus accumsan tortor posuere ac. Eu ultrices vitae auctor eu augue ut lectus arcu bibendum. Pretium nibh ipsum consequat nisl vel pretium lectus. Aliquam etiam erat velit scelerisque in dictum. Sem et tortor consequat id porta nibh venenatis cras sed. A scelerisque purus semper eget duis at tellus at urna. At auctor urna nunc id. Ornare quam viverra orci sagittis eu volutpat odio. Nisl purus in mollis nunc sed id semper. Ornare suspendisse sed nisi lacus sed. Consectetur lorem donec massa sapien faucibus et. Ipsum dolor sit amet consectetur adipiscing elit ut. Porta nibh venenatis cras sed. Dignissim diam quis enim lobortis scelerisque. Quam nulla porttitor massa id. Tellus molestie nunc non blandit massa. + +Malesuada fames ac turpis egestas. Suscipit tellus mauris a diam maecenas. Turpis in eu mi bibendum neque egestas. Venenatis tellus in metus vulputate eu scelerisque felis imperdiet. Quis imperdiet massa tincidunt nunc pulvinar sapien et. Urna duis convallis convallis tellus id. Velit egestas dui id ornare arcu odio. Consectetur purus ut faucibus pulvinar elementum integer enim neque. Aenean sed adipiscing diam donec adipiscing tristique. Tortor aliquam nulla facilisi cras fermentum odio eu. Diam in arcu cursus euismod quis viverra nibh cras. + +Id ornare arcu odio ut sem. Arcu dictum varius duis at consectetur lorem donec massa sapien. Proin libero nunc consequat interdum varius sit. Ut eu sem integer vitae justo. Vitae elementum curabitur vitae nunc. Diam quam nulla porttitor massa. Lectus mauris ultrices eros in cursus turpis massa tincidunt dui. Natoque penatibus et magnis dis parturient montes. Pellentesque habitant morbi tristique senectus et netus et malesuada fames. Libero nunc consequat interdum varius sit. Rhoncus dolor purus non enim praesent. Pellentesque sit amet porttitor eget. Nibh tortor id aliquet lectus proin nibh. Fermentum iaculis eu non diam phasellus vestibulum lorem sed. + +Eu feugiat pretium nibh ipsum consequat nisl vel pretium lectus. Habitant morbi tristique senectus et netus et malesuada fames ac. Urna condimentum mattis pellentesque id. Lorem sed risus ultricies tristique nulla aliquet enim tortor at. Ipsum dolor sit amet consectetur adipiscing elit. Convallis a cras semper auctor neque vitae tempus quam. A diam sollicitudin tempor id eu nisl nunc mi ipsum. Maecenas sed enim ut sem viverra aliquet eget. Massa enim nec dui nunc mattis enim. Nam aliquam sem et tortor consequat. Adipiscing commodo elit at imperdiet dui accumsan sit amet nulla. Nullam eget felis eget nunc lobortis. Mauris a diam maecenas sed enim ut sem viverra. Ornare massa eget egestas purus. In hac habitasse platea dictumst. Ut tortor pretium viverra suspendisse potenti nullam ac tortor. Nisl nunc mi ipsum faucibus. At varius vel pharetra vel. Mauris ultrices eros in cursus turpis massa tincidunt.`, + testData.Value3, + ) +} diff --git a/key_test.go b/key_test.go index 913d802..5a842ad 100644 --- a/key_test.go +++ b/key_test.go @@ -12,7 +12,7 @@ // License for the specific language governing permissions and limitations // under the License. -package ini_test +package ini import ( "bytes" @@ -24,13 +24,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "gopkg.in/ini.v1" ) func TestKey_AddShadow(t *testing.T) { t.Run("add shadow to a key", func(t *testing.T) { - f, err := ini.ShadowLoad([]byte(` + f, err := ShadowLoad([]byte(` [notes] -: note1`)) require.NoError(t, err) @@ -62,7 +60,7 @@ func TestKey_AddShadow(t *testing.T) { }) t.Run("allow duplicate shadowed values", func(t *testing.T) { - f := ini.Empty(ini.LoadOptions{ + f := Empty(LoadOptions{ AllowShadows: true, AllowDuplicateShadowValues: true, }) @@ -79,7 +77,7 @@ func TestKey_AddShadow(t *testing.T) { }) t.Run("shadow is not allowed", func(t *testing.T) { - f := ini.Empty() + f := Empty() require.NotNil(t, f) k, err := f.Section("").NewKey("NAME", "ini") @@ -156,7 +154,7 @@ func timesEqual(t *testing.T, values []time.Time, expected ...time.Time) { func TestKey_Helpers(t *testing.T) { t.Run("getting and setting values", func(t *testing.T) { - f, err := ini.Load(fullConf) + f, err := Load(fullConf) require.NoError(t, err) require.NotNil(t, f) @@ -213,7 +211,7 @@ func TestKey_Helpers(t *testing.T) { t.Run("get sections", func(t *testing.T) { sections := f.Sections() - for i, name := range []string{ini.DefaultSection, "author", "package", "package.sub", "features", "types", "array", "note", "comments", "string escapes", "advance"} { + for i, name := range []string{DefaultSection, "author", "package", "package.sub", "features", "types", "array", "note", "comments", "string escapes", "advance"} { assert.Equal(t, name, sections[i].Name()) } }) @@ -525,7 +523,7 @@ func TestKey_Helpers(t *testing.T) { func TestKey_StringsWithShadows(t *testing.T) { t.Run("get strings of shadows of a key", func(t *testing.T) { - f, err := ini.ShadowLoad([]byte("")) + f, err := ShadowLoad([]byte("")) require.NoError(t, err) require.NotNil(t, f) @@ -542,7 +540,7 @@ func TestKey_StringsWithShadows(t *testing.T) { func TestKey_SetValue(t *testing.T) { t.Run("set value of key", func(t *testing.T) { - f := ini.Empty() + f := Empty() require.NotNil(t, f) k, err := f.Section("").NewKey("NAME", "ini") @@ -557,7 +555,7 @@ func TestKey_SetValue(t *testing.T) { func TestKey_NestedValues(t *testing.T) { t.Run("read and write nested values", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{ + f, err := LoadSources(LoadOptions{ AllowNestedValues: true, }, []byte(` aws_access_key_id = foo @@ -589,7 +587,7 @@ s3 = func TestRecursiveValues(t *testing.T) { t.Run("recursive values should not reflect on same key", func(t *testing.T) { - f, err := ini.Load([]byte(` + f, err := Load([]byte(` NAME = ini expires = yes [package] @@ -603,7 +601,7 @@ expires = %(expires)s`)) }) t.Run("recursive value with no target found", func(t *testing.T) { - f, err := ini.Load([]byte(` + f, err := Load([]byte(` [foo] bar = %(missing)s `)) diff --git a/parser_test.go b/parser_test.go index 3462807..7016d67 100644 --- a/parser_test.go +++ b/parser_test.go @@ -12,21 +12,19 @@ // License for the specific language governing permissions and limitations // under the License. -package ini_test +package ini import ( "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "gopkg.in/ini.v1" ) func TestBOM(t *testing.T) { t.Run("test handling BOM", func(t *testing.T) { t.Run("UTF-8-BOM", func(t *testing.T) { - f, err := ini.Load("testdata/UTF-8-BOM.ini") + f, err := Load("testdata/UTF-8-BOM.ini") require.NoError(t, err) require.NotNil(t, f) @@ -34,7 +32,7 @@ func TestBOM(t *testing.T) { }) t.Run("UTF-16-LE-BOM", func(t *testing.T) { - f, err := ini.Load("testdata/UTF-16-LE-BOM.ini") + f, err := Load("testdata/UTF-16-LE-BOM.ini") require.NoError(t, err) require.NotNil(t, f) }) @@ -47,32 +45,32 @@ func TestBOM(t *testing.T) { func TestBadLoad(t *testing.T) { t.Run("load with bad data", func(t *testing.T) { t.Run("bad section name", func(t *testing.T) { - _, err := ini.Load([]byte("[]")) + _, err := Load([]byte("[]")) require.Error(t, err) - _, err = ini.Load([]byte("[")) + _, err = Load([]byte("[")) require.Error(t, err) }) t.Run("bad keys", func(t *testing.T) { - _, err := ini.Load([]byte(`"""name`)) + _, err := Load([]byte(`"""name`)) require.Error(t, err) - _, err = ini.Load([]byte(`"""name"""`)) + _, err = Load([]byte(`"""name"""`)) require.Error(t, err) - _, err = ini.Load([]byte(`""=1`)) + _, err = Load([]byte(`""=1`)) require.Error(t, err) - _, err = ini.Load([]byte(`=`)) + _, err = Load([]byte(`=`)) require.Error(t, err) - _, err = ini.Load([]byte(`name`)) + _, err = Load([]byte(`name`)) require.Error(t, err) }) t.Run("bad values", func(t *testing.T) { - _, err := ini.Load([]byte(`name="""Unknwon`)) + _, err := Load([]byte(`name="""Unknwon`)) require.Error(t, err) }) }) diff --git a/section_test.go b/section_test.go index 9cf3189..09ed366 100644 --- a/section_test.go +++ b/section_test.go @@ -12,20 +12,18 @@ // License for the specific language governing permissions and limitations // under the License. -package ini_test +package ini import ( "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "gopkg.in/ini.v1" ) func TestSection_SetBody(t *testing.T) { t.Run("set body of raw section", func(t *testing.T) { - f := ini.Empty() + f := Empty() require.NotNil(t, f) sec, err := f.NewRawSection("comments", `1111111111111111111000000000000000001110000 @@ -52,7 +50,7 @@ func TestSection_SetBody(t *testing.T) { func TestSection_NewKey(t *testing.T) { t.Run("create a new key", func(t *testing.T) { - f := ini.Empty() + f := Empty() require.NotNil(t, f) k, err := f.Section("").NewKey("NAME", "ini") @@ -77,7 +75,7 @@ func TestSection_NewKey(t *testing.T) { }) t.Run("create keys with same name and allow shadow", func(t *testing.T) { - f, err := ini.ShadowLoad([]byte("")) + f, err := ShadowLoad([]byte("")) require.NoError(t, err) require.NotNil(t, f) @@ -94,7 +92,7 @@ func TestSection_NewKey(t *testing.T) { func TestSection_NewBooleanKey(t *testing.T) { t.Run("create a new boolean key", func(t *testing.T) { - f := ini.Empty() + f := Empty() require.NotNil(t, f) k, err := f.Section("").NewBooleanKey("start-ssh-server") @@ -112,7 +110,7 @@ func TestSection_NewBooleanKey(t *testing.T) { func TestSection_GetKey(t *testing.T) { t.Run("get a key", func(t *testing.T) { - f := ini.Empty() + f := Empty() require.NotNil(t, f) k, err := f.Section("").NewKey("NAME", "ini") @@ -145,7 +143,7 @@ func TestSection_GetKey(t *testing.T) { func TestSection_HasKey(t *testing.T) { t.Run("check if a key exists", func(t *testing.T) { - f := ini.Empty() + f := Empty() require.NotNil(t, f) k, err := f.Section("").NewKey("NAME", "ini") @@ -161,7 +159,7 @@ func TestSection_HasKey(t *testing.T) { func TestSection_HasValue(t *testing.T) { t.Run("check if contains a value in any key", func(t *testing.T) { - f := ini.Empty() + f := Empty() require.NotNil(t, f) k, err := f.Section("").NewKey("NAME", "ini") @@ -175,7 +173,7 @@ func TestSection_HasValue(t *testing.T) { func TestSection_Key(t *testing.T) { t.Run("get a key", func(t *testing.T) { - f := ini.Empty() + f := Empty() require.NotNil(t, f) k, err := f.Section("").NewKey("NAME", "ini") @@ -207,7 +205,7 @@ func TestSection_Key(t *testing.T) { func TestSection_Keys(t *testing.T) { t.Run("get all keys in a section", func(t *testing.T) { - f := ini.Empty() + f := Empty() require.NotNil(t, f) k, err := f.Section("").NewKey("NAME", "ini") @@ -231,7 +229,7 @@ func TestSection_Keys(t *testing.T) { func TestSection_ParentKeys(t *testing.T) { t.Run("get all keys of parent sections", func(t *testing.T) { - f := ini.Empty() + f := Empty() require.NotNil(t, f) k, err := f.Section("package").NewKey("NAME", "ini") @@ -255,7 +253,7 @@ func TestSection_ParentKeys(t *testing.T) { func TestSection_KeyStrings(t *testing.T) { t.Run("get all key names in a section", func(t *testing.T) { - f := ini.Empty() + f := Empty() require.NotNil(t, f) k, err := f.Section("").NewKey("NAME", "ini") @@ -274,7 +272,7 @@ func TestSection_KeyStrings(t *testing.T) { func TestSection_KeyHash(t *testing.T) { t.Run("get clone of key hash", func(t *testing.T) { - f, err := ini.Load([]byte(` + f, err := Load([]byte(` key = one [log] name = app @@ -303,7 +301,7 @@ file = b.log func TestSection_DeleteKey(t *testing.T) { t.Run("delete a key", func(t *testing.T) { - f := ini.Empty() + f := Empty() require.NotNil(t, f) k, err := f.Section("").NewKey("NAME", "ini") diff --git a/struct_test.go b/struct_test.go index e2855c6..6bacaea 100644 --- a/struct_test.go +++ b/struct_test.go @@ -12,7 +12,7 @@ // License for the specific language governing permissions and limitations // under the License. -package ini_test +package ini import ( "bytes" @@ -23,8 +23,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "gopkg.in/ini.v1" ) type testNested struct { @@ -219,7 +217,7 @@ func Test_MapToStruct(t *testing.T) { t.Run("map to struct", func(t *testing.T) { t.Run("map file to struct", func(t *testing.T) { ts := new(testStruct) - assert.NoError(t, ini.MapTo(ts, []byte(confDataStruct))) + assert.NoError(t, MapTo(ts, []byte(confDataStruct))) assert.Equal(t, "Unknwon", ts.Name) assert.Equal(t, 21, ts.Age) @@ -278,7 +276,7 @@ func Test_MapToStruct(t *testing.T) { t.Run("map section to struct", func(t *testing.T) { foobar := new(fooBar) - f, err := ini.Load([]byte(confDataStruct)) + f, err := Load([]byte(confDataStruct)) require.NoError(t, err) assert.NoError(t, f.Section("foo.bar").MapTo(foobar)) @@ -287,7 +285,7 @@ func Test_MapToStruct(t *testing.T) { }) t.Run("map to non-pointer struct", func(t *testing.T) { - f, err := ini.Load([]byte(confDataStruct)) + f, err := Load([]byte(confDataStruct)) require.NoError(t, err) require.NotNil(t, f) @@ -295,7 +293,7 @@ func Test_MapToStruct(t *testing.T) { }) t.Run("map to unsupported type", func(t *testing.T) { - f, err := ini.Load([]byte(confDataStruct)) + f, err := Load([]byte(confDataStruct)) require.NoError(t, err) require.NotNil(t, f) @@ -312,13 +310,13 @@ func Test_MapToStruct(t *testing.T) { t.Run("map to omitempty field", func(t *testing.T) { ts := new(testStruct) - assert.NoError(t, ini.MapTo(ts, []byte(confDataStruct))) + assert.NoError(t, MapTo(ts, []byte(confDataStruct))) assert.Equal(t, true, ts.Omitted) }) t.Run("map with shadows", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{AllowShadows: true}, []byte(confDataStruct)) + f, err := LoadSources(LoadOptions{AllowShadows: true}, []byte(confDataStruct)) require.NoError(t, err) ts := new(testStruct) assert.NoError(t, f.MapTo(ts)) @@ -328,11 +326,11 @@ func Test_MapToStruct(t *testing.T) { }) t.Run("map from invalid data source", func(t *testing.T) { - assert.Error(t, ini.MapTo(&testStruct{}, "hi")) + assert.Error(t, MapTo(&testStruct{}, "hi")) }) t.Run("map to wrong types and gain default values", func(t *testing.T) { - f, err := ini.Load([]byte(invalidDataConfStruct)) + f, err := Load([]byte(invalidDataConfStruct)) require.NoError(t, err) ti, err := time.Parse(time.RFC3339, "1993-10-07T20:17:05Z") @@ -348,7 +346,7 @@ func Test_MapToStruct(t *testing.T) { }) t.Run("map to extended base", func(t *testing.T) { - f, err := ini.Load([]byte(confDataStruct)) + f, err := Load([]byte(confDataStruct)) require.NoError(t, err) require.NotNil(t, f) te := testExtend{} @@ -359,7 +357,7 @@ func Test_MapToStruct(t *testing.T) { }) t.Run("map to struct in strict mode", func(t *testing.T) { - f, err := ini.Load([]byte(` + f, err := Load([]byte(` name=bruce age=a30`)) require.NoError(t, err) @@ -374,7 +372,7 @@ age=a30`)) }) t.Run("map slice in strict mode", func(t *testing.T) { - f, err := ini.Load([]byte(` + f, err := Load([]byte(` names=alice, bruce`)) require.NoError(t, err) @@ -391,7 +389,7 @@ names=alice, bruce`)) func Test_MapToStructNonUniqueSections(t *testing.T) { t.Run("map to struct non unique", func(t *testing.T) { t.Run("map file to struct non unique", func(t *testing.T) { - f, err := ini.LoadSources(ini.LoadOptions{AllowNonUniqueSections: true}, []byte(confNonUniqueSectionDataStruct)) + f, err := LoadSources(LoadOptions{AllowNonUniqueSections: true}, []byte(confNonUniqueSectionDataStruct)) require.NoError(t, err) ts := new(testNonUniqueSectionsStruct) @@ -416,7 +414,7 @@ func Test_MapToStructNonUniqueSections(t *testing.T) { newPeer := new(testPeer) newPeerSlice := make([]testPeer, 0) - f, err := ini.LoadSources(ini.LoadOptions{AllowNonUniqueSections: true}, []byte(confNonUniqueSectionDataStruct)) + f, err := LoadSources(LoadOptions{AllowNonUniqueSections: true}, []byte(confNonUniqueSectionDataStruct)) require.NoError(t, err) // try only first one @@ -440,7 +438,7 @@ func Test_MapToStructNonUniqueSections(t *testing.T) { }) t.Run("map non unique sections with subsections to struct", func(t *testing.T) { - iniFile, err := ini.LoadSources(ini.LoadOptions{AllowNonUniqueSections: true}, strings.NewReader(` + iniFile, err := LoadSources(LoadOptions{AllowNonUniqueSections: true}, strings.NewReader(` [Section] FieldInSubSection = 1 FieldInSubSection2 = 2 @@ -525,8 +523,8 @@ func Test_ReflectFromStruct(t *testing.T) { []bool{true, false}, []int{}, }} - cfg := ini.Empty() - assert.NoError(t, ini.ReflectFrom(cfg, a)) + cfg := Empty() + assert.NoError(t, ReflectFrom(cfg, a)) var buf bytes.Buffer _, err = cfg.WriteTo(&buf) @@ -558,11 +556,11 @@ None = ) t.Run("reflect from non-point struct", func(t *testing.T) { - assert.Error(t, ini.ReflectFrom(cfg, Author{})) + assert.Error(t, ReflectFrom(cfg, Author{})) }) t.Run("reflect from struct with omitempty", func(t *testing.T) { - cfg := ini.Empty() + cfg := Empty() type SpecialStruct struct { FirstName string `ini:"first_name"` LastName string `ini:"last_name,omitempty"` @@ -583,7 +581,7 @@ None = NotEmpty: 9, } - assert.NoError(t, ini.ReflectFrom(cfg, special)) + assert.NoError(t, ReflectFrom(cfg, special)) var buf bytes.Buffer _, err = cfg.WriteTo(&buf) @@ -597,7 +595,7 @@ omitempty = 9 }) t.Run("reflect from struct with non-anonymous structure pointer", func(t *testing.T) { - cfg := ini.Empty() + cfg := Empty() type Rpc struct { Enable bool `ini:"enable"` Type string `ini:"type"` @@ -655,11 +653,11 @@ func Test_ReflectFromStructNonUniqueSections(t *testing.T) { }, } - cfg := ini.Empty(ini.LoadOptions{ + cfg := Empty(LoadOptions{ AllowNonUniqueSections: true, }) - assert.NoError(t, ini.ReflectFrom(cfg, nonUnique)) + assert.NoError(t, ReflectFrom(cfg, nonUnique)) var buf bytes.Buffer _, err := cfg.WriteTo(&buf) @@ -739,7 +737,7 @@ func TestMapToAndReflectFromStructWithShadows(t *testing.T) { Paths []string `ini:"path,omitempty,allowshadow"` } - cfg, err := ini.LoadSources(ini.LoadOptions{ + cfg, err := LoadSources(LoadOptions{ AllowShadows: true, }, []byte(` [include] @@ -767,7 +765,7 @@ path = /tmp/gpm-profiles/test1.profile ) t.Run("reflect from struct with shadows", func(t *testing.T) { - cfg := ini.Empty(ini.LoadOptions{ + cfg := Empty(LoadOptions{ AllowShadows: true, }) type ShadowStruct struct { @@ -800,7 +798,7 @@ path = /tmp/gpm-profiles/test1.profile None: []int{}, } - assert.NoError(t, ini.ReflectFrom(cfg, shadow)) + assert.NoError(t, ReflectFrom(cfg, shadow)) var buf bytes.Buffer _, err := cfg.WriteTo(&buf) @@ -839,13 +837,13 @@ type testMapper struct { func Test_NameGetter(t *testing.T) { t.Run("test name mappers", func(t *testing.T) { - assert.NoError(t, ini.MapToWithMapper(&testMapper{}, ini.TitleUnderscore, []byte("packag_name=ini"))) + assert.NoError(t, MapToWithMapper(&testMapper{}, TitleUnderscore, []byte("packag_name=ini"))) - cfg, err := ini.Load([]byte("PACKAGE_NAME=ini")) + cfg, err := Load([]byte("PACKAGE_NAME=ini")) require.NoError(t, err) require.NotNil(t, cfg) - cfg.NameMapper = ini.SnackCase + cfg.NameMapper = SnackCase tg := new(testMapper) assert.NoError(t, cfg.MapTo(tg)) assert.Equal(t, "ini", tg.PackageName) @@ -859,7 +857,7 @@ type testDurationStruct struct { func Test_Duration(t *testing.T) { t.Run("duration less than 16m50s", func(t *testing.T) { ds := new(testDurationStruct) - assert.NoError(t, ini.MapTo(ds, []byte("Duration=16m49s"))) + assert.NoError(t, MapTo(ds, []byte("Duration=16m49s"))) dur, err := time.ParseDuration("16m49s") require.NoError(t, err) @@ -874,7 +872,7 @@ type Employer struct { type Employers []*Employer -func (es Employers) ReflectINIStruct(f *ini.File) error { +func (es Employers) ReflectINIStruct(f *File) error { for _, e := range es { f.Section(e.Name).Key("Title").SetValue(e.Title) } @@ -901,7 +899,7 @@ func Test_StructReflector(t *testing.T) { }, } - f := ini.Empty() + f := Empty() assert.NoError(t, f.ReflectFrom(p)) var buf bytes.Buffer