Beispiel #1
0
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()
	}
}
Beispiel #2
0
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(path)
	}
	if merged["favourites"] != "true" || merged["1color"].([]interface{})[0] != "red" || merged["1color"].([]interface{})[1] != "blue" || merged["1quality"] != "very high" {
		t.Fatal(merged)
	}
}
Beispiel #3
0
func (h *HighLev) Sub(actionOrNoun string, p map[string]interface{}) (*HighLev, error) {
	form := lang.NewURLEncoder(h.desc.Route, h.desc.Sentence).Form(actionOrNoun)
	params := form.FilterFields
	for i, v := range p {
		params[form.KeyPrefix+i] = v
	}
	return New(h.hooks, form.ActionPath, h.nouns, params)
}
Beispiel #4
0
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)
	}
}
Beispiel #5
0
func (h *HighLev) URLE() *lang.URLEncoder {
	return lang.NewURLEncoder(h.desc.Route, h.desc.Sentence)
}