Skip to content

Commit

Permalink
reverse booleans
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahalsmiller committed Nov 5, 2024
1 parent 782b781 commit fccb564
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var (
// Unmarshal accepts a byte slice as input and writes the
// data to the value pointed to by v.
func Unmarshal(bs []byte, v interface{}) error {
root, err := parse(bs, true)
root, err := parse(bs, false)
if err != nil {
return err
}
Expand All @@ -34,8 +34,8 @@ func Unmarshal(bs []byte, v interface{}) error {

// Unmarshal accepts a byte slice as input and writes the
// data to the value pointed to by v.
func UnmarshalDontErrorOnDuplicates(bs []byte, v interface{}) error {
root, err := parse(bs, false)
func UnmarshalErrorOnDuplicates(bs []byte, v interface{}) error {
root, err := parse(bs, true)
if err != nil {
return err
}
Expand All @@ -46,13 +46,13 @@ func UnmarshalDontErrorOnDuplicates(bs []byte, v interface{}) error {
// Decode reads the given input and decodes it into the structure
// given by `out`.
func Decode(out interface{}, in string) error {
return decode(out, in, true)
return decode(out, in, false)
}

// Decode reads the given input and decodes it into the structure
// given by `out`.
func DecodeDontErrorOnDuplicates(out interface{}, in string) error {
return decode(out, in, false)
func DecodeErrorOnDuplicates(out interface{}, in string) error {
return decode(out, in, true)
}

// Decode reads the given input and decodes it into the structure
Expand Down
18 changes: 9 additions & 9 deletions decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ func TestDecode_interface(t *testing.T) {
},
{
"basic_duplicates.hcl",
true,
nil,
false,
map[string]interface{}{
"foo": "${file(\"bing/bong.txt\")}",
},
},
{
"empty.hcl",
Expand Down Expand Up @@ -455,18 +457,16 @@ func TestDecode_interface(t *testing.T) {
}
}

func TestDecodeDontErrorOnDuplicates_interface(t *testing.T) {
func TestDecodeErrorOnDuplicates_interface(t *testing.T) {
cases := []struct {
File string
Err bool
Out interface{}
}{
{
"basic_duplicates.hcl",
false,
map[string]interface{}{
"foo": "${file(\"bing/bong.txt\")}",
},
true,
nil,
},
}

Expand All @@ -478,7 +478,7 @@ func TestDecodeDontErrorOnDuplicates_interface(t *testing.T) {
}

var out interface{}
err = DecodeDontErrorOnDuplicates(&out, string(d))
err = DecodeErrorOnDuplicates(&out, string(d))
if (err != nil) != tc.Err {
t.Fatalf("Input: %s\n\nError: %s", tc.File, err)
}
Expand All @@ -488,7 +488,7 @@ func TestDecodeDontErrorOnDuplicates_interface(t *testing.T) {
}

var v interface{}
err = UnmarshalDontErrorOnDuplicates(d, &v)
err = UnmarshalErrorOnDuplicates(d, &v)
if (err != nil) != tc.Err {
t.Fatalf("Input: %s\n\nError: %s", tc.File, err)
}
Expand Down

0 comments on commit fccb564

Please sign in to comment.