From 29dd8be6eab666db9122f4be6942c383551cf7a5 Mon Sep 17 00:00:00 2001 From: daixiheguu Date: Tue, 25 Aug 2026 19:22:47 +0800 Subject: [PATCH] docs: align function comments with names Signed-off-by: daixiheguu --- gin_integration_test.go | 1 + render/render_test.go | 4 ++-- response_writer_test.go | 3 ++- routes_test.go | 18 +++++++++--------- tree.go | 6 +++--- utils.go | 3 ++- 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/gin_integration_test.go b/gin_integration_test.go index 720b140f..da408d9c 100644 --- a/gin_integration_test.go +++ b/gin_integration_test.go @@ -25,6 +25,7 @@ import ( "github.com/stretchr/testify/require" ) +// testRequest sends a request and validates its response. // params[0]=url example:http://127.0.0.1:8080/index (cannot be empty) // params[1]=response status (custom compare status) default:"200 OK" // params[2]=response body (custom compare content) default:"it worked" diff --git a/render/render_test.go b/render/render_test.go index f63878b9..7889100a 100644 --- a/render/render_test.go +++ b/render/render_test.go @@ -283,7 +283,7 @@ func TestRenderPureJSON(t *testing.T) { type xmlmap map[string]any -// Allows type H to be used with xml.Marshal +// MarshalXML allows xmlmap to be used with xml.Marshal. func (h xmlmap) MarshalXML(e *xml.Encoder, start xml.StartElement) error { start.Name = xml.Name{ Space: "", @@ -331,7 +331,7 @@ b: type fail struct{} -// Hook MarshalYAML +// MarshalYAML returns an error for YAML rendering failure tests. func (ft *fail) MarshalYAML() (any, error) { return nil, errors.New("fail") } diff --git a/response_writer_test.go b/response_writer_test.go index 03417375..99548431 100644 --- a/response_writer_test.go +++ b/response_writer_test.go @@ -220,7 +220,8 @@ func TestResponseWriterHijackAfterWrite(t *testing.T) { } } -// Test: WebSocket compatibility - allow hijack after WriteHeaderNow(), but block after body data. +// TestResponseWriterHijackAfterWriteHeaderNow verifies that hijacking is allowed after +// WriteHeaderNow but blocked after body data is written. func TestResponseWriterHijackAfterWriteHeaderNow(t *testing.T) { tests := []struct { name string diff --git a/routes_test.go b/routes_test.go index 1cae3fce..1b7570b0 100644 --- a/routes_test.go +++ b/routes_test.go @@ -51,7 +51,7 @@ func testRouteOK(method string, t *testing.T) { assert.True(t, passedAny) } -// TestSingleRouteOK tests that POST route is correctly invoked. +// testRouteNotOK tests that a request with the wrong method returns a not found response. func testRouteNotOK(method string, t *testing.T) { passed := false router := New() @@ -65,7 +65,7 @@ func testRouteNotOK(method string, t *testing.T) { assert.Equal(t, http.StatusNotFound, w.Code) } -// TestSingleRouteOK tests that POST route is correctly invoked. +// testRouteNotOK2 tests that a request with the wrong method returns a method not allowed response. func testRouteNotOK2(method string, t *testing.T) { passed := false router := New() @@ -273,7 +273,7 @@ func TestRouteRedirectFixedPath(t *testing.T) { assert.Equal(t, http.StatusTemporaryRedirect, w.Code) } -// TestContextParamsGet tests that a parameter can be parsed from the URL. +// TestRouteParamsByName tests that route parameters can be parsed by name. func TestRouteParamsByName(t *testing.T) { name := "" lastName := "" @@ -305,7 +305,7 @@ func TestRouteParamsByName(t *testing.T) { assert.Equal(t, "/is/super/great", wild) } -// TestContextParamsGet tests that a parameter can be parsed from the URL even with extra slashes. +// TestRouteParamsByNameWithExtraSlash tests that route parameters can be parsed by name even with extra slashes. func TestRouteParamsByNameWithExtraSlash(t *testing.T) { name := "" lastName := "" @@ -377,7 +377,7 @@ func TestRouteParamsNotEmpty(t *testing.T) { assert.Equal(t, "/is/super/great", wild) } -// TestHandleStaticFile - ensure the static file handles properly +// TestRouteStaticFile tests that a static file is served correctly. func TestRouteStaticFile(t *testing.T) { // SETUP file testRoot, _ := os.Getwd() @@ -412,7 +412,7 @@ func TestRouteStaticFile(t *testing.T) { assert.Equal(t, http.StatusOK, w3.Code) } -// TestHandleStaticFile - ensure the static file handles properly +// TestRouteStaticFileFS tests that a static file from an http.FileSystem is served correctly. func TestRouteStaticFileFS(t *testing.T) { // SETUP file testRoot, _ := os.Getwd() @@ -446,7 +446,7 @@ func TestRouteStaticFileFS(t *testing.T) { assert.Equal(t, http.StatusOK, w3.Code) } -// TestHandleStaticDir - ensure the root/sub dir handles properly +// TestRouteStaticListingDir tests that static directory listing is enabled when configured. func TestRouteStaticListingDir(t *testing.T) { router := New() router.StaticFS("/", Dir("./", true)) @@ -458,7 +458,7 @@ func TestRouteStaticListingDir(t *testing.T) { assert.Equal(t, "text/html; charset=utf-8", w.Header().Get("Content-Type")) } -// TestHandleHeadToDir - ensure the root/sub dir handles properly +// TestRouteStaticNoListing tests that static directory listing is disabled by default. func TestRouteStaticNoListing(t *testing.T) { router := New() router.Static("/", "./") @@ -656,7 +656,7 @@ func TestRouterStaticFSFileNotFound(t *testing.T) { }) } -// Reproduction test for the bug of issue #1805 +// TestMiddlewareCalledOnceByRouterStaticFSNotFound reproduces the bug reported in issue #1805. func TestMiddlewareCalledOnceByRouterStaticFSNotFound(t *testing.T) { router := New() diff --git a/tree.go b/tree.go index 580abbaf..dc84ff61 100644 --- a/tree.go +++ b/tree.go @@ -107,7 +107,7 @@ type node struct { fullPath string } -// Increments priority of the given child and reorders if necessary +// incrementChildPrio increments the priority of the given child and reorders it if necessary. func (n *node) incrementChildPrio(pos int) int { cs := n.children cs[pos].priority++ @@ -683,7 +683,7 @@ func (n *node) findCaseInsensitivePath(path string, fixTrailingSlash bool) ([]by return ciPath, ciPath != nil } -// Shift bytes in array by n bytes left +// shiftNRuneBytes shifts bytes in the array n positions to the left. func shiftNRuneBytes(rb [4]byte, n int) [4]byte { switch n { case 0: @@ -699,7 +699,7 @@ func shiftNRuneBytes(rb [4]byte, n int) [4]byte { } } -// Recursive case-insensitive lookup function used by n.findCaseInsensitivePath +// findCaseInsensitivePathRec recursively performs a case-insensitive path lookup. func (n *node) findCaseInsensitivePathRec(path string, ciPath []byte, rb [4]byte, fixTrailingSlash bool) []byte { npLen := len(n.path) diff --git a/utils.go b/utils.go index 2fecce46..738161c4 100644 --- a/utils.go +++ b/utils.go @@ -160,7 +160,8 @@ func resolveAddress(addr []string) string { } } -// https://stackoverflow.com/questions/53069040/checking-a-string-contains-only-ascii-characters +// isASCII reports whether s contains only ASCII characters. +// See https://stackoverflow.com/questions/53069040/checking-a-string-contains-only-ascii-characters. func isASCII(s string) bool { for i := range len(s) { if s[i] > unicode.MaxASCII {