(t *testing.T)
| 487 | } |
| 488 | |
| 489 | func TestExtendStdlibFunction(t *testing.T) { |
| 490 | env := testEnv(t, |
| 491 | Function(overloads.Contains, |
| 492 | MemberOverload("bytes_contains_bytes", []*Type{BytesType, BytesType}, BoolType, |
| 493 | BinaryBinding(func(bstr, bsub ref.Val) ref.Val { |
| 494 | return types.Bool(bytes.Contains([]byte(bstr.(types.Bytes)), []byte(bsub.(types.Bytes)))) |
| 495 | }))), |
| 496 | ) |
| 497 | prg := compile(t, env, `b'string'.contains(b'tri') && 'string'.contains('tri')`) |
| 498 | out, _, err := prg.Eval(NoVars()) |
| 499 | if err != nil { |
| 500 | t.Fatalf("contains check errored: %v", err) |
| 501 | } |
| 502 | if out != types.True { |
| 503 | t.Errorf("contains check got %v, wanted true", out) |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | func TestSubsetStdLib(t *testing.T) { |
| 508 | env, err := NewCustomEnv( |
nothing calls this directly
no test coverage detected