mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-13 03:45:37 +00:00
Added getValue tests
This commit is contained in:
parent
35ceb01222
commit
0cb8a47ccb
24
yaml_test.go
24
yaml_test.go
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -42,9 +43,30 @@ func TestWrite_simple(t *testing.T) {
|
|||||||
assertResult(t, "4", b["c"].(string))
|
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{}) {
|
func assertResult(t *testing.T, expectedValue interface{}, actualValue interface{}) {
|
||||||
if (expectedValue != actualValue) {
|
if expectedValue != actualValue {
|
||||||
t.Error("Expected <", expectedValue, "> but got <", 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, ">")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user