-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support glob.match without delimiters #4923 #4933
Changes from 4 commits
4e3111a
1cec74d
e7e8e2e
ef40d44
3a51bd0
21beae4
9f26e40
d0c4640
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
cases: | ||
- data: {} | ||
modules: | ||
- | | ||
package generated | ||
|
||
p[x] { | ||
glob.match("*", null, "foo.bar", x) | ||
} | ||
note: globmatch/glob match single without default delimiter | ||
query: data.generated.p = x | ||
sort_bindings: true | ||
want_result: | ||
- x: | ||
- true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you mind adding one case like glob.match("foo*", null, "foo.bar", x) just to make the "no delimiters" case more obvious? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added another test case to more clearly about this. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,16 +18,22 @@ func builtinGlobMatch(a, b, c ast.Value) (ast.Value, error) { | |
if err != nil { | ||
return nil, err | ||
} | ||
var delimiters []rune | ||
switch b.(type) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need a default case here, otherwise it'll accept any input, too |
||
case ast.Null: | ||
delimiters = []rune{} | ||
case *ast.Array: | ||
delimiters, err = builtins.RuneSliceOperand(b, 2) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
delimiters, err := builtins.RuneSliceOperand(b, 2) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if len(delimiters) == 0 { | ||
delimiters = []rune{'.'} | ||
if len(delimiters) == 0 { | ||
delimiters = []rune{'.'} | ||
} | ||
default: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry this isn't what I meant -- if it's not
|
||
return nil, builtins.NewOperandTypeErr(2, b, "array", "null") | ||
} | ||
|
||
match, err := builtins.StringOperand(c, 3) | ||
if err != nil { | ||
return nil, err | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this line only gives a call by type
ArrayString
ornull
. So any types else have raised error before function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's for static inputs. There are still inputs whose type is only known at runtime. For example
glob.match(input.m, input.d, input.x)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have made a change to return
OperandError
with default.