Skip to content

Commit

Permalink
function/stdlib: Test cases for SubtractFunc
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgoodhouse authored and apparentlymart committed Nov 26, 2019
1 parent e9c57e4 commit c6d6223
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions cty/function/stdlib/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,55 @@ func TestSetIntersection(t *testing.T) {
})
}
}

func TestSetSubtract(t *testing.T) {
tests := []struct {
InputA cty.Value
InputB cty.Value
Want cty.Value
}{
{
cty.SetValEmpty(cty.String),
cty.SetValEmpty(cty.String),
cty.SetValEmpty(cty.String),
},
{
cty.SetVal([]cty.Value{cty.True}),
cty.SetValEmpty(cty.String),
cty.SetVal([]cty.Value{cty.StringVal("true")}),
},
{
cty.SetVal([]cty.Value{cty.True}),
cty.SetVal([]cty.Value{cty.False}),
cty.SetVal([]cty.Value{cty.True}),
},
{
cty.SetVal([]cty.Value{
cty.StringVal("a"),
cty.StringVal("b"),
cty.StringVal("c"),
}),
cty.SetVal([]cty.Value{
cty.StringVal("a"),
cty.StringVal("c"),
}),
cty.SetVal([]cty.Value{
cty.StringVal("b"),
}),
},
}

for _, test := range tests {
t.Run(fmt.Sprintf("SetSubtract(%#v, %#v)", test.InputA, test.InputB), func(t *testing.T) {
got, err := SetSubtract(test.InputA, test.InputB)

if err != nil {
t.Fatalf("unexpected error: %s", err)
}

if !got.RawEquals(test.Want) {
t.Errorf("wrong result\ngot: %#v\nwant: %#v", got, test.Want)
}
})
}
}

0 comments on commit c6d6223

Please sign in to comment.