androidbp: Test valueToString

Change-Id: I358cf4bb020fc4db14792e2cdffc18bc2f89f4d4
This commit is contained in:
Dan Willemsen
2015-06-23 23:34:49 -07:00
parent 00a36d3f21
commit f33877b0e9
3 changed files with 98 additions and 1 deletions

View File

@@ -0,0 +1,59 @@
package main
import (
"strings"
"testing"
bpparser "github.com/google/blueprint/parser"
)
var valueTestCases = []struct {
blueprint string
expected string
}{
{
blueprint: `test = false`,
expected: `false`,
},
{
blueprint: `test = Variable`,
expected: `$(Variable)`,
},
{
blueprint: `test = "string"`,
expected: `string`,
},
{
blueprint: `test = ["a", "b"]`,
expected: `\
a \
b`,
},
{
blueprint: `test = Var + "b"`,
expected: `$(Var)b`,
},
{
blueprint: `test = ["a"] + ["b"]`,
expected: `\
a\
b`,
},
}
func TestValueToString(t *testing.T) {
for _, testCase := range valueTestCases {
blueprint, errs := bpparser.Parse("", strings.NewReader(testCase.blueprint), nil)
if len(errs) > 0 {
t.Errorf("Failed to read blueprint: %q", errs)
}
str := valueToString(blueprint.Defs[0].(*bpparser.Assignment).Value)
if str != testCase.expected {
t.Errorf("test case: %s", testCase.blueprint)
t.Errorf("unexpected difference:")
t.Errorf(" expected: %s", testCase.expected)
t.Errorf(" got: %s", str)
}
}
}