|
4 | 4 | "fmt"
|
5 | 5 | "gopkg.in/yaml.v2"
|
6 | 6 | "os"
|
| 7 | + "strings" |
7 | 8 | "testing"
|
8 | 9 | )
|
9 | 10 |
|
@@ -42,9 +43,30 @@ func TestWrite_simple(t *testing.T) {
|
42 | 43 | assertResult(t, "4", b["c"].(string))
|
43 | 44 | }
|
44 | 45 |
|
| 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 | +} |
45 | 61 |
|
46 | 62 | func assertResult(t *testing.T, expectedValue interface{}, actualValue interface{}) {
|
47 |
| - if (expectedValue != actualValue) { |
| 63 | + if expectedValue != actualValue { |
48 | 64 | t.Error("Expected <", expectedValue, "> but got <", actualValue, ">")
|
49 | 65 | }
|
50 | 66 | }
|
| 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