else
(t *testing.T)
| 197 | |
| 198 | // else |
| 199 | func TestBinder_Bind_default(t *testing.T) { |
| 200 | |
| 201 | binder := newBinder() |
| 202 | |
| 203 | if binder == nil { |
| 204 | t.Error("binder can not be nil!") |
| 205 | } |
| 206 | |
| 207 | // init DotServer |
| 208 | app := New() |
| 209 | |
| 210 | if app == nil { |
| 211 | t.Error("app can not be nil!") |
| 212 | } |
| 213 | |
| 214 | // expected |
| 215 | expected := &Person{ |
| 216 | Hair: "Brown", |
| 217 | HasGlass: true, |
| 218 | Age: 10, |
| 219 | Legs: []string{"Left", "Right"}, |
| 220 | } |
| 221 | param := &InitContextParam{ |
| 222 | t, |
| 223 | expected, |
| 224 | "", |
| 225 | test.ToDefault, |
| 226 | } |
| 227 | |
| 228 | // init param |
| 229 | context := initContext(param) |
| 230 | |
| 231 | form := make(map[string][]string) |
| 232 | form["Hair"] = []string{"Brown"} |
| 233 | form["HasGlass"] = []string{"true"} |
| 234 | form["Age"] = []string{"10"} |
| 235 | form["Legs"] = []string{"Left", "Right"} |
| 236 | |
| 237 | context.request.Form = form |
| 238 | // actual |
| 239 | person := &Person{} |
| 240 | |
| 241 | err := binder.Bind(person, context) |
| 242 | |
| 243 | // check error must nil |
| 244 | test.Nil(t, err) |
| 245 | |
| 246 | // check expected |
| 247 | test.Equal(t, expected, person) |
| 248 | |
| 249 | t.Log("person:", person) |
| 250 | t.Log("expected:", expected) |
| 251 | |
| 252 | } |
| 253 | |
| 254 | // else |
| 255 | func TestBinder_Bind_default_error(t *testing.T) { |