Path: blob/main/vendor/github.com/onsi/gomega/matchers/have_prefix_matcher.go
2880 views
package matchers12import (3"fmt"45"github.com/onsi/gomega/format"6)78type HavePrefixMatcher struct {9Prefix string10Args []any11}1213func (matcher *HavePrefixMatcher) Match(actual any) (success bool, err error) {14actualString, ok := toString(actual)15if !ok {16return false, fmt.Errorf("HavePrefix matcher requires a string or stringer. Got:\n%s", format.Object(actual, 1))17}18prefix := matcher.prefix()19return len(actualString) >= len(prefix) && actualString[0:len(prefix)] == prefix, nil20}2122func (matcher *HavePrefixMatcher) prefix() string {23if len(matcher.Args) > 0 {24return fmt.Sprintf(matcher.Prefix, matcher.Args...)25}26return matcher.Prefix27}2829func (matcher *HavePrefixMatcher) FailureMessage(actual any) (message string) {30return format.Message(actual, "to have prefix", matcher.prefix())31}3233func (matcher *HavePrefixMatcher) NegatedFailureMessage(actual any) (message string) {34return format.Message(actual, "not to have prefix", matcher.prefix())35}363738