/* * Copyright 2026 Oleg Borodin * * This work is published and licensed under a Creative Commons * Attribution-NonCommercial-NoDerivatives 4.0 International License. * * Distribution of this work is permitted, but commercial use and * modifications are strictly prohibited. */ package router import ( "fmt" "regexp" "testing" "github.com/stretchr/testify/require" ) func tDebugf(msg string, args ...any) { fmt.Printf("debug: ") fmt.Printf(msg, args...) fmt.Printf("\n") } func TestPatchCompilerA(t *testing.T) { var err error srcPath := `/v1/file/{collection:[a-zA-Z]+}/{name}` reSource, err := pathCompiler(srcPath) require.NoError(t, err) tDebugf("re: %s\n", reSource) re, err := regexp.Compile(reSource) require.NoError(t, err) reqPath := `/v1/file/foo/bare` match := re.MatchString(reqPath) require.True(t, match) submatch := re.FindStringSubmatch(reqPath) subnames := re.SubexpNames() submap := make(map[string]string) for i, val := range subnames { tDebugf("subname: %d = %s", i, val) } for i, val := range submatch { key := subnames[i] if key != "" { submap[key] = val } tDebugf("sub: %d = %s", i, val) } tDebugf("submap: %v", submap) }