*: refactor constants to use camelcase

This commit is contained in:
Unknwon
2019-02-17 14:54:15 -05:00
parent 7c1c4f765b
commit ece0e89bb0
8 changed files with 49 additions and 47 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ import (
)
func newTestFile(block bool) *ini.File {
c, _ := ini.Load([]byte(_CONF_DATA))
c, _ := ini.Load([]byte(confData))
c.BlockMode = block
return c
}
+5 -5
View File
@@ -68,7 +68,7 @@ func Empty() *File {
func (f *File) NewSection(name string) (*Section, error) {
if len(name) == 0 {
return nil, errors.New("error creating new section: empty section name")
} else if f.options.Insensitive && name != DEFAULT_SECTION {
} else if f.options.Insensitive && name != DefaultSection {
name = strings.ToLower(name)
}
@@ -111,7 +111,7 @@ func (f *File) NewSections(names ...string) (err error) {
// GetSection returns section by given name.
func (f *File) GetSection(name string) (*Section, error) {
if len(name) == 0 {
name = DEFAULT_SECTION
name = DefaultSection
}
if f.options.Insensitive {
name = strings.ToLower(name)
@@ -175,7 +175,7 @@ func (f *File) DeleteSection(name string) {
}
if len(name) == 0 {
name = DEFAULT_SECTION
name = DefaultSection
}
for i, s := range f.sectionList {
@@ -306,7 +306,7 @@ func (f *File) writeToBuffer(indent string) (*bytes.Buffer, error) {
for _, kname := range sec.keyList {
key := sec.Key(kname)
if len(key.Comment) > 0 {
if len(indent) > 0 && sname != DEFAULT_SECTION {
if len(indent) > 0 && sname != DefaultSection {
buf.WriteString(indent)
}
@@ -325,7 +325,7 @@ func (f *File) writeToBuffer(indent string) (*bytes.Buffer, error) {
}
}
if len(indent) > 0 && sname != DEFAULT_SECTION {
if len(indent) > 0 && sname != DefaultSection {
buf.WriteString(indent)
}
+16 -16
View File
@@ -46,7 +46,7 @@ func TestFile_NewSection(t *testing.T) {
So(sec, ShouldNotBeNil)
So(sec.Name(), ShouldEqual, "author")
So(f.SectionStrings(), ShouldResemble, []string{ini.DEFAULT_SECTION, "author"})
So(f.SectionStrings(), ShouldResemble, []string{ini.DefaultSection, "author"})
Convey("With duplicated name", func() {
sec, err := f.NewSection("author")
@@ -54,7 +54,7 @@ func TestFile_NewSection(t *testing.T) {
So(sec, ShouldNotBeNil)
// Does nothing if section already exists
So(f.SectionStrings(), ShouldResemble, []string{ini.DEFAULT_SECTION, "author"})
So(f.SectionStrings(), ShouldResemble, []string{ini.DefaultSection, "author"})
})
Convey("With empty string", func() {
@@ -75,7 +75,7 @@ func TestFile_NewRawSection(t *testing.T) {
So(sec, ShouldNotBeNil)
So(sec.Name(), ShouldEqual, "comments")
So(f.SectionStrings(), ShouldResemble, []string{ini.DEFAULT_SECTION, "comments"})
So(f.SectionStrings(), ShouldResemble, []string{ini.DefaultSection, "comments"})
So(f.Section("comments").Body(), ShouldEqual, `1111111111111111111000000000000000001110000
111111111111111111100000000000111000000000`)
@@ -83,7 +83,7 @@ func TestFile_NewRawSection(t *testing.T) {
sec, err := f.NewRawSection("comments", `1111111111111111111000000000000000001110000`)
So(err, ShouldBeNil)
So(sec, ShouldNotBeNil)
So(f.SectionStrings(), ShouldResemble, []string{ini.DEFAULT_SECTION, "comments"})
So(f.SectionStrings(), ShouldResemble, []string{ini.DefaultSection, "comments"})
// Overwrite previous existed section
So(f.Section("comments").Body(), ShouldEqual, `1111111111111111111000000000000000001110000`)
@@ -102,13 +102,13 @@ func TestFile_NewSections(t *testing.T) {
So(f, ShouldNotBeNil)
So(f.NewSections("package", "author"), ShouldBeNil)
So(f.SectionStrings(), ShouldResemble, []string{ini.DEFAULT_SECTION, "package", "author"})
So(f.SectionStrings(), ShouldResemble, []string{ini.DefaultSection, "package", "author"})
Convey("With duplicated name", func() {
So(f.NewSections("author", "features"), ShouldBeNil)
// Ignore section already exists
So(f.SectionStrings(), ShouldResemble, []string{ini.DEFAULT_SECTION, "package", "author", "features"})
So(f.SectionStrings(), ShouldResemble, []string{ini.DefaultSection, "package", "author", "features"})
})
Convey("With empty string", func() {
@@ -119,7 +119,7 @@ func TestFile_NewSections(t *testing.T) {
func TestFile_GetSection(t *testing.T) {
Convey("Get a section", t, func() {
f, err := ini.Load(_FULL_CONF)
f, err := ini.Load(fullConf)
So(err, ShouldBeNil)
So(f, ShouldNotBeNil)
@@ -137,7 +137,7 @@ func TestFile_GetSection(t *testing.T) {
func TestFile_Section(t *testing.T) {
Convey("Get a section", t, func() {
f, err := ini.Load(_FULL_CONF)
f, err := ini.Load(fullConf)
So(err, ShouldBeNil)
So(f, ShouldNotBeNil)
@@ -167,12 +167,12 @@ VERSION = v1`))
func TestFile_Sections(t *testing.T) {
Convey("Get all sections", t, func() {
f, err := ini.Load(_FULL_CONF)
f, err := ini.Load(fullConf)
So(err, ShouldBeNil)
So(f, ShouldNotBeNil)
secs := f.Sections()
names := []string{ini.DEFAULT_SECTION, "author", "package", "package.sub", "features", "types", "array", "note", "comments", "string escapes", "advance"}
names := []string{ini.DefaultSection, "author", "package", "package.sub", "features", "types", "array", "note", "comments", "string escapes", "advance"}
So(len(secs), ShouldEqual, len(names))
for i, name := range names {
So(secs[i].Name(), ShouldEqual, name)
@@ -203,11 +203,11 @@ func TestFile_ChildSections(t *testing.T) {
func TestFile_SectionStrings(t *testing.T) {
Convey("Get all section names", t, func() {
f, err := ini.Load(_FULL_CONF)
f, err := ini.Load(fullConf)
So(err, ShouldBeNil)
So(f, ShouldNotBeNil)
So(f.SectionStrings(), ShouldResemble, []string{ini.DEFAULT_SECTION, "author", "package", "package.sub", "features", "types", "array", "note", "comments", "string escapes", "advance"})
So(f.SectionStrings(), ShouldResemble, []string{ini.DefaultSection, "author", "package", "package.sub", "features", "types", "array", "note", "comments", "string escapes", "advance"})
})
}
@@ -228,20 +228,20 @@ func TestFile_Append(t *testing.T) {
f := ini.Empty()
So(f, ShouldNotBeNil)
So(f.Append(_MINIMAL_CONF, []byte(`
So(f.Append(minimalConf, []byte(`
[author]
NAME = Unknwon`)), ShouldBeNil)
Convey("With bad input", func() {
So(f.Append(123), ShouldNotBeNil)
So(f.Append(_MINIMAL_CONF, 123), ShouldNotBeNil)
So(f.Append(minimalConf, 123), ShouldNotBeNil)
})
})
}
func TestFile_WriteTo(t *testing.T) {
Convey("Write content to somewhere", t, func() {
f, err := ini.Load(_FULL_CONF)
f, err := ini.Load(fullConf)
So(err, ShouldBeNil)
So(f, ShouldNotBeNil)
@@ -297,7 +297,7 @@ test =
func TestFile_SaveTo(t *testing.T) {
Convey("Write content to somewhere", t, func() {
f, err := ini.Load(_FULL_CONF)
f, err := ini.Load(fullConf)
So(err, ShouldBeNil)
So(f, ShouldNotBeNil)
+6 -4
View File
@@ -30,16 +30,18 @@ import (
const (
// Name for default section. You can use this constant or the string literal.
// In most of cases, an empty string is all you need to access the section.
DEFAULT_SECTION = "DEFAULT"
DefaultSection = "DEFAULT"
// Deprecated: Use "DefaultSection" instead.
DEFAULT_SECTION = DefaultSection
// Maximum allowed depth when recursively substituing variable names.
_DEPTH_VALUES = 99
_VERSION = "1.42.0"
depthValues = 99
version = "1.42.1"
)
// Version returns current package version literal.
func Version() string {
return _VERSION
return version
}
var (
+1 -1
View File
@@ -22,7 +22,7 @@ import (
func Test_Version(t *testing.T) {
Convey("Get version", t, func() {
So(Version(), ShouldEqual, _VERSION)
So(Version(), ShouldEqual, version)
})
}
+17 -17
View File
@@ -25,7 +25,7 @@ import (
)
const (
_CONF_DATA = `
confData = `
; Package name
NAME = ini
; Package version
@@ -43,9 +43,9 @@ const (
Coding addict.
Good man.
""" # Succeeding comment`
_MINIMAL_CONF = "testdata/minimal.ini"
_FULL_CONF = "testdata/full.ini"
_NOT_FOUND_CONF = "testdata/404.ini"
minimalConf = "testdata/minimal.ini"
fullConf = "testdata/full.ini"
notFoundConf = "testdata/404.ini"
)
var update = flag.Bool("update", false, "Update .golden files")
@@ -78,7 +78,7 @@ NAME = Unknwon
Convey("Load from bad data sources", t, func() {
Convey("Invalid input", func() {
_, err := ini.Load(_NOT_FOUND_CONF)
_, err := ini.Load(notFoundConf)
So(err, ShouldNotBeNil)
})
@@ -229,12 +229,12 @@ long_rsa_private_key = -----BEGIN RSA PRIVATE KEY-----
func TestLooseLoad(t *testing.T) {
Convey("Load from data sources with option `Loose` true", t, func() {
f, err := ini.LoadSources(ini.LoadOptions{Loose: true}, _NOT_FOUND_CONF, _MINIMAL_CONF)
f, err := ini.LoadSources(ini.LoadOptions{Loose: true}, notFoundConf, minimalConf)
So(err, ShouldBeNil)
So(f, ShouldNotBeNil)
Convey("Inverse case", func() {
_, err = ini.Load(_NOT_FOUND_CONF)
_, err = ini.Load(notFoundConf)
So(err, ShouldNotBeNil)
})
})
@@ -242,7 +242,7 @@ func TestLooseLoad(t *testing.T) {
func TestInsensitiveLoad(t *testing.T) {
Convey("Insensitive to section and key names", t, func() {
f, err := ini.InsensitiveLoad(_MINIMAL_CONF)
f, err := ini.InsensitiveLoad(minimalConf)
So(err, ShouldBeNil)
So(f, ShouldNotBeNil)
@@ -259,7 +259,7 @@ e-mail = u@gogs.io
})
Convey("Inverse case", func() {
f, err := ini.Load(_MINIMAL_CONF)
f, err := ini.Load(minimalConf)
So(err, ShouldBeNil)
So(f, ShouldNotBeNil)
@@ -272,18 +272,18 @@ func TestLoadSources(t *testing.T) {
Convey("Load from data sources with options", t, func() {
Convey("with true `AllowPythonMultilineValues`", func() {
Convey("Ignore nonexistent files", func() {
f, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: true, Loose: true}, _NOT_FOUND_CONF, _MINIMAL_CONF)
f, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: true, Loose: true}, notFoundConf, minimalConf)
So(err, ShouldBeNil)
So(f, ShouldNotBeNil)
Convey("Inverse case", func() {
_, err = ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: true}, _NOT_FOUND_CONF)
_, err = ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: true}, notFoundConf)
So(err, ShouldNotBeNil)
})
})
Convey("Insensitive to section and key names", func() {
f, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: true, Insensitive: true}, _MINIMAL_CONF)
f, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: true, Insensitive: true}, minimalConf)
So(err, ShouldBeNil)
So(f, ShouldNotBeNil)
@@ -300,7 +300,7 @@ e-mail = u@gogs.io
})
Convey("Inverse case", func() {
f, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: true}, _MINIMAL_CONF)
f, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: true}, minimalConf)
So(err, ShouldBeNil)
So(f, ShouldNotBeNil)
@@ -817,18 +817,18 @@ GITHUB = U;n;k;n;w;o;n
Convey("with false `AllowPythonMultilineValues`", func() {
Convey("Ignore nonexistent files", func() {
f, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: false, Loose: true}, _NOT_FOUND_CONF, _MINIMAL_CONF)
f, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: false, Loose: true}, notFoundConf, minimalConf)
So(err, ShouldBeNil)
So(f, ShouldNotBeNil)
Convey("Inverse case", func() {
_, err = ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: false}, _NOT_FOUND_CONF)
_, err = ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: false}, notFoundConf)
So(err, ShouldNotBeNil)
})
})
Convey("Insensitive to section and key names", func() {
f, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: false, Insensitive: true}, _MINIMAL_CONF)
f, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: false, Insensitive: true}, minimalConf)
So(err, ShouldBeNil)
So(f, ShouldNotBeNil)
@@ -845,7 +845,7 @@ e-mail = u@gogs.io
})
Convey("Inverse case", func() {
f, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: false}, _MINIMAL_CONF)
f, err := ini.LoadSources(ini.LoadOptions{AllowPythonMultilineValues: false}, minimalConf)
So(err, ShouldBeNil)
So(f, ShouldNotBeNil)
+1 -1
View File
@@ -126,7 +126,7 @@ func (k *Key) transformValue(val string) string {
if !strings.Contains(val, "%") {
return val
}
for i := 0; i < _DEPTH_VALUES; i++ {
for i := 0; i < depthValues; i++ {
vr := varPattern.FindString(val)
if len(vr) == 0 {
break
+2 -2
View File
@@ -109,7 +109,7 @@ func timesEqual(values []time.Time, expected ...time.Time) {
func TestKey_Helpers(t *testing.T) {
Convey("Getting and setting values", t, func() {
f, err := ini.Load(_FULL_CONF)
f, err := ini.Load(fullConf)
So(err, ShouldBeNil)
So(f, ShouldNotBeNil)
@@ -166,7 +166,7 @@ func TestKey_Helpers(t *testing.T) {
Convey("Get sections", func() {
sections := f.Sections()
for i, name := range []string{ini.DEFAULT_SECTION, "author", "package", "package.sub", "features", "types", "array", "note", "comments", "string escapes", "advance"} {
for i, name := range []string{ini.DefaultSection, "author", "package", "package.sub", "features", "types", "array", "note", "comments", "string escapes", "advance"} {
So(sections[i].Name(), ShouldEqual, name)
}
})