From eea9a0067a2892c2bfa8589b2a8709c3c253e8cf Mon Sep 17 00:00:00 2001 From: PJ Date: Sat, 18 Apr 2026 01:59:46 +0700 Subject: [PATCH] feat(hierarchy): descPrefix selector for Compose testTag + UUID suffixes --- internal/hierarchy/hierarchy.go | 9 ++++++--- internal/hierarchy/hierarchy_test.go | 13 +++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/internal/hierarchy/hierarchy.go b/internal/hierarchy/hierarchy.go index a77825b..427865c 100644 --- a/internal/hierarchy/hierarchy.go +++ b/internal/hierarchy/hierarchy.go @@ -3,9 +3,10 @@ // // Selector grammar (v0.1): // -// id: — match resource-id ending with ":id/" or equal to -// text: — exact match on the node's text -// desc: — exact match on the node's content-desc +// id: — match resource-id ending with ":id/" or equal to +// text: — exact match on the node's text +// desc: — exact match on the node's content-desc +// descPrefix: — startsWith match on the node's content-desc (e.g. Compose testTag + UUID) package hierarchy import ( @@ -133,6 +134,8 @@ func match(element *Element, kind, value string) bool { return element.Text == value case "desc": return element.Description == value + case "descPrefix": + return strings.HasPrefix(element.Description, value) default: return false } diff --git a/internal/hierarchy/hierarchy_test.go b/internal/hierarchy/hierarchy_test.go index f1b6f41..1ca1321 100644 --- a/internal/hierarchy/hierarchy_test.go +++ b/internal/hierarchy/hierarchy_test.go @@ -73,3 +73,16 @@ func TestUnknownSelector(t *testing.T) { t.Fatal("unknown kind should not match") } } + +func TestDescPrefix(t *testing.T) { + xml := ` + + + + ` + tree, _ := Parse(xml) + rows := tree.FindAll("descPrefix:customer_row_") + if len(rows) != 2 { + t.Fatalf("want 2 customer rows, got %d", len(rows)) + } +}