From 0cb8a47ccba4cc9fda54af7b156b1bd84ef5d3a6 Mon Sep 17 00:00:00 2001 From: mfarah Date: Thu, 1 Oct 2015 15:20:07 +1000 Subject: [PATCH] Added getValue tests --- yaml_test.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/yaml_test.go b/yaml_test.go index 30a14f7f..1e7451ee 100644 --- a/yaml_test.go +++ b/yaml_test.go @@ -4,6 +4,7 @@ import ( "fmt" "gopkg.in/yaml.v2" "os" + "strings" "testing" ) @@ -42,9 +43,30 @@ func TestWrite_simple(t *testing.T) { assertResult(t, "4", b["c"].(string)) } +var getValueTests = []struct { + argument string + expectedResult interface{} + testDescription string +}{ + {"true", true, "boolean"}, + {"3.4", 3.4, "number"}, +} + +func TestGetValue(t *testing.T) { + for _, tt := range getValueTests { + assertResultWithContext(t, tt.expectedResult, getValue(tt.argument, false), tt.testDescription) + assertResultWithContext(t, tt.argument, getValue(tt.argument, true), strings.Join([]string{tt.testDescription, "with forceString"}, " ")) + } +} func assertResult(t *testing.T, expectedValue interface{}, actualValue interface{}) { - if (expectedValue != actualValue) { + if expectedValue != actualValue { t.Error("Expected <", expectedValue, "> but got <", actualValue, ">") } } + +func assertResultWithContext(t *testing.T, expectedValue interface{}, actualValue interface{}, testDescription string) { + if expectedValue != actualValue { + t.Error(testDescription, ": expected <", expectedValue, "> but got <", actualValue, ">") + } +}