d2ir: Make globs case insensitive to match the rest of the language

note: I personally wish to change the language and make it case sensitive.
This commit is contained in:
Anmol Sethi 2023-07-29 16:43:22 -07:00
parent 95667750e0
commit ff47a00abf
No known key found for this signature in database
GPG key ID: 8CEF1878FF10ADEB
3 changed files with 172 additions and 1 deletions

View file

@ -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]):]

View file

@ -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) {

159
testdata/d2ir/TestCompile/patterns/case.exp.json generated vendored Normal file
View file

@ -0,0 +1,159 @@
{
"fields": [
{
"name": "animal",
"primary": {
"value": {
"range": "TestCompile/patterns/case.d2,2:4:29-2:11:36",
"value": [
{
"string": "globbed",
"raw_string": "globbed"
}
]
}
},
"references": [
{
"string": {
"range": "TestCompile/patterns/case.d2,0:0:0-0:6:6",
"value": [
{
"string": "animal",
"raw_string": "animal"
}
]
},
"key_path": {
"range": "TestCompile/patterns/case.d2,0:0:0-0:6:6",
"path": [
{
"unquoted_string": {
"range": "TestCompile/patterns/case.d2,0:0:0-0:6:6",
"value": [
{
"string": "animal",
"raw_string": "animal"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/patterns/case.d2,0:0:0-0:12:12",
"key": {
"range": "TestCompile/patterns/case.d2,0:0:0-0:6:6",
"path": [
{
"unquoted_string": {
"range": "TestCompile/patterns/case.d2,0:0:0-0:6:6",
"value": [
{
"string": "animal",
"raw_string": "animal"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/patterns/case.d2,0:8:8-0:12:12",
"value": [
{
"string": "meow",
"raw_string": "meow"
}
]
}
}
}
}
}
]
},
{
"name": "action",
"primary": {
"value": {
"range": "TestCompile/patterns/case.d2,2:4:29-2:11:36",
"value": [
{
"string": "globbed",
"raw_string": "globbed"
}
]
}
},
"references": [
{
"string": {
"range": "TestCompile/patterns/case.d2,1:0:13-1:6:19",
"value": [
{
"string": "action",
"raw_string": "action"
}
]
},
"key_path": {
"range": "TestCompile/patterns/case.d2,1:0:13-1:6:19",
"path": [
{
"unquoted_string": {
"range": "TestCompile/patterns/case.d2,1:0:13-1:6:19",
"value": [
{
"string": "action",
"raw_string": "action"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/patterns/case.d2,1:0:13-1:11:24",
"key": {
"range": "TestCompile/patterns/case.d2,1:0:13-1:6:19",
"path": [
{
"unquoted_string": {
"range": "TestCompile/patterns/case.d2,1:0:13-1:6:19",
"value": [
{
"string": "action",
"raw_string": "action"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/patterns/case.d2,1:8:21-1:11:24",
"value": [
{
"string": "yes",
"raw_string": "yes"
}
]
}
}
}
}
}
]
}
],
"edges": null
}