Skip to content

Commit

Permalink
d2ir: Make globs case insensitive to match the rest of the language
Browse files Browse the repository at this point in the history
note: I personally wish to change the language and make it case sensitive.
  • Loading branch information
nhooyr committed Jul 29, 2023
1 parent 137b909 commit 1c8ecd3
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 1 deletion.
2 changes: 1 addition & 1 deletion d2ir/pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func matchPattern(s string, pattern []string) bool {
i++
}
} else {
if !strings.HasPrefix(s, pattern[i]) {
if !strings.HasPrefix(strings.ToLower(s), strings.ToLower(pattern[i])) {
return false
}
s = s[len(pattern[i]):]
Expand Down
12 changes: 12 additions & 0 deletions d2ir/pattern_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ a*: globbed`)
assertQuery(t, m, 0, 0, "globbed", "action")
},
},
{
name: "case",
run: func(t testing.TB) {
m, err := compile(t, `animal: meow
action: yes
A*: globbed`)
assert.Success(t, err)
assertQuery(t, m, 2, 0, nil, "")
assertQuery(t, m, 0, 0, "globbed", "animal")
assertQuery(t, m, 0, 0, "globbed", "action")
},
},
{
name: "suffix",
run: func(t testing.TB) {
Expand Down
159 changes: 159 additions & 0 deletions testdata/d2ir/TestCompile/patterns/case.exp.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1c8ecd3

Please sign in to comment.