From 80117687294aaebcdc1df11a456cd1655e58ab8d Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 30 Oct 2015 15:53:55 -0700 Subject: Add property support for pointers to bools and strings The only append semantics for bool that result in a no-op when the zero value is appended is to OR the two values together, but that is rarely the desired semantics. Add support for *bool and *string as property types, where appending a nil pointer is a no-op. For *bool, appending a non-nil pointer replaces the destination with the value. For *string, appending a non-nil pointer appends the value. This also provides a more reliable replacement for ModuleContext.ContainsProperty, as the build logic can tell that the property was set, even if it was set by a mutator and not by the blueprints file, by testing against nil. []string already provides these semantics for lists. Setting a *bool or *string property from a blueprints file is the same syntax as setting a bool or a string property. --- unpack_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'unpack_test.go') diff --git a/unpack_test.go b/unpack_test.go index 0b31efc..77a57ec 100644 --- a/unpack_test.go +++ b/unpack_test.go @@ -30,6 +30,24 @@ var validUnpackTestCases = []struct { output interface{} errs []error }{ + {` + m { + name: "abc", + blank: "", + } + `, + struct { + Name *string + Blank *string + Unset *string + }{ + Name: proptools.StringPtr("abc"), + Blank: proptools.StringPtr(""), + Unset: nil, + }, + nil, + }, + {` m { name: "abc", @@ -56,6 +74,24 @@ var validUnpackTestCases = []struct { nil, }, + {` + m { + isGood: true, + isBad: false, + } + `, + struct { + IsGood *bool + IsBad *bool + IsUgly *bool + }{ + IsGood: proptools.BoolPtr(true), + IsBad: proptools.BoolPtr(false), + IsUgly: nil, + }, + nil, + }, + {` m { stuff: ["asdf", "jkl;", "qwert", -- cgit v1.2.3