diff options
| author | Shulhan <ms@kilabit.info> | 2019-05-25 06:37:31 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2019-05-25 07:10:38 +0700 |
| commit | 9bc7afd4e748627d28f267cbebb5d19a92a7c407 (patch) | |
| tree | 56f7683756fac210f3084470b85da29beb4a32ad | |
| parent | 0f6c9178711cc9a494a3cd5792d3d4a37c94b278 (diff) | |
| download | pakakeh.go-9bc7afd4e748627d28f267cbebb5d19a92a7c407.tar.xz | |
ini: rename varModeXXX to lineModeXXX
This is the second part of refactoring to provide clean and readable
code.
| -rw-r--r-- | lib/ini/ini.go | 18 | ||||
| -rw-r--r-- | lib/ini/ini_test.go | 4 | ||||
| -rw-r--r-- | lib/ini/linemode.go | 17 | ||||
| -rw-r--r-- | lib/ini/reader.go | 42 | ||||
| -rw-r--r-- | lib/ini/reader_test.go | 44 | ||||
| -rw-r--r-- | lib/ini/section.go | 14 | ||||
| -rw-r--r-- | lib/ini/section_test.go | 64 | ||||
| -rw-r--r-- | lib/ini/variable.go | 38 | ||||
| -rw-r--r-- | lib/ini/variable_test.go | 30 |
9 files changed, 138 insertions, 133 deletions
diff --git a/lib/ini/ini.go b/lib/ini/ini.go index fcf49fe0..95808392 100644 --- a/lib/ini/ini.go +++ b/lib/ini/ini.go @@ -54,7 +54,7 @@ func (in *Ini) addSection(sec *section) { if sec == nil { return } - if sec.mode != varModeEmpty && len(sec.name) == 0 { + if sec.mode != lineModeEmpty && len(sec.name) == 0 { return } @@ -91,10 +91,10 @@ func (in *Ini) AsMap() (out map[string][]string) { for y := 0; y < len(sec.vars); y++ { v := sec.vars[y] - if v.mode == varModeEmpty { + if v.mode == lineModeEmpty { continue } - if v.mode&varModeSection > 0 || v.mode&varModeSubsection > 0 { + if v.mode&lineModeSection > 0 || v.mode&lineModeSubsection > 0 { continue } @@ -164,7 +164,7 @@ func (in *Ini) Gets(section, subsection, key string) (out []string) { section = strings.ToLower(section) for _, sec := range in.secs { - if sec.mode&varModeSection == 0 { + if sec.mode&lineModeSection == 0 { continue } if sec.nameLower != section { @@ -191,20 +191,20 @@ func (in *Ini) Prune() { newSecs := make([]*section, 0, len(in.secs)) for _, sec := range in.secs { - if sec.mode == varModeEmpty { + if sec.mode == lineModeEmpty { continue } newSec := §ion{ - mode: varModeSection, + mode: lineModeSection, name: sec.name, nameLower: sec.nameLower, } if len(sec.sub) > 0 { - newSec.mode |= varModeSubsection + newSec.mode |= lineModeSubsection newSec.sub = sec.sub } for _, v := range sec.vars { - if v.mode == varModeEmpty || v.mode == varModeComment { + if v.mode == lineModeEmpty || v.mode == lineModeComment { continue } @@ -233,7 +233,7 @@ func mergeSection(secs []*section, newSec *section) []*section { continue } for _, v := range newSec.vars { - if v.mode == varModeEmpty || v.mode == varModeComment { + if v.mode == lineModeEmpty || v.mode == lineModeComment { continue } secs[x].addUniqValue(v.keyLower, v.value) diff --git a/lib/ini/ini_test.go b/lib/ini/ini_test.go index ef35059d..803f67c7 100644 --- a/lib/ini/ini_test.go +++ b/lib/ini/ini_test.go @@ -110,13 +110,13 @@ func TestAddSection(t *testing.T) { }, { desc: "With valid section", sec: §ion{ - mode: varModeSection, + mode: lineModeSection, name: "Test", nameLower: "test", }, expIni: &Ini{ secs: []*section{{ - mode: varModeSection, + mode: lineModeSection, name: "Test", nameLower: "test", }}, diff --git a/lib/ini/linemode.go b/lib/ini/linemode.go new file mode 100644 index 00000000..68887a19 --- /dev/null +++ b/lib/ini/linemode.go @@ -0,0 +1,17 @@ +// Copyright 2018, Shulhan <ms@kilabit.info>. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ini + +type lineMode uint + +const ( + lineModeEmpty lineMode = 0 + lineModeComment lineMode = 1 + lineModeSection lineMode = 2 + lineModeSubsection lineMode = 4 + lineModeSingle lineMode = 8 + lineModeValue lineMode = 16 + lineModeMulti lineMode = 32 +) diff --git a/lib/ini/reader.go b/lib/ini/reader.go index 30526ee9..1b7af049 100644 --- a/lib/ini/reader.go +++ b/lib/ini/reader.go @@ -78,10 +78,10 @@ func (reader *reader) reset(src []byte) { reader.r = 0 reader.lineNum = 0 reader._var = &variable{ - mode: varModeEmpty, + mode: lineModeEmpty, } reader.sec = §ion{ - mode: varModeEmpty, + mode: lineModeEmpty, } reader.buf.Reset() reader.bufComment.Reset() @@ -134,10 +134,10 @@ func (reader *reader) Parse(src []byte) (in *Ini, err error) { reader._var.lineNum = reader.lineNum - if reader._var.mode&varModeSingle == varModeSingle || - reader._var.mode&varModeValue == varModeValue || - reader._var.mode&varModeMulti == varModeMulti { - if reader.sec.mode == varModeEmpty { + if reader._var.mode&lineModeSingle == lineModeSingle || + reader._var.mode&lineModeValue == lineModeValue || + reader._var.mode&lineModeMulti == lineModeMulti { + if reader.sec.mode == lineModeEmpty { err = fmt.Errorf(errVarNoSection, reader.lineNum, reader.filename) @@ -145,8 +145,8 @@ func (reader *reader) Parse(src []byte) (in *Ini, err error) { } } - if reader._var.mode&varModeSection == varModeSection || - reader._var.mode&varModeSubsection == varModeSubsection { + if reader._var.mode&lineModeSection == lineModeSection || + reader._var.mode&lineModeSubsection == lineModeSubsection { in.addSection(reader.sec) @@ -160,7 +160,7 @@ func (reader *reader) Parse(src []byte) (in *Ini, err error) { } reader._var = &variable{ - mode: varModeEmpty, + mode: lineModeEmpty, } continue } @@ -168,11 +168,11 @@ func (reader *reader) Parse(src []byte) (in *Ini, err error) { reader.sec.addVariable(reader._var) reader._var = &variable{ - mode: varModeEmpty, + mode: lineModeEmpty, } } - if reader._var.mode != varModeEmpty { + if reader._var.mode != lineModeEmpty { if debug.Value >= 1 { fmt.Println(reader._var) } @@ -224,7 +224,7 @@ func (reader *reader) parse() (err error) { func (reader *reader) parseComment() (err error) { reader.bufComment.Reset() - reader._var.mode |= varModeComment + reader._var.mode |= lineModeComment reader.bufFormat.Write([]byte{'%', 's'}) @@ -259,7 +259,7 @@ func (reader *reader) parseSectionHeader() (err error) { } reader.bufFormat.WriteByte(tokSecStart) - reader._var.mode = varModeSection + reader._var.mode = lineModeSection reader.r, _, err = reader.br.ReadRune() if err != nil { @@ -308,7 +308,7 @@ func (reader *reader) parseSectionHeader() (err error) { func (reader *reader) parseSubsection() (err error) { reader.buf.Reset() - reader._var.mode |= varModeSubsection + reader._var.mode |= lineModeSubsection // (0) for { @@ -430,7 +430,7 @@ func (reader *reader) parseVariable() (err error) { if reader.r == tokHash || reader.r == tokSemiColon { _ = reader.br.UnreadRune() - reader._var.mode = varModeSingle + reader._var.mode = lineModeSingle reader._var.key = reader.buf.String() reader._var.value = varValueTrue @@ -439,7 +439,7 @@ func (reader *reader) parseVariable() (err error) { if unicode.IsSpace(reader.r) { reader.bufFormat.WriteRune(reader.r) - reader._var.mode = varModeSingle + reader._var.mode = lineModeSingle reader._var.key = reader.buf.String() return reader.parsePossibleValue() @@ -447,7 +447,7 @@ func (reader *reader) parseVariable() (err error) { if reader.r == tokEqual { reader.bufFormat.WriteRune(reader.r) - reader._var.mode = varModeSingle + reader._var.mode = lineModeSingle reader._var.key = reader.buf.String() return reader.parseVarValue() @@ -455,7 +455,7 @@ func (reader *reader) parseVariable() (err error) { return errVarNameInvalid } - reader._var.mode = varModeSingle + reader._var.mode = lineModeSingle reader._var.format = reader.bufFormat.String() reader._var.key = reader.buf.String() reader._var.value = varValueTrue @@ -493,7 +493,7 @@ func (reader *reader) parsePossibleValue() (err error) { return errVarNameInvalid } - reader._var.mode = varModeSingle + reader._var.mode = lineModeSingle reader._var.format = reader.bufFormat.String() reader._var.value = varValueTrue @@ -536,7 +536,7 @@ func (reader *reader) parseVarValue() (err error) { break } - reader._var.mode = varModeValue + reader._var.mode = lineModeValue _ = reader.br.UnreadByte() var ( @@ -552,7 +552,7 @@ func (reader *reader) parseVarValue() (err error) { if esc { if reader.b == tokNewLine { - reader._var.mode = varModeMulti + reader._var.mode = lineModeMulti reader.valueCommit(true) diff --git a/lib/ini/reader_test.go b/lib/ini/reader_test.go index 6ad7a5be..43dc5c21 100644 --- a/lib/ini/reader_test.go +++ b/lib/ini/reader_test.go @@ -16,7 +16,7 @@ func TestParseSectionHeader(t *testing.T) { desc string in string expErr error - expMode varMode + expMode lineMode expFormat string expSecName string expSubName string @@ -69,14 +69,14 @@ func TestParseSectionHeader(t *testing.T) { desc: "With valid name", in: `[section-.]`, expErr: io.EOF, - expMode: varModeSection, + expMode: lineModeSection, expSecName: "section-.", expFormat: "[%s]", }, { desc: "With valid name and comment", in: `[section-.] ; a comment`, expErr: io.EOF, - expMode: varModeSection | varModeComment, + expMode: lineModeSection | lineModeComment, expSecName: "section-.", expFormat: "[%s] %s", expComment: "; a comment", @@ -84,7 +84,7 @@ func TestParseSectionHeader(t *testing.T) { desc: "With valid name and sub", in: `[section-. "su\bsec\tio\n"]`, expErr: io.EOF, - expMode: varModeSection | varModeSubsection, + expMode: lineModeSection | lineModeSubsection, expSecName: "section-.", expSubName: "subsection", expFormat: `[%s "%s"]`, @@ -92,7 +92,7 @@ func TestParseSectionHeader(t *testing.T) { desc: "With valid name, sub, and comment", in: `[section-. "su\bsec\tio\n"] # comment`, expErr: io.EOF, - expMode: varModeSection | varModeSubsection | varModeComment, + expMode: lineModeSection | lineModeSubsection | lineModeComment, expSecName: "section-.", expSubName: "subsection", expFormat: `[%s "%s"] %s`, @@ -128,7 +128,7 @@ func TestParseSubsection(t *testing.T) { desc string in string expErr error - expMode varMode + expMode lineMode expFormat string expSub string expComment string @@ -143,14 +143,14 @@ func TestParseSubsection(t *testing.T) { desc: "With leading space", in: `" "]`, expErr: io.EOF, - expMode: varModeSubsection, + expMode: lineModeSubsection, expFormat: `"%s"]`, expSub: ` `, }, { desc: "With valid subsection", in: `"subsection\""]`, expErr: io.EOF, - expMode: varModeSubsection, + expMode: lineModeSubsection, expFormat: `"%s"]`, expSub: `subsection"`, }} @@ -182,7 +182,7 @@ func TestParseVariable(t *testing.T) { desc string in []byte expErr error - expMode varMode + expMode lineMode expFormat string expComment string expKey string @@ -202,7 +202,7 @@ func TestParseVariable(t *testing.T) { desc: "Digit at end", in: []byte("name0"), expErr: io.EOF, - expMode: varModeSingle, + expMode: lineModeSingle, expFormat: "%s", expKey: "name0", expValue: varValueTrue, @@ -210,7 +210,7 @@ func TestParseVariable(t *testing.T) { desc: "Digit at middle", in: []byte("na0me"), expErr: io.EOF, - expMode: varModeSingle, + expMode: lineModeSingle, expFormat: "%s", expKey: "na0me", expValue: varValueTrue, @@ -222,7 +222,7 @@ func TestParseVariable(t *testing.T) { desc: "Hyphen at end", in: []byte("name-"), expErr: io.EOF, - expMode: varModeSingle, + expMode: lineModeSingle, expFormat: "%s", expKey: "name-", expValue: varValueTrue, @@ -230,7 +230,7 @@ func TestParseVariable(t *testing.T) { desc: "hyphen at middle", in: []byte("na-me"), expErr: io.EOF, - expMode: varModeSingle, + expMode: lineModeSingle, expFormat: "%s", expKey: "na-me", expValue: varValueTrue, @@ -254,7 +254,7 @@ func TestParseVariable(t *testing.T) { desc: "With comment #1", in: []byte(`name; comment`), expErr: io.EOF, - expMode: varModeSingle | varModeComment, + expMode: lineModeSingle | lineModeComment, expKey: "name", expComment: "; comment", expFormat: "%s%s", @@ -263,7 +263,7 @@ func TestParseVariable(t *testing.T) { desc: "With comment #2", in: []byte(`name ; comment`), expErr: io.EOF, - expMode: varModeSingle | varModeComment, + expMode: lineModeSingle | lineModeComment, expKey: "name", expComment: "; comment", expFormat: "%s %s", @@ -272,7 +272,7 @@ func TestParseVariable(t *testing.T) { desc: "With empty value #1", in: []byte(`name=`), expErr: io.EOF, - expMode: varModeSingle, + expMode: lineModeSingle, expKey: "name", expFormat: "%s=", expValue: varValueTrue, @@ -280,7 +280,7 @@ func TestParseVariable(t *testing.T) { desc: "With empty value #2", in: []byte(`name =`), expErr: io.EOF, - expMode: varModeSingle, + expMode: lineModeSingle, expKey: "name", expFormat: "%s =", expValue: varValueTrue, @@ -288,7 +288,7 @@ func TestParseVariable(t *testing.T) { desc: "With empty value and comment", in: []byte(`name =# a comment`), expErr: io.EOF, - expMode: varModeSingle | varModeComment, + expMode: lineModeSingle | lineModeComment, expKey: "name", expFormat: "%s =%s", expComment: "# a comment", @@ -297,7 +297,7 @@ func TestParseVariable(t *testing.T) { desc: "With empty value #3", in: []byte(`name `), expErr: io.EOF, - expMode: varModeSingle, + expMode: lineModeSingle, expKey: "name", expFormat: "%s ", expValue: varValueTrue, @@ -306,7 +306,7 @@ func TestParseVariable(t *testing.T) { in: []byte(`name `), expErr: io.EOF, - expMode: varModeSingle, + expMode: lineModeSingle, expKey: "name", expFormat: "%s \n", expValue: varValueTrue, @@ -317,7 +317,7 @@ func TestParseVariable(t *testing.T) { }, { desc: "With dot", in: []byte(`name.subname`), - expMode: varModeSingle, + expMode: lineModeSingle, expErr: io.EOF, expKey: "name.subname", expFormat: "%s", @@ -325,7 +325,7 @@ func TestParseVariable(t *testing.T) { }, { desc: "With underscore char", in: []byte(`name_subname`), - expMode: varModeSingle, + expMode: lineModeSingle, expErr: io.EOF, expKey: "name_subname", expFormat: "%s", diff --git a/lib/ini/section.go b/lib/ini/section.go index bf6c13a8..db0589c8 100644 --- a/lib/ini/section.go +++ b/lib/ini/section.go @@ -17,7 +17,7 @@ import ( // compare section name use the NameLower field. // type section struct { - mode varMode + mode lineMode lineNum int name string sub string @@ -38,14 +38,14 @@ func newSection(name, subName string) (sec *section) { } sec = §ion{ - mode: varModeSection, + mode: lineModeSection, name: name, } sec.nameLower = strings.ToLower(sec.name) if len(subName) > 0 { - sec.mode |= varModeSubsection + sec.mode |= lineModeSubsection sec.sub = subName } @@ -140,9 +140,9 @@ func (sec *section) addVariable(v *variable) { return } - if v.mode&varModeSingle == varModeSingle || - v.mode&varModeValue == varModeValue || - v.mode&varModeMulti == varModeMulti { + if v.mode&lineModeSingle == lineModeSingle || + v.mode&lineModeValue == lineModeValue || + v.mode&lineModeMulti == lineModeMulti { if len(v.value) == 0 { v.value = varValueTrue } @@ -262,7 +262,7 @@ func (sec *section) set(key, value string) bool { if idx < 0 { sec.addVariable(&variable{ - mode: varModeValue, + mode: lineModeValue, key: key, value: value, }) diff --git a/lib/ini/section_test.go b/lib/ini/section_test.go index 92ddedd5..d0bf3d37 100644 --- a/lib/ini/section_test.go +++ b/lib/ini/section_test.go @@ -25,7 +25,7 @@ func TestNewSection(t *testing.T) { desc: "With name only", name: "Section", expSec: §ion{ - mode: varModeSection, + mode: lineModeSection, name: "Section", nameLower: "section", }, @@ -34,7 +34,7 @@ func TestNewSection(t *testing.T) { name: "Section", sub: "Subsection", expSec: §ion{ - mode: varModeSection | varModeSubsection, + mode: lineModeSection | lineModeSubsection, name: "Section", nameLower: "section", sub: "Subsection", @@ -73,7 +73,7 @@ func TestSectionSet(t *testing.T) { name: sec.name, nameLower: sec.nameLower, vars: []*variable{{ - mode: varModeValue, + mode: lineModeValue, key: "Key-1", keyLower: "key-1", value: "true", @@ -89,7 +89,7 @@ func TestSectionSet(t *testing.T) { name: sec.name, nameLower: sec.nameLower, vars: []*variable{{ - mode: varModeValue, + mode: lineModeValue, key: "Key-1", keyLower: "key-1", value: "false", @@ -105,12 +105,12 @@ func TestSectionSet(t *testing.T) { name: sec.name, nameLower: sec.nameLower, vars: []*variable{{ - mode: varModeValue, + mode: lineModeValue, key: "Key-1", keyLower: "key-1", value: "false", }, { - mode: varModeValue, + mode: lineModeValue, key: "Key-2", keyLower: "key-2", value: "2", @@ -125,12 +125,12 @@ func TestSectionSet(t *testing.T) { name: sec.name, nameLower: sec.nameLower, vars: []*variable{{ - mode: varModeValue, + mode: lineModeValue, key: "Key-1", keyLower: "key-1", value: "false", }, { - mode: varModeValue, + mode: lineModeValue, key: "Key-2", keyLower: "key-2", value: "true", @@ -167,17 +167,17 @@ func TestSectionAdd(t *testing.T) { name: sec.name, nameLower: sec.nameLower, vars: []*variable{{ - mode: varModeValue, + mode: lineModeValue, key: "Key-1", keyLower: "key-1", value: "false", }, { - mode: varModeValue, + mode: lineModeValue, key: "Key-2", keyLower: "key-2", value: "true", }, { - mode: varModeValue, + mode: lineModeValue, key: "Key-1", keyLower: "key-1", value: "true", @@ -192,22 +192,22 @@ func TestSectionAdd(t *testing.T) { name: sec.name, nameLower: sec.nameLower, vars: []*variable{{ - mode: varModeValue, + mode: lineModeValue, key: "Key-1", keyLower: "key-1", value: "false", }, { - mode: varModeValue, + mode: lineModeValue, key: "Key-2", keyLower: "key-2", value: "true", }, { - mode: varModeValue, + mode: lineModeValue, key: "Key-1", keyLower: "key-1", value: "true", }, { - mode: varModeValue, + mode: lineModeValue, key: "Key-1", keyLower: "key-1", value: "1", @@ -280,17 +280,17 @@ func TestSectionUnset(t *testing.T) { name: sec.name, nameLower: sec.nameLower, vars: []*variable{{ - mode: varModeValue, + mode: lineModeValue, key: "Key-1", keyLower: "key-1", value: "false", }, { - mode: varModeValue, + mode: lineModeValue, key: "Key-1", keyLower: "key-1", value: "true", }, { - mode: varModeValue, + mode: lineModeValue, key: "Key-1", keyLower: "key-1", value: "1", @@ -305,17 +305,17 @@ func TestSectionUnset(t *testing.T) { name: sec.name, nameLower: sec.nameLower, vars: []*variable{{ - mode: varModeValue, + mode: lineModeValue, key: "Key-1", keyLower: "key-1", value: "false", }, { - mode: varModeValue, + mode: lineModeValue, key: "Key-1", keyLower: "key-1", value: "true", }, { - mode: varModeValue, + mode: lineModeValue, key: "Key-1", keyLower: "key-1", value: "1", @@ -396,22 +396,22 @@ func TestSectionReplaceAll(t *testing.T) { name: sec.name, nameLower: sec.nameLower, vars: []*variable{{ - mode: varModeValue, + mode: lineModeValue, key: "key-3", keyLower: "key-3", value: "3", }, { - mode: varModeValue, + mode: lineModeValue, key: "key-3", keyLower: "key-3", value: "33", }, { - mode: varModeValue, + mode: lineModeValue, key: "key-3", keyLower: "key-3", value: "333", }, { - mode: varModeValue, + mode: lineModeValue, key: "key-3", keyLower: "key-3", value: "3333", @@ -426,27 +426,27 @@ func TestSectionReplaceAll(t *testing.T) { name: sec.name, nameLower: sec.nameLower, vars: []*variable{{ - mode: varModeValue, + mode: lineModeValue, key: "key-3", keyLower: "key-3", value: "3", }, { - mode: varModeValue, + mode: lineModeValue, key: "key-3", keyLower: "key-3", value: "33", }, { - mode: varModeValue, + mode: lineModeValue, key: "key-3", keyLower: "key-3", value: "333", }, { - mode: varModeValue, + mode: lineModeValue, key: "key-3", keyLower: "key-3", value: "3333", }, { - mode: varModeValue, + mode: lineModeValue, key: "KEY-4", keyLower: "key-4", value: "4", @@ -461,12 +461,12 @@ func TestSectionReplaceAll(t *testing.T) { name: sec.name, nameLower: sec.nameLower, vars: []*variable{{ - mode: varModeValue, + mode: lineModeValue, key: "KEY-4", keyLower: "key-4", value: "4", }, { - mode: varModeValue, + mode: lineModeValue, key: "KEY-3", keyLower: "key-3", value: "replaced", diff --git a/lib/ini/variable.go b/lib/ini/variable.go index 65f9d720..dbc20eff 100644 --- a/lib/ini/variable.go +++ b/lib/ini/variable.go @@ -9,18 +9,6 @@ import ( "fmt" ) -type varMode uint - -const ( - varModeEmpty varMode = 0 - varModeComment = 1 - varModeSection = 2 - varModeSubsection = 4 - varModeSingle = 8 - varModeValue = 16 - varModeMulti = 32 -) - const ( varValueTrue = "true" ) @@ -34,7 +22,7 @@ const ( // want to compare variable, use the KeyLower value. // type variable struct { - mode varMode + mode lineMode lineNum int format string secName string @@ -52,71 +40,71 @@ func (v *variable) String() string { var buf bytes.Buffer switch v.mode { - case varModeEmpty: + case lineModeEmpty: if len(v.format) > 0 { _, _ = fmt.Fprint(&buf, v.format) } - case varModeComment: + case lineModeComment: if len(v.format) > 0 { _, _ = fmt.Fprintf(&buf, v.format, v.others) } else { _, _ = fmt.Fprintf(&buf, "%s\n", v.others) } - case varModeSection: + case lineModeSection: if len(v.format) > 0 { _, _ = fmt.Fprintf(&buf, v.format, v.secName) } else { _, _ = fmt.Fprintf(&buf, "[%s]\n", v.secName) } - case varModeSection | varModeComment: + case lineModeSection | lineModeComment: if len(v.format) > 0 { _, _ = fmt.Fprintf(&buf, v.format, v.secName, v.others) } else { _, _ = fmt.Fprintf(&buf, "[%s] %s\n", v.secName, v.others) } - case varModeSection | varModeSubsection: + case lineModeSection | lineModeSubsection: if len(v.format) > 0 { _, _ = fmt.Fprintf(&buf, v.format, v.secName, v.subName) } else { _, _ = fmt.Fprintf(&buf, `[%s "%s"]\n`, v.secName, v.subName) } - case varModeSection | varModeSubsection | varModeComment: + case lineModeSection | lineModeSubsection | lineModeComment: if len(v.format) > 0 { _, _ = fmt.Fprintf(&buf, v.format, v.secName, v.subName, v.others) } else { _, _ = fmt.Fprintf(&buf, `[%s "%s"] %s\n`, v.secName, v.subName, v.others) } - case varModeSingle: + case lineModeSingle: if len(v.format) > 0 { _, _ = fmt.Fprintf(&buf, v.format, v.key) } else { _, _ = fmt.Fprintf(&buf, "%s = true\n", v.key) } - case varModeSingle | varModeComment: + case lineModeSingle | lineModeComment: if len(v.format) > 0 { _, _ = fmt.Fprintf(&buf, v.format, v.key, v.others) } else { _, _ = fmt.Fprintf(&buf, "%s = true %s\n", v.key, v.others) } - case varModeValue: + case lineModeValue: if len(v.format) > 0 { _, _ = fmt.Fprintf(&buf, v.format, v.key) } else { _, _ = fmt.Fprintf(&buf, "%s = %s\n", v.key, v.value) } - case varModeValue | varModeComment: + case lineModeValue | lineModeComment: if len(v.format) > 0 { _, _ = fmt.Fprintf(&buf, v.format, v.key, v.others) } else { _, _ = fmt.Fprintf(&buf, "%s = %s %s\n", v.key, v.value, v.others) } - case varModeMulti: + case lineModeMulti: if len(v.format) > 0 { _, _ = fmt.Fprintf(&buf, v.format, v.key) } else { _, _ = fmt.Fprintf(&buf, "%s = %s\n", v.key, v.value) } - case varModeMulti | varModeComment: + case lineModeMulti | lineModeComment: if len(v.format) > 0 { _, _ = fmt.Fprintf(&buf, v.format, v.key, v.others) } else { diff --git a/lib/ini/variable_test.go b/lib/ini/variable_test.go index 3752a186..d881d3a5 100644 --- a/lib/ini/variable_test.go +++ b/lib/ini/variable_test.go @@ -18,19 +18,19 @@ func TestVariableString(t *testing.T) { }{{ desc: "With mode empty #1", v: &variable{ - mode: varModeEmpty, + mode: lineModeEmpty, }, }, { desc: "With mode empty #2", v: &variable{ - mode: varModeEmpty, + mode: lineModeEmpty, format: " ", }, exp: " ", }, { desc: "With mode comment #1", v: &variable{ - mode: varModeComment, + mode: lineModeComment, format: " %s", others: "; comment", }, @@ -38,21 +38,21 @@ func TestVariableString(t *testing.T) { }, { desc: "With mode comment #2", v: &variable{ - mode: varModeComment, + mode: lineModeComment, others: "; comment", }, exp: "; comment\n", }, { desc: "With mode section", v: &variable{ - mode: varModeSection, + mode: lineModeSection, secName: "section", }, exp: "[section]\n", }, { desc: "With mode section and comment #1", v: &variable{ - mode: varModeSection | varModeComment, + mode: lineModeSection | lineModeComment, secName: "section", others: "; comment", }, @@ -60,7 +60,7 @@ func TestVariableString(t *testing.T) { }, { desc: "With mode section and comment #2", v: &variable{ - mode: varModeSection | varModeComment, + mode: lineModeSection | lineModeComment, format: " [%s] %s", secName: "section", others: "; comment", @@ -69,7 +69,7 @@ func TestVariableString(t *testing.T) { }, { desc: "With mode section and subsection", v: &variable{ - mode: varModeSection | varModeSubsection, + mode: lineModeSection | lineModeSubsection, secName: "section", subName: "subsection", }, @@ -77,7 +77,7 @@ func TestVariableString(t *testing.T) { }, { desc: "With mode section, subsection, and comment", v: &variable{ - mode: varModeSection | varModeSubsection | varModeComment, + mode: lineModeSection | lineModeSubsection | lineModeComment, secName: "section", subName: "subsection", others: "; comment", @@ -86,14 +86,14 @@ func TestVariableString(t *testing.T) { }, { desc: "With mode single", v: &variable{ - mode: varModeSingle, + mode: lineModeSingle, key: "name", }, exp: "name = true\n", }, { desc: "With mode single and comment", v: &variable{ - mode: varModeSingle | varModeComment, + mode: lineModeSingle | lineModeComment, key: "name", others: "; comment", }, @@ -101,7 +101,7 @@ func TestVariableString(t *testing.T) { }, { desc: "With mode value", v: &variable{ - mode: varModeValue, + mode: lineModeValue, key: "name", value: "value", }, @@ -109,7 +109,7 @@ func TestVariableString(t *testing.T) { }, { desc: "With mode value and comment", v: &variable{ - mode: varModeValue | varModeComment, + mode: lineModeValue | lineModeComment, key: "name", value: "value", others: "; comment", @@ -118,7 +118,7 @@ func TestVariableString(t *testing.T) { }, { desc: "With mode multi", v: &variable{ - mode: varModeMulti, + mode: lineModeMulti, key: "name", value: "value", }, @@ -126,7 +126,7 @@ func TestVariableString(t *testing.T) { }, { desc: "With mode multi and comment", v: &variable{ - mode: varModeMulti | varModeComment, + mode: lineModeMulti | lineModeComment, key: "name", value: "value", others: "; comment", |
