You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
toolkit/integrationtest/assert_matches_text_test.go

125 lines
2.0 KiB

package integrationtest
import (
"testing"
)
func Test_patternMatch(t *testing.T) {
type args struct {
expected string
actual string
pattern string
}
tests := []struct {
name string
args args
want bool
}{
{
name: "foobarbaz matches",
args: args{
expected: "foo[BAR]baz",
actual: "foobarbaz",
pattern: "[BAR]",
},
want: true,
},
{
name: "foobarbaz does not match",
args: args{
expected: "foo[BAR]baz",
actual: "foobazbar",
pattern: "[BAR]",
},
want: false,
},
{
name: "wildcard matches but not rest of string",
args: args{
expected: "foo[BAR]baz",
actual: "foobarfizz",
pattern: "[BAR]",
},
want: false,
},
{
name: "just wildcard",
args: args{
expected: "[BAR]",
actual: "foobarbaz",
pattern: "[BAR]",
},
want: true,
},
{
name: "prefix",
args: args{
expected: "prefix[BAR]",
actual: "prefixbarbaz",
pattern: "[BAR]",
},
want: true,
},
{
name: "prefix does not match",
args: args{
expected: "prefix[BAR]",
actual: "somethingelsebarbaz",
pattern: "[BAR]",
},
want: false,
},
{
name: "suffix",
args: args{
expected: "[BAR]suffix",
actual: "foobarbazsuffix",
pattern: "[BAR]",
},
want: true,
},
{
name: "no pattern",
args: args{
expected: "exact match",
actual: "exact match",
pattern: "[BAR]",
},
want: true,
},
{
name: "multiline",
args: args{
expected: `first line
[BAR]
last line`,
actual: `first line
second line
last line`,
pattern: "[BAR]",
},
want: true,
},
{
name: "multiline prefix",
args: args{
expected: `[BAR]
first line
last line`,
actual: `[BAR]
first line
last line`,
pattern: "[BAR]",
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := patternMatch(tt.args.expected, tt.args.actual, tt.args.pattern); got != tt.want {
t.Errorf("patternMatch() = %v, want %v", got, tt.want)
}
})
}
}