From 681a235385d5d8b35a44a879ecf94fc17b38c91c Mon Sep 17 00:00:00 2001 From: Maciej Borzecki Date: Wed, 7 Aug 2024 14:05:26 +0200 Subject: [PATCH] interfaces/prompting/patterns: add unit test for conflicting patterns Add a specific unit for parting and then rendering a pattern which produces many identical variants. Signed-off-by: Maciej Borzecki --- .../patterns/render_internal_test.go | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/interfaces/prompting/patterns/render_internal_test.go b/interfaces/prompting/patterns/render_internal_test.go index 2252515f3359..7ea48660e35e 100644 --- a/interfaces/prompting/patterns/render_internal_test.go +++ b/interfaces/prompting/patterns/render_internal_test.go @@ -95,6 +95,28 @@ func (s *renderSuite) TestRenderAllVariants(c *C) { c.Check(variants, HasLen, parsed.NumVariants()) } +func (s *renderSuite) TestRenderAllVariantsConflicts(c *C) { + // all variants are the exact same path + pattern := "/{fo{obar},foo{b{ar,ar},bar,{ba}r}}" + scanned, err := scan(pattern) + c.Assert(err, IsNil) + parsed, err := parse(scanned) + c.Assert(err, IsNil) + + expectedVariants := []string{ + "/foobar", + } + + variants := make([]string, 0, len(expectedVariants)) + renderAllVariants(parsed, func(index int, variant PatternVariant) { + variants = append(variants, variant.String()) + }) + + c.Check(variants, DeepEquals, expectedVariants) + c.Check(variants, HasLen, parsed.NumVariants()) + c.Check(variants, HasLen, 1) +} + func (s *renderSuite) TestNextVariant(c *C) { pattern := "/{,usr/}lib{,32,64,x32}/{,@{multiarch}/{,atomics/}}ld{-*,64}.so*" scanned, err := scan(pattern)