feat: supports importValue for more path formats (#1569)
`importValueRegex` now can match more path formats Resolves: #1568
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
const (
|
||||
versionRegex = `(?m)"v[1-9][0-9]*"`
|
||||
importValueRegex = `(?m)"(/?[a-zA-Z0-9_#-])+\.api"`
|
||||
importValueRegex = `(?m)"\/?(([a-zA-Z0-9.]+)+(\/?){1})+([a-zA-Z0-9]+)+\.api"`
|
||||
tagRegex = `(?m)\x60[a-z]+:".+"\x60`
|
||||
)
|
||||
|
||||
|
||||
@@ -9,3 +9,24 @@ import (
|
||||
func TestMatch(t *testing.T) {
|
||||
assert.False(t, matchRegex("v1ddd", versionRegex))
|
||||
}
|
||||
|
||||
func TestImportRegex(t *testing.T) {
|
||||
tests := []struct {
|
||||
value string
|
||||
matched bool
|
||||
}{
|
||||
{`"bar.api"`, true},
|
||||
{`"foo/bar.api"`, true},
|
||||
{`"/foo/bar.api"`, true},
|
||||
{`"../foo/bar.api"`, true},
|
||||
{`"../../foo/bar.api"`, true},
|
||||
|
||||
{`"bar..api"`, false},
|
||||
{`"//bar.api"`, false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.value, func(t *testing.T) {
|
||||
assert.Equal(t, tt.matched, matchRegex(tt.value, importValueRegex))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user