test(kql): cover dotted keys in property restrictions

Four cases covering the distinct grammar paths touched by the
new Key rule: dotted key in a TextPropertyRestrictionNode,
multi-level key (stressing the Kleene part), dotted key in a
GroupNode (the k:Key? branch), and a dot on the value side
that must stay a literal character.
This commit is contained in:
Dominik Schmidt
2026-04-20 16:05:07 +02:00
parent ed1353d161
commit c7a2ab8d02

View File

@@ -916,6 +916,61 @@ func TestParse_Errors(t *testing.T) {
}
}
func TestParse_DottedKey(t *testing.T) {
tests := []testCase{
// TextPropertyRestrictionNode with a dotted key.
{
name: `audio.artist:Motörhead`,
ast: &ast.Ast{
Nodes: []ast.Node{
&ast.StringNode{Key: "audio.artist", Value: "Motörhead"},
},
},
},
// Multi-level key exercises the ("." Char+)* kleene in the Key rule.
{
name: `foo.bar.baz:qux`,
ast: &ast.Ast{
Nodes: []ast.Node{
&ast.StringNode{Key: "foo.bar.baz", Value: "qux"},
},
},
},
// GroupNode also uses the Key rule via k:Key?.
{
name: `audio.artist:("Motörhead" OR Beatles)`,
ast: &ast.Ast{
Nodes: []ast.Node{
&ast.GroupNode{
Key: "audio.artist",
Nodes: []ast.Node{
&ast.StringNode{Value: "Motörhead"},
&ast.OperatorNode{Value: kql.BoolOR},
&ast.StringNode{Value: "Beatles"},
},
},
},
},
},
// A dot on the value side is still a literal character.
{
name: `name:foo.bar`,
ast: &ast.Ast{
Nodes: []ast.Node{
&ast.StringNode{Key: "name", Value: "foo.bar"},
},
},
},
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
testKQL(t, tc)
})
}
}
func TestParse_Stress(t *testing.T) {
tests := []testCase{
{