...
1
18
19 package grpcutil
20
21 import (
22 "regexp"
23 "testing"
24 )
25
26 func TestFullMatchWithRegex(t *testing.T) {
27 tests := []struct {
28 name string
29 regexStr string
30 string string
31 want bool
32 }{
33 {
34 name: "not match because only partial",
35 regexStr: "^a+$",
36 string: "ab",
37 want: false,
38 },
39 {
40 name: "match because fully match",
41 regexStr: "^a+$",
42 string: "aa",
43 want: true,
44 },
45 {
46 name: "longest",
47 regexStr: "a(|b)",
48 string: "ab",
49 want: true,
50 },
51 {
52 name: "match all",
53 regexStr: ".*",
54 string: "",
55 want: true,
56 },
57 {
58 name: "matches non-empty strings",
59 regexStr: ".+",
60 string: "",
61 want: false,
62 },
63 }
64 for _, tt := range tests {
65 t.Run(tt.name, func(t *testing.T) {
66 hrm := regexp.MustCompile(tt.regexStr)
67 if got := FullMatchWithRegex(hrm, tt.string); got != tt.want {
68 t.Errorf("match() = %v, want %v", got, tt.want)
69 }
70 })
71 }
72 }
73
View as plain text