func TestUrlEncoderForm(t *testing.T) { path := "/cars/UHPHs2-Q6Q7Ey1gJ/comments/flame" query := Values{} query.Add("favourites", "true") query.Add("1fake", "11") route, err := lang.NewRoute(path, query) if err != nil { t.Fatal() } speaker := MockSpeaker{} sentence, err := lang.NewSentence(route, speaker) if err != nil { t.Fatal() } if sentence.Verb != "Flame" && sentence.Noun != "comments" { t.Fatal() } urle := lang.NewURLEncoder(route, sentence) form := urle.Form("whatever-action") if form.KeyPrefix != "1" { t.Fatal(form.KeyPrefix) } if len(form.FilterFields) != 2 || form.FilterFields["favourites"] != "true" || form.FilterFields["1fake"] != "11" { t.Fatal() } if form.ActionPath != "cars/UHPHs2-Q6Q7Ey1gJ/comments/whatever-action" { t.Fatal() } }
func TestURLEncoderUrlNonGet(t *testing.T) { path := "/cars/ignite" query := Values{} query.Add("favourites", "true") query.Add("1fake", "11") route, err := lang.NewRoute(path, query) if err != nil { t.Fatal() } speaker := MockSpeaker{} sentence, err := lang.NewSentence(route, speaker) if err != nil { t.Fatal() } if sentence.Verb != "Ignite" { t.Fatal() } urle := lang.NewURLEncoder(route, sentence) u1 := Values{} u1.Add("color", "red") u1.Add("color", "blue") u1.Add("quality", "very high") path, merged := urle.Url("paint", u1) if path != "cars/paint" { t.Fatal() } if merged["favourites"] != "true" || merged["1color"].([]interface{})[0] != "red" || merged["1color"].([]interface{})[1] != "blue" || merged["1quality"] != "very high" { t.Fatal() } }
func _url(action_name string, r *lang.Route, s *lang.Sentence, i ...interface{}) string { f := lang.NewURLEncoder(r, s) if len(i)%2 == 1 { panic("Must be even.") } inp := convert.ListToMap(i...) return f.UrlString(action_name, inp) }
func TestUrlEncoderForm1(t *testing.T) { path := "/cars/ignite" query := Values{} route, err := lang.NewRoute(path, query) if err != nil { t.Fatal() } speaker := MockSpeaker{} sentence, err := lang.NewSentence(route, speaker) if err != nil { t.Fatal() } urle := lang.NewURLEncoder(route, sentence) form := urle.Form("whatever-action") if form.KeyPrefix != "1" { t.Fatal(form.KeyPrefix) } }
func form(action_name string, r *lang.Route, s *lang.Sentence) *Form { f := lang.NewURLEncoder(r, s).Form(action_name) return &Form{f} }