github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/testing/include.go (about) 1 package testing 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/MontFerret/ferret/pkg/runtime/core" 8 "github.com/MontFerret/ferret/pkg/runtime/values" 9 "github.com/MontFerret/ferret/pkg/stdlib/collections" 10 "github.com/MontFerret/ferret/pkg/stdlib/testing/base" 11 ) 12 13 // INCLUDE asserts that haystack includes needle. 14 // @param {String | Array | Object | Iterable} actual - Haystack value. 15 // @param {Any} expected - Expected value. 16 // @param {String} [message] - Message to display on error. 17 var Include = base.Assertion{ 18 DefaultMessage: func(args []core.Value) string { 19 return fmt.Sprintf("include %s", base.FormatValue(args[1])) 20 }, 21 MinArgs: 2, 22 MaxArgs: 3, 23 Fn: func(ctx context.Context, args []core.Value) (bool, error) { 24 haystack := args[0] 25 needle := args[1] 26 27 out, err := collections.Includes(ctx, haystack, needle) 28 29 if err != nil { 30 return false, err 31 } 32 33 return out.Compare(values.True) == 0, nil 34 }, 35 }