aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2018-09-26 23:32:54 +0700
committerShulhan <ms@kilabit.info>2018-09-26 23:33:10 +0700
commit351ccdbdcec960358f6f94c215c4d178b2f52fd7 (patch)
tree1166af345b8f5de7481bec85108ce7d432b3a2f6
parent0e821e8b243c7ae067f8fccfb172c233238fe0fd (diff)
downloadpakakeh.go-351ccdbdcec960358f6f94c215c4d178b2f52fd7.tar.xz
lib/ini: move IsValueBoolTrue as common function
-rw-r--r--lib/ini/common.go25
-rw-r--r--lib/ini/common_test.go54
-rw-r--r--lib/ini/variable.go17
-rw-r--r--lib/ini/variable_test.go56
4 files changed, 79 insertions, 73 deletions
diff --git a/lib/ini/common.go b/lib/ini/common.go
new file mode 100644
index 00000000..4da99cc5
--- /dev/null
+++ b/lib/ini/common.go
@@ -0,0 +1,25 @@
+// 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
+
+import (
+ "strings"
+)
+
+//
+// IsValueBoolTrue will return true if variable contains boolean value for
+// true. The following conditions is boolean true for value: "" (empty
+// string), "true", "yes", "ya", "t", "1" (all of string is case insensitive).
+//
+func IsValueBoolTrue(v string) bool {
+ if len(v) == 0 {
+ return true
+ }
+ v = strings.ToLower(v)
+ if v == "true" || v == "t" || v == "ya" || v == "yes" || v == "1" {
+ return true
+ }
+ return false
+}
diff --git a/lib/ini/common_test.go b/lib/ini/common_test.go
new file mode 100644
index 00000000..3f5fb697
--- /dev/null
+++ b/lib/ini/common_test.go
@@ -0,0 +1,54 @@
+// 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
+
+import (
+ "testing"
+
+ "github.com/shuLhan/share/lib/test"
+)
+
+func TestIsValueBoolTrue(t *testing.T) {
+ cases := []struct {
+ desc string
+ v string
+ exp bool
+ }{{
+ desc: "With empty value",
+ exp: true,
+ }, {
+ desc: "With value in all caps",
+ v: "TRUE",
+ exp: true,
+ }, {
+ desc: "With value is yes",
+ v: "YES",
+ exp: true,
+ }, {
+ desc: "With value is ya",
+ v: "yA",
+ exp: true,
+ }, {
+ desc: "With value is 1",
+ v: "1",
+ exp: true,
+ }, {
+ desc: "With value is 11",
+ v: "11",
+ exp: false,
+ }, {
+ desc: "With value is tru (typo)",
+ v: "tru",
+ exp: false,
+ }}
+
+ for _, c := range cases {
+ t.Log(c.desc)
+
+ got := IsValueBoolTrue(c.v)
+
+ test.Assert(t, "", c.exp, got, true)
+ }
+}
diff --git a/lib/ini/variable.go b/lib/ini/variable.go
index 94fd35c8..30e799fc 100644
--- a/lib/ini/variable.go
+++ b/lib/ini/variable.go
@@ -7,7 +7,6 @@ package ini
import (
"bytes"
"fmt"
- "strings"
)
type varMode uint
@@ -48,22 +47,6 @@ type Variable struct {
}
//
-// IsValueBoolTrue will return true if variable contains boolean value for
-// true. The following conditions is boolean true for value: "" (empty
-// string), "true", "yes", "ya", "t", "1" (all of string is case insensitive).
-//
-func (v *Variable) IsValueBoolTrue() bool {
- if len(v.Value) == 0 {
- return true
- }
- value := strings.ToLower(v.Value)
- if value == "true" || value == "t" || value == "ya" || value == "yes" || value == "1" {
- return true
- }
- return false
-}
-
-//
// String return formatted INI variable.
//
func (v *Variable) String() string {
diff --git a/lib/ini/variable_test.go b/lib/ini/variable_test.go
index 35cea218..fb941f6a 100644
--- a/lib/ini/variable_test.go
+++ b/lib/ini/variable_test.go
@@ -10,62 +10,6 @@ import (
"github.com/shuLhan/share/lib/test"
)
-func TestVariableIsValueBoolTrue(t *testing.T) {
- cases := []struct {
- desc string
- v *Variable
- exp bool
- }{{
- desc: "With empty value",
- v: &Variable{},
- exp: true,
- }, {
- desc: "With value in all caps",
- v: &Variable{
- Value: "TRUE",
- },
- exp: true,
- }, {
- desc: "With value is yes",
- v: &Variable{
- Value: "YES",
- },
- exp: true,
- }, {
- desc: "With value is ya",
- v: &Variable{
- Value: "yA",
- },
- exp: true,
- }, {
- desc: "With value is 1",
- v: &Variable{
- Value: "1",
- },
- exp: true,
- }, {
- desc: "With value is 11",
- v: &Variable{
- Value: "11",
- },
- exp: false,
- }, {
- desc: "With value is tru (typo)",
- v: &Variable{
- Value: "tru",
- },
- exp: false,
- }}
-
- for _, c := range cases {
- t.Log(c.desc)
-
- got := c.v.IsValueBoolTrue()
-
- test.Assert(t, "", c.exp, got, true)
- }
-}
-
func TestVariableString(t *testing.T) {
cases := []struct {
desc string