Dan Willemsen | f33877b | 2015-06-23 23:34:49 -0700 | [diff] [blame^] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | |
| 7 | bpparser "github.com/google/blueprint/parser" |
| 8 | ) |
| 9 | |
| 10 | var valueTestCases = []struct { |
| 11 | blueprint string |
| 12 | expected string |
| 13 | }{ |
| 14 | { |
| 15 | blueprint: `test = false`, |
| 16 | expected: `false`, |
| 17 | }, |
| 18 | { |
| 19 | blueprint: `test = Variable`, |
| 20 | expected: `$(Variable)`, |
| 21 | }, |
| 22 | { |
| 23 | blueprint: `test = "string"`, |
| 24 | expected: `string`, |
| 25 | }, |
| 26 | { |
| 27 | blueprint: `test = ["a", "b"]`, |
| 28 | expected: `\ |
| 29 | a \ |
| 30 | b`, |
| 31 | }, |
| 32 | { |
| 33 | blueprint: `test = Var + "b"`, |
| 34 | expected: `$(Var)b`, |
| 35 | }, |
| 36 | { |
| 37 | blueprint: `test = ["a"] + ["b"]`, |
| 38 | expected: `\ |
| 39 | a\ |
| 40 | b`, |
| 41 | }, |
| 42 | } |
| 43 | |
| 44 | func TestValueToString(t *testing.T) { |
| 45 | for _, testCase := range valueTestCases { |
| 46 | blueprint, errs := bpparser.Parse("", strings.NewReader(testCase.blueprint), nil) |
| 47 | if len(errs) > 0 { |
| 48 | t.Errorf("Failed to read blueprint: %q", errs) |
| 49 | } |
| 50 | |
| 51 | str := valueToString(blueprint.Defs[0].(*bpparser.Assignment).Value) |
| 52 | if str != testCase.expected { |
| 53 | t.Errorf("test case: %s", testCase.blueprint) |
| 54 | t.Errorf("unexpected difference:") |
| 55 | t.Errorf(" expected: %s", testCase.expected) |
| 56 | t.Errorf(" got: %s", str) |
| 57 | } |
| 58 | } |
| 59 | } |