-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathform_template_test.go
111 lines (104 loc) · 2.66 KB
/
form_template_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package engine
import (
"strings"
"testing"
"github.com/Masterminds/engine/form"
"golang.org/x/net/html"
)
func TestFormTemplate(t *testing.T) {
e, err := New("_template")
if err != nil {
t.Errorf("Failed to load templates: %s", err)
}
f := form.New("name", "form-action")
f.Id = "1234"
f.Lang = "en-us"
f.Title = "Login"
f.Hidden = form.OFalse
f.Class = []string{"foo", "bar", "baz"}
f.Method = "POST"
f.Autocomplete = true
f.Fields = []form.Field{
&form.Button{
HTML: form.HTML{Id: "button-1"},
Name: "button-1",
Value: "Push Me!",
},
&form.FieldSet{
Name: "fset1",
Legend: "Look, Ma! A Fieldset!",
Fields: []form.Field{
&form.Button{
HTML: form.HTML{Id: "button-2"},
Name: "button-2",
Value: "Push Me Too!",
},
},
},
&form.Keygen{
Name: "keygen",
KeyType: "rsa",
Challenge: "How much would could a wood chuck chuck?",
},
&form.Label{For: "ever", Text: "Don't Label Me"},
&form.Output{For: "your eyes only", Name: "Bond, James Bond"},
&form.Progress{Value: 0.5, Max: 1.0},
&form.Meter{Value: 0.5, Max: 1.0, Min: 0.2, Optimum: 0.7, Low: 0.1, High: 0.5},
&form.DataList{
HTML: form.HTML{Id: "dl-1"},
Options: []*form.Option{
&form.Option{Value: "one", Label: "One"},
&form.Option{Value: "two", Label: "Two"},
},
},
&form.Select{
Name: "cookies",
Label: "How many cookies?",
Options: []form.OptionItem{
&form.Option{Value: "one", Label: "One"},
&form.Option{Value: "two", Label: "Two"},
&form.OptGroup{
Label: "optgroup",
Options: []*form.Option{
&form.Option{Value: "three", Label: "Three"},
&form.Option{Value: "four", Label: "Four"},
},
},
},
},
&form.TextArea{
Name: "textarea",
Cols: 80,
Rows: 5,
Value: "Default text",
},
&form.Password{Name: "password", Label: "Enter Password"},
&form.Text{Name: "text"},
&form.Submit{Name: "submit"},
&form.Tel{Name: "tel"},
&form.URL{Name: "url"},
&form.Email{Name: "email"},
&form.Date{Name: "date"},
&form.Time{Name: "time"},
&form.Number{Name: "number"},
&form.Range{Name: "range"},
&form.Color{Name: "color"},
&form.Checkbox{Name: "checkbox"},
&form.Radio{Name: "radio"},
&form.File{Name: "file"},
&form.Image{Name: "image"},
&form.Reset{Name: "reset"},
&form.Hidden{Name: "hidden"},
}
out, err := e.Render("#form", f)
if err != nil {
t.Errorf("Failed render of form.html.tpl: %s", err)
}
t.Log(out)
// Now we load the result with an HTML parser to ensure that it's
// well-formed.
read := strings.NewReader(out)
if _, err := html.Parse(read); err != nil {
t.Errorf("Failed to parse generated markup: %s", err)
}
}