diff --git a/dynaml/concatenation.go b/dynaml/concatenation.go index c646a5f..354723f 100644 --- a/dynaml/concatenation.go +++ b/dynaml/concatenation.go @@ -20,15 +20,17 @@ func (e ConcatenationExpr) Evaluate(binding Binding) (yaml.Node, bool) { return nil, false } - astring, ok := a.(string) - if !ok { - return nil, false + astring, aok := a.(string) + bstring, bok := b.(string) + if aok && bok { + return astring + bstring, true } - bstring, ok := b.(string) - if !ok { - return nil, false + alist, aok := a.([]yaml.Node) + blist, bok := b.([]yaml.Node) + if aok && bok { + return append(alist, blist...), true } - return astring + bstring, true + return nil, false } diff --git a/dynaml/concatenation_test.go b/dynaml/concatenation_test.go index 5db2092..c7449ab 100644 --- a/dynaml/concatenation_test.go +++ b/dynaml/concatenation_test.go @@ -1,39 +1,58 @@ package dynaml import ( + "github.com/vito/spiff/yaml" + . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("concatenation", func() { - It("concatenates two strings", func() { - expr := ConcatenationExpr{ - StringExpr{"one"}, - StringExpr{"two"}, - } + Context("when the left-hand side is a string", func() { + Context("and the right-hand side is a string", func() { + It("concatenates both strings", func() { + expr := ConcatenationExpr{ + StringExpr{"one"}, + StringExpr{"two"}, + } - Expect(expr).To(EvaluateAs("onetwo", FakeBinding{})) - }) + Expect(expr).To(EvaluateAs("onetwo", FakeBinding{})) + }) + }) - Context("when the left-hand side is not a string", func() { - It("fails", func() { - expr := ConcatenationExpr{ - StringExpr{"one"}, - IntegerExpr{42}, - } + Context("and the right-hand side is NOT a string", func() { + It("fails", func() { + expr := ConcatenationExpr{ + StringExpr{"two"}, + IntegerExpr{42}, + } - Expect(expr).To(FailToEvaluate(FakeBinding{})) + Expect(expr).To(FailToEvaluate(FakeBinding{})) + }) }) }) - Context("when the right-hand side is not a string", func() { - It("fails", func() { - expr := ConcatenationExpr{ - IntegerExpr{42}, - StringExpr{"two"}, - } + Context("when the left-hand side is a list", func() { + Context("and the right-hand side is a list", func() { + It("concatenates both lists", func() { + expr := ConcatenationExpr{ + ListExpr{[]Expression{StringExpr{"one"}}}, + ListExpr{[]Expression{StringExpr{"two"}}}, + } + + Expect(expr).To(EvaluateAs([]yaml.Node{"one", "two"}, FakeBinding{})) + }) + }) + + Context("and the right-hand side is NOT a list", func() { + It("fails", func() { + expr := ConcatenationExpr{ + IntegerExpr{42}, + ListExpr{[]Expression{StringExpr{"two"}}}, + } - Expect(expr).To(FailToEvaluate(FakeBinding{})) + Expect(expr).To(FailToEvaluate(FakeBinding{})) + }) }) }) }) diff --git a/spiff_test.go b/spiff_test.go index 7b319d9..3793323 100644 --- a/spiff_test.go +++ b/spiff_test.go @@ -48,7 +48,6 @@ foo: bar Expect(err).NotTo(HaveOccured()) }) - It("resolves the template and prints it out", func() { Expect(merge).To(Say(`foo: bar`)) Expect(merge).To(ExitWith(0))