Skip to content
Myr

refactor(struct): Remove redundant type conversions (#3345)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by hopehook · committed by GitHub · parent 45c758e · Browse files · 3 files+7 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+7 added−11 removed

  • other:+7 added−11 removed

3 files+7 added−11 removed

modified:binding/binding_test.go+2 added-6 removed
1105 unmodified lines
1106 assert.NoError(t, err)1107 assert.Equal(t,1108 struct {1109 Idx int "form:\"idx\""1110 }(struct {1111 Idx int "form:\"idx\""1112 }{Idx: 123}),1110 }{Idx: 123},1111 obj.StructFoo)1112 case "StructPointer":1113 obj := FooStructForStructPointerType{}1114 err := b.Bind(req, &obj)1115 assert.NoError(t, err)1116 assert.Equal(t,1117 struct {1118 Name string "form:\"name\""1121 }(struct {1122 Name string "form:\"name\""1123 }{Name: "thinkerou"}),1119 }{Name: "thinkerou"},1120 *obj.StructPointerFoo)1121 case "Map":1122 obj := FooStructForMapType{}1123 err := b.Bind(req, &obj)
249 unmodified lines
modified:binding/form_mapping_test.go+4 added-4 removed
112 unmodified lines
113 f int `form:"field"`114 }115 err := mappingByPtr(&s, formSource{"field": {"6"}}, "form")116 assert.NoError(t, err)117 assert.Equal(t, int(0), s.f)117 assert.Equal(t, 0, s.f)118}119120func TestMappingUnknownFieldType(t *testing.T) {121 var s struct {
10 unmodified lines
132 F int `uri:"field"`133 }134 err := mapURI(&s, map[string][]string{"field": {"6"}})135 assert.NoError(t, err)136 assert.Equal(t, int(6), s.F)136 assert.Equal(t, 6, s.F)137}138139func TestMappingForm(t *testing.T) {140 var s struct {141 F int `form:"field"`142 }143 err := mapForm(&s, map[string][]string{"field": {"6"}})144 assert.NoError(t, err)145 assert.Equal(t, int(6), s.F)145 assert.Equal(t, 6, s.F)146}147148func TestMapFormWithTag(t *testing.T) {149 var s struct {150 F int `externalTag:"field"`151 }152 err := MapFormWithTag(&s, map[string][]string{"field": {"6"}}, "externalTag")153 assert.NoError(t, err)154 assert.Equal(t, int(6), s.F)154 assert.Equal(t, 6, s.F)155}156157func TestMappingTime(t *testing.T) {158 var s struct {
132 unmodified lines
modified:render/render_test.go+1 added-1 removed
171 unmodified lines
172 assert.Equal(t, "{\"lang\":\"GO\\u8bed\\u8a00\",\"tag\":\"\\u003cbr\\u003e\"}", w1.Body.String())173 assert.Equal(t, "application/json", w1.Header().Get("Content-Type"))174175 w2 := httptest.NewRecorder()176 data2 := float64(3.1415926)176 data2 := 3.1415926177178 err = (AsciiJSON{data2}).Render(w2)179 assert.NoError(t, err)180 assert.Equal(t, "3.1415926", w2.Body.String())
332 unmodified lines