Files
build_soong/androidbp/cmd/androidbp_test.go
Dan Willemsen f33877b0e9 androidbp: Test valueToString
Change-Id: I358cf4bb020fc4db14792e2cdffc18bc2f89f4d4
2015-06-29 21:46:22 +00:00

60 lines
1.1 KiB
Go

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)
}
}
}