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:
parent
95667750e0
commit
ff47a00abf
3 changed files with 172 additions and 1 deletions
|
|
@ -44,7 +44,7 @@ func matchPattern(s string, pattern []string) bool {
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if !strings.HasPrefix(s, pattern[i]) {
|
if !strings.HasPrefix(strings.ToLower(s), strings.ToLower(pattern[i])) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
s = s[len(pattern[i]):]
|
s = s[len(pattern[i]):]
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,18 @@ a*: globbed`)
|
||||||
assertQuery(t, m, 0, 0, "globbed", "action")
|
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",
|
name: "suffix",
|
||||||
run: func(t testing.TB) {
|
run: func(t testing.TB) {
|
||||||
|
|
|
||||||
159
testdata/d2ir/TestCompile/patterns/case.exp.json
generated
vendored
Normal file
159
testdata/d2ir/TestCompile/patterns/case.exp.json
generated
vendored
Normal 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
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue