(t *testing.T)
| 76 | } |
| 77 | |
| 78 | func TestGlobPathToRegexp(t *testing.T) { |
| 79 | for _, test := range []struct { |
| 80 | in string |
| 81 | want string |
| 82 | error string |
| 83 | }{ |
| 84 | {``, `(^|/)$`, ``}, |
| 85 | {`potato`, `(^|/)potato$`, ``}, |
| 86 | {`potato,sausage`, `(^|/)potato,sausage$`, ``}, |
| 87 | {`/potato`, `^potato$`, ``}, |
| 88 | {`potato?sausage`, `(^|/)potato[^/]sausage$`, ``}, |
| 89 | {`potat[oa]`, `(^|/)potat[oa]$`, ``}, |
| 90 | {`potat[a-z]or`, `(^|/)potat[a-z]or$`, ``}, |
| 91 | {`potat[[:alpha:]]or`, `(^|/)potat[[:alpha:]]or$`, ``}, |
| 92 | {`'.' '+' '(' ')' '|' '^' '$'`, `(^|/)'\.' '\+' '\(' '\)' '\|' '\^' '\$'$`, ``}, |
| 93 | {`*.jpg`, `(^|/)[^/]*\.jpg$`, ``}, |
| 94 | {`a{b,c,d}e`, `(^|/)a(b|c|d)e$`, ``}, |
| 95 | {`potato**`, `(^|/)potato.*$`, ``}, |
| 96 | {`potato**sausage`, `(^|/)potato.*sausage$`, ``}, |
| 97 | {`*.p[lm]`, `(^|/)[^/]*\.p[lm]$`, ``}, |
| 98 | {`[\[\]]`, `(^|/)[\[\]]$`, ``}, |
| 99 | {`***potato`, ``, `too many stars`}, |
| 100 | {`***`, ``, `too many stars`}, |
| 101 | {`ab]c`, ``, `mismatched ']'`}, |
| 102 | {`ab[c`, ``, `mismatched '[' and ']'`}, |
| 103 | {`ab{x{cd`, ``, `can't nest`}, |
| 104 | {`ab{}}cd`, ``, `mismatched '{' and '}'`}, |
| 105 | {`ab}c`, ``, `mismatched '{' and '}'`}, |
| 106 | {`ab{c`, ``, `mismatched '{' and '}'`}, |
| 107 | {`*.{jpg,png,gif}`, `(^|/)[^/]*\.(jpg|png|gif)$`, ``}, |
| 108 | {`[a--b]`, ``, `bad glob pattern`}, |
| 109 | {`a\*b`, `(^|/)a\*b$`, ``}, |
| 110 | {`a\\b`, `(^|/)a\\b$`, ``}, |
| 111 | {`a{{.*}}b`, `(^|/)a(.*)b$`, ``}, |
| 112 | {`a{{.*}`, ``, `mismatched '{{' and '}}'`}, |
| 113 | {`{{regexp}}`, `(^|/)(regexp)$`, ``}, |
| 114 | {`\{{{regexp}}`, `(^|/)\{(regexp)$`, ``}, |
| 115 | {`/{{regexp}}`, `^(regexp)$`, ``}, |
| 116 | {`/{{\d{8}}}`, `^(\d{8})$`, ``}, |
| 117 | {`/{{\}}}`, `^(\})$`, ``}, |
| 118 | {`{{(?i)regexp}}`, `(^|/)((?i)regexp)$`, ``}, |
| 119 | } { |
| 120 | for _, ignoreCase := range []bool{false, true} { |
| 121 | gotRe, err := GlobPathToRegexp(test.in, ignoreCase) |
| 122 | if test.error == "" { |
| 123 | require.NoError(t, err, test.in) |
| 124 | prefix := "" |
| 125 | if ignoreCase { |
| 126 | prefix = "(?i)" |
| 127 | } |
| 128 | got := gotRe.String() |
| 129 | assert.Equal(t, prefix+test.want, got, test.in) |
| 130 | } else { |
| 131 | require.Error(t, err, test.in) |
| 132 | assert.Contains(t, err.Error(), test.error, test.in) |
| 133 | assert.Nil(t, gotRe) |
| 134 | } |
| 135 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…