Skip to content

Commit

Permalink
refactor: move status code before method
Browse files Browse the repository at this point in the history
  • Loading branch information
crhntr committed Aug 30, 2024
1 parent 1011246 commit 4502441
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/muxt/testdata/generate/form.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cat template_routes.go
exec go test -cover

-- template.gohtml --
{{define "POST / Method(form) 201" }}<script>var _ = {{.}}</script>{{end}}
{{define "POST / 201 Method(form)" }}<script>var _ = {{.}}</script>{{end}}

-- go.mod --
module server
Expand Down
2 changes: 1 addition & 1 deletion name.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func newTemplate(in string) (TemplateName, error, bool) {

var (
pathSegmentPattern = regexp.MustCompile(`/\{([^}]*)}`)
templateNameMux = regexp.MustCompile(`^(?P<endpoint>(((?P<method>[A-Z]+)\s+)?)(?P<host>([^/])*)(?P<path>(/(\S)*)))(?P<handler>\PL+.*\(.*\))?(?P<code>\s\d+)?$`)
templateNameMux = regexp.MustCompile(`^(?P<endpoint>(((?P<method>[A-Z]+)\s+)?)(?P<host>([^/])*)(?P<path>(/(\S)*)))(?P<code>\s\d+)?(?P<handler>\PL+.*\(.*\))?$`)
)

func (def TemplateName) parsePathValueNames() ([]string, error) {
Expand Down
10 changes: 9 additions & 1 deletion name_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,21 @@ func TestNewTemplateName(t *testing.T) {
},
},
{
Name: "with code",
Name: "without status code",
In: "POST /",
ExpMatch: true,
TemplateName: func(t *testing.T, pat TemplateName) {
assert.Equal(t, http.StatusOK, pat.statusCode)
},
},
{
Name: "with status code and handler",
In: "POST / 202 F()",
ExpMatch: true,
TemplateName: func(t *testing.T, pat TemplateName) {
assert.Equal(t, http.StatusAccepted, pat.statusCode)
},
},
} {
t.Run(tt.Name, func(t *testing.T) {
pat, err, match := NewTemplateName(tt.In)
Expand Down

0 comments on commit 4502441

Please sign in to comment.