docs: align function comments with names (#4814)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by daixiheguu · committed by GitHub · parent 3329b63 · Browse files · 6 files·+19 added−16 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Trailers
- Signed-off-by: daixiheguu <daixihegu@outlook.com>
- Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
Diff stats
6 files+19 added−16 removed
- other:+19 added−16 removed
Provenance
- Commit
e318c6a- Tree
af28e5b- Author
daixiheguu <daixihegu@outlook.com>- Committer
GitHub <noreply@github.com>- Parent
3329b63
6 files changed+19 added−16 removed
modified:render/render_test.go+2 added-2 removed
281 unmodified lines282 }283 284 type xmlmap map[string]any285 286-// Allows type H to be used with xml.Marshal286+// MarshalXML allows xmlmap to be used with xml.Marshal.287 func (h xmlmap) MarshalXML(e *xml.Encoder, start xml.StartElement) error {288 start.Name = xml.Name{289 Space: "",290 Local: "map",39 unmodified lines330 }331 332 type fail struct{}333 334-// Hook MarshalYAML334+// MarshalYAML returns an error for YAML rendering failure tests.335 func (ft *fail) MarshalYAML() (any, error) {336 return nil, errors.New("fail")337 }338 479 unmodified linesmodified:gin_integration_test.go+1 added
23 unmodified lines24 "github.com/stretchr/testify/assert"25 "github.com/stretchr/testify/require"26 )27 28+// testRequest sends a request and validates its response.29 // params[0]=url example:http://127.0.0.1:8080/index (cannot be empty)30 // params[1]=response status (custom compare status) default:"200 OK"31 // params[2]=response body (custom compare content) default:"it worked"32 func testRequest(t *testing.T, params ...string) {576 unmodified linesmodified:response_writer_test.go+2 added-1 removed
218 unmodified lines219 })220 }221 }222 223-// Test: WebSocket compatibility - allow hijack after WriteHeaderNow(), but block after body data.223+// TestResponseWriterHijackAfterWriteHeaderNow verifies that hijacking is allowed after224+// WriteHeaderNow but blocked after body data is written.225 func TestResponseWriterHijackAfterWriteHeaderNow(t *testing.T) {226 tests := []struct {227 name string228 action func(w ResponseWriter) error116 unmodified linesmodified:routes_test.go+9 added-9 removed
49 unmodified lines50 PerformRequest(r, method, "/test2")51 assert.True(t, passedAny)52 }53 54-// TestSingleRouteOK tests that POST route is correctly invoked.54+// testRouteNotOK tests that a request with the wrong method returns a not found response.55 func testRouteNotOK(method string, t *testing.T) {56 passed := false57 router := New()58 router.Handle(method, "/test_2", func(c *Context) {5 unmodified lines64 assert.False(t, passed)65 assert.Equal(t, http.StatusNotFound, w.Code)66 }67 68-// TestSingleRouteOK tests that POST route is correctly invoked.68+// testRouteNotOK2 tests that a request with the wrong method returns a method not allowed response.69 func testRouteNotOK2(method string, t *testing.T) {70 passed := false71 router := New()72 router.HandleMethodNotAllowed = true199 unmodified lines272 assert.Equal(t, "/Path4/", w.Header().Get("Location"))273 assert.Equal(t, http.StatusTemporaryRedirect, w.Code)274 }275 276-// TestContextParamsGet tests that a parameter can be parsed from the URL.276+// TestRouteParamsByName tests that route parameters can be parsed by name.277 func TestRouteParamsByName(t *testing.T) {278 name := ""279 lastName := ""280 wild := ""23 unmodified lines304 assert.Equal(t, "smith", lastName)305 assert.Equal(t, "/is/super/great", wild)306 }307 308-// TestContextParamsGet tests that a parameter can be parsed from the URL even with extra slashes.308+// TestRouteParamsByNameWithExtraSlash tests that route parameters can be parsed by name even with extra slashes.309 func TestRouteParamsByNameWithExtraSlash(t *testing.T) {310 name := ""311 lastName := ""312 wild := ""63 unmodified lines376 assert.Equal(t, "smith", lastName)377 assert.Equal(t, "/is/super/great", wild)378 }379 380-// TestHandleStaticFile - ensure the static file handles properly380+// TestRouteStaticFile tests that a static file is served correctly.381 func TestRouteStaticFile(t *testing.T) {382 // SETUP file383 testRoot, _ := os.Getwd()384 f, err := os.CreateTemp(testRoot, "")26 unmodified lines411 assert.Equal(t, w3, w4)412 assert.Equal(t, http.StatusOK, w3.Code)413 }414 415-// TestHandleStaticFile - ensure the static file handles properly415+// TestRouteStaticFileFS tests that a static file from an http.FileSystem is served correctly.416 func TestRouteStaticFileFS(t *testing.T) {417 // SETUP file418 testRoot, _ := os.Getwd()419 f, err := os.CreateTemp(testRoot, "")25 unmodified lines445 assert.Equal(t, w3, w4)446 assert.Equal(t, http.StatusOK, w3.Code)447 }448 449-// TestHandleStaticDir - ensure the root/sub dir handles properly449+// TestRouteStaticListingDir tests that static directory listing is enabled when configured.450 func TestRouteStaticListingDir(t *testing.T) {451 router := New()452 router.StaticFS("/", Dir("./", true))453 3 unmodified lines457 assert.Contains(t, w.Body.String(), "gin.go")458 assert.Equal(t, "text/html; charset=utf-8", w.Header().Get("Content-Type"))459 }460 461-// TestHandleHeadToDir - ensure the root/sub dir handles properly461+// TestRouteStaticNoListing tests that static directory listing is disabled by default.462 func TestRouteStaticNoListing(t *testing.T) {463 router := New()464 router.Static("/", "./")465 189 unmodified lines655 PerformRequest(router, http.MethodGet, "/nonexistent")656 })657 }658 659-// Reproduction test for the bug of issue #1805659+// TestMiddlewareCalledOnceByRouterStaticFSNotFound reproduces the bug reported in issue #1805.660 func TestMiddlewareCalledOnceByRouterStaticFSNotFound(t *testing.T) {661 router := New()662 663 // Middleware must be called just only once by per request.128 unmodified linesmodified:tree.go+3 added-3 removed
105 unmodified lines106 handlers HandlersChain107 fullPath string108 }109 110-// Increments priority of the given child and reorders if necessary110+// incrementChildPrio increments the priority of the given child and reorders it if necessary.111 func (n *node) incrementChildPrio(pos int) int {112 cs := n.children113 cs[pos].priority++114 prio := cs[pos].priority567 unmodified lines682 683 return ciPath, ciPath != nil684 }685 686-// Shift bytes in array by n bytes left686+// shiftNRuneBytes shifts bytes in the array n positions to the left.687 func shiftNRuneBytes(rb [4]byte, n int) [4]byte {688 switch n {689 case 0:690 return rb7 unmodified lines698 return [4]byte{}699 }700 }701 702-// Recursive case-insensitive lookup function used by n.findCaseInsensitivePath702+// findCaseInsensitivePathRec recursively performs a case-insensitive path lookup.703 func (n *node) findCaseInsensitivePathRec(path string, ciPath []byte, rb [4]byte, fixTrailingSlash bool) []byte {704 npLen := len(n.path)705 706 walk: // Outer loop for walking the tree244 unmodified linesmodified:utils.go+2 added-1 removed
159 unmodified lines160 panic("too many parameters")161 }162 }163 164-// https://stackoverflow.com/questions/53069040/checking-a-string-contains-only-ascii-characters164+// isASCII reports whether s contains only ASCII characters.165+// See https://stackoverflow.com/questions/53069040/checking-a-string-contains-only-ascii-characters.166 func isASCII(s string) bool {167 for i := range len(s) {168 if s[i] > unicode.MaxASCII {169 return false20 unmodified lines