Skip to content

Commit 0cb8a47

Browse files
mfarahmikefarah
authored andcommitted
Added getValue tests
1 parent 35ceb01 commit 0cb8a47

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

yaml_test.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"gopkg.in/yaml.v2"
66
"os"
7+
"strings"
78
"testing"
89
)
910

@@ -42,9 +43,30 @@ func TestWrite_simple(t *testing.T) {
4243
assertResult(t, "4", b["c"].(string))
4344
}
4445

46+
var getValueTests = []struct {
47+
argument string
48+
expectedResult interface{}
49+
testDescription string
50+
}{
51+
{"true", true, "boolean"},
52+
{"3.4", 3.4, "number"},
53+
}
54+
55+
func TestGetValue(t *testing.T) {
56+
for _, tt := range getValueTests {
57+
assertResultWithContext(t, tt.expectedResult, getValue(tt.argument, false), tt.testDescription)
58+
assertResultWithContext(t, tt.argument, getValue(tt.argument, true), strings.Join([]string{tt.testDescription, "with forceString"}, " "))
59+
}
60+
}
4561

4662
func assertResult(t *testing.T, expectedValue interface{}, actualValue interface{}) {
47-
if (expectedValue != actualValue) {
63+
if expectedValue != actualValue {
4864
t.Error("Expected <", expectedValue, "> but got <", actualValue, ">")
4965
}
5066
}
67+
68+
func assertResultWithContext(t *testing.T, expectedValue interface{}, actualValue interface{}, testDescription string) {
69+
if expectedValue != actualValue {
70+
t.Error(testDescription, ": expected <", expectedValue, "> but got <", actualValue, ">")
71+
}
72+
}

0 commit comments

Comments
 (0)