d2ir: Make suffix globs case insensitive too
This commit is contained in:
parent
63efa12160
commit
bd2c94f7a8
4 changed files with 312 additions and 2 deletions
|
|
@ -39,7 +39,7 @@ func matchPattern(s string, pattern []string) bool {
|
|||
if pattern[i] == "*" {
|
||||
// * so match next.
|
||||
if i != len(pattern)-1 {
|
||||
j := strings.Index(s, pattern[i+1])
|
||||
j := strings.Index(strings.ToLower(s), strings.ToLower(pattern[i+1]))
|
||||
if j == -1 {
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ a*: globbed`)
|
|||
},
|
||||
},
|
||||
{
|
||||
name: "case",
|
||||
name: "case/1",
|
||||
run: func(t testing.TB) {
|
||||
m, err := compile(t, `animal: meow
|
||||
action: yes
|
||||
|
|
@ -47,6 +47,18 @@ A*: globbed`)
|
|||
assertQuery(t, m, 0, 0, "globbed", "action")
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "case/2",
|
||||
run: func(t testing.TB) {
|
||||
m, err := compile(t, `diddy kong
|
||||
Donkey Kong
|
||||
*kong: yes`)
|
||||
assert.Success(t, err)
|
||||
assertQuery(t, m, 2, 0, nil, "")
|
||||
assertQuery(t, m, 0, 0, "yes", "diddy kong")
|
||||
assertQuery(t, m, 0, 0, "yes", "Donkey Kong")
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "suffix",
|
||||
run: func(t testing.TB) {
|
||||
|
|
|
|||
159
testdata/d2ir/TestCompile/patterns/case/1.exp.json
generated
vendored
Normal file
159
testdata/d2ir/TestCompile/patterns/case/1.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
{
|
||||
"fields": [
|
||||
{
|
||||
"name": "animal",
|
||||
"primary": {
|
||||
"value": {
|
||||
"range": "TestCompile/patterns/case/1.d2,2:4:29-2:11:36",
|
||||
"value": [
|
||||
{
|
||||
"string": "globbed",
|
||||
"raw_string": "globbed"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"string": {
|
||||
"range": "TestCompile/patterns/case/1.d2,0:0:0-0:6:6",
|
||||
"value": [
|
||||
{
|
||||
"string": "animal",
|
||||
"raw_string": "animal"
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path": {
|
||||
"range": "TestCompile/patterns/case/1.d2,0:0:0-0:6:6",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "TestCompile/patterns/case/1.d2,0:0:0-0:6:6",
|
||||
"value": [
|
||||
{
|
||||
"string": "animal",
|
||||
"raw_string": "animal"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"context": {
|
||||
"edge": null,
|
||||
"key": {
|
||||
"range": "TestCompile/patterns/case/1.d2,0:0:0-0:12:12",
|
||||
"key": {
|
||||
"range": "TestCompile/patterns/case/1.d2,0:0:0-0:6:6",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "TestCompile/patterns/case/1.d2,0:0:0-0:6:6",
|
||||
"value": [
|
||||
{
|
||||
"string": "animal",
|
||||
"raw_string": "animal"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {
|
||||
"unquoted_string": {
|
||||
"range": "TestCompile/patterns/case/1.d2,0:8:8-0:12:12",
|
||||
"value": [
|
||||
{
|
||||
"string": "meow",
|
||||
"raw_string": "meow"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "action",
|
||||
"primary": {
|
||||
"value": {
|
||||
"range": "TestCompile/patterns/case/1.d2,2:4:29-2:11:36",
|
||||
"value": [
|
||||
{
|
||||
"string": "globbed",
|
||||
"raw_string": "globbed"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"string": {
|
||||
"range": "TestCompile/patterns/case/1.d2,1:0:13-1:6:19",
|
||||
"value": [
|
||||
{
|
||||
"string": "action",
|
||||
"raw_string": "action"
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path": {
|
||||
"range": "TestCompile/patterns/case/1.d2,1:0:13-1:6:19",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "TestCompile/patterns/case/1.d2,1:0:13-1:6:19",
|
||||
"value": [
|
||||
{
|
||||
"string": "action",
|
||||
"raw_string": "action"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"context": {
|
||||
"edge": null,
|
||||
"key": {
|
||||
"range": "TestCompile/patterns/case/1.d2,1:0:13-1:11:24",
|
||||
"key": {
|
||||
"range": "TestCompile/patterns/case/1.d2,1:0:13-1:6:19",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "TestCompile/patterns/case/1.d2,1:0:13-1:6:19",
|
||||
"value": [
|
||||
{
|
||||
"string": "action",
|
||||
"raw_string": "action"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {
|
||||
"unquoted_string": {
|
||||
"range": "TestCompile/patterns/case/1.d2,1:8:21-1:11:24",
|
||||
"value": [
|
||||
{
|
||||
"string": "yes",
|
||||
"raw_string": "yes"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"edges": null
|
||||
}
|
||||
139
testdata/d2ir/TestCompile/patterns/case/2.exp.json
generated
vendored
Normal file
139
testdata/d2ir/TestCompile/patterns/case/2.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
{
|
||||
"fields": [
|
||||
{
|
||||
"name": "diddy kong",
|
||||
"primary": {
|
||||
"value": {
|
||||
"range": "TestCompile/patterns/case/2.d2,2:7:30-2:10:33",
|
||||
"value": [
|
||||
{
|
||||
"string": "yes",
|
||||
"raw_string": "yes"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"string": {
|
||||
"range": "TestCompile/patterns/case/2.d2,0:0:0-0:10:10",
|
||||
"value": [
|
||||
{
|
||||
"string": "diddy kong",
|
||||
"raw_string": "diddy kong"
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path": {
|
||||
"range": "TestCompile/patterns/case/2.d2,0:0:0-0:10:10",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "TestCompile/patterns/case/2.d2,0:0:0-0:10:10",
|
||||
"value": [
|
||||
{
|
||||
"string": "diddy kong",
|
||||
"raw_string": "diddy kong"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"context": {
|
||||
"edge": null,
|
||||
"key": {
|
||||
"range": "TestCompile/patterns/case/2.d2,0:0:0-0:10:10",
|
||||
"key": {
|
||||
"range": "TestCompile/patterns/case/2.d2,0:0:0-0:10:10",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "TestCompile/patterns/case/2.d2,0:0:0-0:10:10",
|
||||
"value": [
|
||||
{
|
||||
"string": "diddy kong",
|
||||
"raw_string": "diddy kong"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Donkey Kong",
|
||||
"primary": {
|
||||
"value": {
|
||||
"range": "TestCompile/patterns/case/2.d2,2:7:30-2:10:33",
|
||||
"value": [
|
||||
{
|
||||
"string": "yes",
|
||||
"raw_string": "yes"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"string": {
|
||||
"range": "TestCompile/patterns/case/2.d2,1:0:11-1:11:22",
|
||||
"value": [
|
||||
{
|
||||
"string": "Donkey Kong",
|
||||
"raw_string": "Donkey Kong"
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path": {
|
||||
"range": "TestCompile/patterns/case/2.d2,1:0:11-1:11:22",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "TestCompile/patterns/case/2.d2,1:0:11-1:11:22",
|
||||
"value": [
|
||||
{
|
||||
"string": "Donkey Kong",
|
||||
"raw_string": "Donkey Kong"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"context": {
|
||||
"edge": null,
|
||||
"key": {
|
||||
"range": "TestCompile/patterns/case/2.d2,1:0:11-1:11:22",
|
||||
"key": {
|
||||
"range": "TestCompile/patterns/case/2.d2,1:0:11-1:11:22",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "TestCompile/patterns/case/2.d2,1:0:11-1:11:22",
|
||||
"value": [
|
||||
{
|
||||
"string": "Donkey Kong",
|
||||
"raw_string": "Donkey Kong"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"edges": null
|
||||
}
|
||||
Loading…
Reference in a new issue