1package mux23import (4 "testing"56 "gno.land/p/nt/uassert/v0"7 "gno.land/p/nt/ufmt/v0"8)910func TestRequest_GetVar(t *testing.T) {11 cases := []struct {12 handlerPath string13 reqPath string14 getVarKey string15 expectedOutput string16 }{1718 {"users/{id}", "users/123", "id", "123"},19 {"users/123", "users/123", "id", ""},20 {"users/{id}", "users/123", "nonexistent", ""},21 {"users/{userId}/posts/{postId}", "users/123/posts/456", "userId", "123"},22 {"users/{userId}/posts/{postId}", "users/123/posts/456", "postId", "456"},2324 // Wildcards25 {"*", "users/123", "*", "users/123"},26 {"*", "users/123/posts/456", "*", "users/123/posts/456"},27 {"*", "users/123/posts/456/comments/789", "*", "users/123/posts/456/comments/789"},28 {"users/*", "users/john/posts", "*", "john/posts"},29 {"users/*/comments", "users/jane/comments", "*", "jane/comments"},30 {"api/*/posts/*", "api/v1/posts/123", "*", "v1/posts/123"},3132 // wildcards and parameters33 {"api/{version}/*", "api/v1/user/settings", "version", "v1"},34 }35 for _, tt := range cases {36 name := ufmt.Sprintf("%s-%s", tt.handlerPath, tt.reqPath)37 t.Run(name, func(t *testing.T) {38 req := &Request{39 HandlerPath: tt.handlerPath,40 Path: tt.reqPath,41 }42 output := req.GetVar(tt.getVarKey)43 uassert.Equal(t, tt.expectedOutput, output,44 "handler: %q, path: %q, key: %q",45 tt.handlerPath, tt.reqPath, tt.getVarKey)46 })47 }48}49Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.