1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-03-27 22:01:47 +02:00
Tim Voronov 2643321e0f
Migration to lab (#526)
* Switched to Lab for e2e tests

* Switched to binary

* Updated lab installation

* Updated use of Lab installer

* updates

* Changed lab installation path

* Updated use of installer

* Works

* Added additional functions

* Updated some tests

* Updated go.sum

* Works

* Refactored assertions

* Added tests for testing.True

* Added tests for testing.None

* Added tests for testing.Lte

* Added tests for testing.Lt

* Added generic consturctor

* Added tests for testing.Len

* Added tests for testing.Gte

* Added tests for testing.Gt

* Added tests for testing.False

* Added tests for testing.Empty

* Added tests for testing.Fail

* Added tests for testing.Equal

* Added tests for testing.Include

* Updated urls in static page tests

* Fixed namespace unit tests

* Fixed unit test for testing.Len

* Updated E2E scripts

* Updaes

* Updated Chrome in CI/CD

* Added e2e for example test click.fql

* Added suite cases for example scripts

* Updated examples

* Updated

* Added type assertions

* Updated Chrome opts and disabled headers and cookies related tests

* Fixed iframes example

* Increased timeouts in navigation examples

* Updated value example

* Updated comments

* Disabled cookies examples

* Fixed static url

* Disabled headers examples

* Disabled UA test

* Simplified wait logic

* Added base testing module

* Fixes after codereview

* Disabled failing tests
2020-06-17 17:37:01 -04:00

74 lines
1.6 KiB
Go

package collections
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
"github.com/MontFerret/ferret/pkg/runtime/values/types"
)
// Includes checks whether a container includes a given value.
// @param text (String|Array|Object|Iterable) - The value container.
// @param text (Mixed) - The target value to assert.
// @returns (Boolean) - Returns a boolean value that indicates whether a container contains a given value.
func Includes(ctx context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 2, 2)
if err != nil {
return values.None, err
}
var result values.Boolean
haystack := args[0]
needle := args[1]
switch v := haystack.(type) {
case values.String:
result = v.Contains(values.NewString(needle.String()))
break
case *values.Array:
_, result = v.Find(func(value core.Value, _ int) bool {
return needle.Compare(value) == 0
})
break
case *values.Object:
_, result = v.Find(func(value core.Value, _ string) bool {
return needle.Compare(value) == 0
})
break
case core.Iterable:
iter, err := v.Iterate(ctx)
if err != nil {
return values.False, err
}
err = core.ForEach(ctx, iter, func(value core.Value, key core.Value) bool {
if needle.Compare(value) == 0 {
result = values.True
return false
}
return true
})
if err != nil {
return values.False, err
}
default:
return values.None, core.TypeError(haystack.Type(),
types.String,
types.Array,
types.Object,
core.NewType("Iterable"),
)
}
return result, nil
}