| 1 |
package editorconfig //nolint:testpackage |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
) |
| 6 |
|
| 7 |
func TestTranslate(t *testing.T) { |
| 8 |
t.Parallel() |
| 9 |
|
| 10 |
tests := []struct { |
| 11 |
pattern string |
| 12 |
expected string |
| 13 |
}{ |
| 14 |
{"a*e.c", `a[^/]*e\.c`}, |
| 15 |
{"a**z.c", `a.*z\.c`}, |
| 16 |
{"d/**/z.c", `d(?:/|/.*/)z\.c`}, |
| 17 |
{"som?.c", `som[^/]\.c`}, |
| 18 |
{"[\\]ab].g", `[\]ab]\.g`}, |
| 19 |
{"[ab]].g", `[ab]]\.g`}, |
| 20 |
{"ab[/c", `ab\[/c`}, |
| 21 |
{"*.{py,js,html}", `[^/]*\.(?:py|js|html)`}, |
| 22 |
{"{single}.b", `\{single\}\.b`}, |
| 23 |
{"{{,b,c{d}.i", `\{\{,b,c\{d\}\.i`}, |
| 24 |
{"{a\\,b,cd}", `(?:a,b|cd)`}, |
| 25 |
{"{e,\\},f}", `(?:e|}|f)`}, |
| 26 |
{"{a,{b,c}}", `(?:a|(?:b|c))`}, |
| 27 |
{"{{a,b},c}", `(?:(?:a|b)|c)`}, |
| 28 |
} |
| 29 |
|
| 30 |
for _, test := range tests { |
| 31 |
t.Run(test.pattern, func(t *testing.T) { |
| 32 |
t.Parallel() |
| 33 |
|
| 34 |
result := translate(test.pattern) |
| 35 |
if result != test.expected { |
| 36 |
t.Errorf("%s != %s", test.expected, result) |
| 37 |
} |
| 38 |
}) |
| 39 |
} |
| 40 |
} |