Skip to content
Myr

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

6 files+19 added−16 removed

modified:render/render_test.go+2 added-2 removed
281 unmodified lines
282}283284type xmlmap map[string]any285286// Allows type H to be used with xml.Marshal286// MarshalXML allows xmlmap to be used with xml.Marshal.287func (h xmlmap) MarshalXML(e *xml.Encoder, start xml.StartElement) error {288 start.Name = xml.Name{289 Space: "",290 Local: "map",
39 unmodified lines
330}331332type fail struct{}333334// Hook MarshalYAML334// MarshalYAML returns an error for YAML rendering failure tests.335func (ft *fail) MarshalYAML() (any, error) {336 return nil, errors.New("fail")337}338
479 unmodified lines
modified:gin_integration_test.go+1 added
23 unmodified lines
24 "github.com/stretchr/testify/assert"25 "github.com/stretchr/testify/require"26)2728// 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"32func testRequest(t *testing.T, params ...string) {
576 unmodified lines
modified:response_writer_test.go+2 added-1 removed
218 unmodified lines
219 })220 }221}222223// 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.225func TestResponseWriterHijackAfterWriteHeaderNow(t *testing.T) {226 tests := []struct {227 name string228 action func(w ResponseWriter) error
116 unmodified lines
modified:routes_test.go+9 added-9 removed
49 unmodified lines
50 PerformRequest(r, method, "/test2")51 assert.True(t, passedAny)52}5354// TestSingleRouteOK tests that POST route is correctly invoked.54// testRouteNotOK tests that a request with the wrong method returns a not found response.55func testRouteNotOK(method string, t *testing.T) {56 passed := false57 router := New()58 router.Handle(method, "/test_2", func(c *Context) {
5 unmodified lines
64 assert.False(t, passed)65 assert.Equal(t, http.StatusNotFound, w.Code)66}6768// TestSingleRouteOK tests that POST route is correctly invoked.68// testRouteNotOK2 tests that a request with the wrong method returns a method not allowed response.69func testRouteNotOK2(method string, t *testing.T) {70 passed := false71 router := New()72 router.HandleMethodNotAllowed = true
199 unmodified lines
272 assert.Equal(t, "/Path4/", w.Header().Get("Location"))273 assert.Equal(t, http.StatusTemporaryRedirect, w.Code)274}275276// TestContextParamsGet tests that a parameter can be parsed from the URL.276// TestRouteParamsByName tests that route parameters can be parsed by name.277func TestRouteParamsByName(t *testing.T) {278 name := ""279 lastName := ""280 wild := ""
23 unmodified lines
304 assert.Equal(t, "smith", lastName)305 assert.Equal(t, "/is/super/great", wild)306}307308// 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.309func TestRouteParamsByNameWithExtraSlash(t *testing.T) {310 name := ""311 lastName := ""312 wild := ""
63 unmodified lines
376 assert.Equal(t, "smith", lastName)377 assert.Equal(t, "/is/super/great", wild)378}379380// TestHandleStaticFile - ensure the static file handles properly380// TestRouteStaticFile tests that a static file is served correctly.381func TestRouteStaticFile(t *testing.T) {382 // SETUP file383 testRoot, _ := os.Getwd()384 f, err := os.CreateTemp(testRoot, "")
26 unmodified lines
411 assert.Equal(t, w3, w4)412 assert.Equal(t, http.StatusOK, w3.Code)413}414415// TestHandleStaticFile - ensure the static file handles properly415// TestRouteStaticFileFS tests that a static file from an http.FileSystem is served correctly.416func TestRouteStaticFileFS(t *testing.T) {417 // SETUP file418 testRoot, _ := os.Getwd()419 f, err := os.CreateTemp(testRoot, "")
25 unmodified lines
445 assert.Equal(t, w3, w4)446 assert.Equal(t, http.StatusOK, w3.Code)447}448449// TestHandleStaticDir - ensure the root/sub dir handles properly449// TestRouteStaticListingDir tests that static directory listing is enabled when configured.450func TestRouteStaticListingDir(t *testing.T) {451 router := New()452 router.StaticFS("/", Dir("./", true))453
3 unmodified lines
457 assert.Contains(t, w.Body.String(), "gin.go")458 assert.Equal(t, "text/html; charset=utf-8", w.Header().Get("Content-Type"))459}460461// TestHandleHeadToDir - ensure the root/sub dir handles properly461// TestRouteStaticNoListing tests that static directory listing is disabled by default.462func TestRouteStaticNoListing(t *testing.T) {463 router := New()464 router.Static("/", "./")465
189 unmodified lines
655 PerformRequest(router, http.MethodGet, "/nonexistent")656 })657}658659// Reproduction test for the bug of issue #1805659// TestMiddlewareCalledOnceByRouterStaticFSNotFound reproduces the bug reported in issue #1805.660func TestMiddlewareCalledOnceByRouterStaticFSNotFound(t *testing.T) {661 router := New()662663 // Middleware must be called just only once by per request.
128 unmodified lines
modified:tree.go+3 added-3 removed
105 unmodified lines
106 handlers HandlersChain107 fullPath string108}109110// Increments priority of the given child and reorders if necessary110// incrementChildPrio increments the priority of the given child and reorders it if necessary.111func (n *node) incrementChildPrio(pos int) int {112 cs := n.children113 cs[pos].priority++114 prio := cs[pos].priority
567 unmodified lines
682683 return ciPath, ciPath != nil684}685686// Shift bytes in array by n bytes left686// shiftNRuneBytes shifts bytes in the array n positions to the left.687func shiftNRuneBytes(rb [4]byte, n int) [4]byte {688 switch n {689 case 0:690 return rb
7 unmodified lines
698 return [4]byte{}699 }700}701702// Recursive case-insensitive lookup function used by n.findCaseInsensitivePath702// findCaseInsensitivePathRec recursively performs a case-insensitive path lookup.703func (n *node) findCaseInsensitivePathRec(path string, ciPath []byte, rb [4]byte, fixTrailingSlash bool) []byte {704 npLen := len(n.path)705706walk: // Outer loop for walking the tree
244 unmodified lines
modified:utils.go+2 added-1 removed
159 unmodified lines
160 panic("too many parameters")161 }162}163164// 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.166func isASCII(s string) bool {167 for i := range len(s) {168 if s[i] > unicode.MaxASCII {169 return false
20 unmodified lines