androidbp: Test valueToString

Change-Id: I358cf4bb020fc4db14792e2cdffc18bc2f89f4d4
diff --git a/androidbp/cmd/androidbp_test.go b/androidbp/cmd/androidbp_test.go
new file mode 100644
index 0000000..178ea57
--- /dev/null
+++ b/androidbp/cmd/androidbp_test.go
@@ -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)
+		}
+	}
+}