(t *testing.T)
| 403 | } |
| 404 | |
| 405 | func TestExtendStdlibFunction(t *testing.T) { |
| 406 | env := testEnv(t, |
| 407 | Function(overloads.Contains, |
| 408 | MemberOverload("bytes_contains_bytes", []*Type{BytesType, BytesType}, BoolType, |
| 409 | BinaryBinding(func(bstr, bsub ref.Val) ref.Val { |
| 410 | return types.Bool(bytes.Contains([]byte(bstr.(types.Bytes)), []byte(bsub.(types.Bytes)))) |
| 411 | }))), |
| 412 | ) |
| 413 | prg := compile(t, env, `b'string'.contains(b'tri') && 'string'.contains('tri')`) |
| 414 | out, _, err := prg.Eval(NoVars()) |
| 415 | if err != nil { |
| 416 | t.Fatalf("contains check errored: %v", err) |
| 417 | } |
| 418 | if out != types.True { |
| 419 | t.Errorf("contains check got %v, wanted true", out) |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | func TestSubsetStdLib(t *testing.T) { |
| 424 | env, err := NewCustomEnv( |
nothing calls this directly
no test coverage detected