Making assertions about TemplatePage
assignment
This commit is contained in:
parent
dcb060b246
commit
8314d97ade
@ -19,6 +19,7 @@ type Simplate struct {
|
||||
ContentType string
|
||||
InitPage *SimplatePage
|
||||
LogicPages []*SimplatePage
|
||||
TemplatePage *SimplatePage
|
||||
}
|
||||
|
||||
type SimplatePage struct {
|
||||
@ -35,20 +36,28 @@ func SimplateFromString(filename, content string) *Simplate {
|
||||
ContentType: mime.TypeByExtension(path.Ext(filename)),
|
||||
}
|
||||
|
||||
if nbreaks == 1 && s.ContentType == "application/json" {
|
||||
s.Type = SIMPLATE_TYPE_JSON
|
||||
return s
|
||||
}
|
||||
|
||||
if nbreaks == 2 {
|
||||
s.Type = SIMPLATE_TYPE_RENDERED
|
||||
if nbreaks == 1 || nbreaks == 2 {
|
||||
s.InitPage = &SimplatePage{Body: rawPages[0]}
|
||||
s.LogicPages = append(s.LogicPages, &SimplatePage{Body: rawPages[1]})
|
||||
|
||||
if s.ContentType == "application/json" {
|
||||
s.Type = SIMPLATE_TYPE_JSON
|
||||
} else {
|
||||
s.Type = SIMPLATE_TYPE_RENDERED
|
||||
s.TemplatePage = &SimplatePage{Body: rawPages[2]}
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
if nbreaks > 2 {
|
||||
s.Type = SIMPLATE_TYPE_NEGOTIATED
|
||||
s.InitPage = &SimplatePage{Body: rawPages[0]}
|
||||
|
||||
for _, rawPage := range rawPages {
|
||||
s.LogicPages = append(s.LogicPages, &SimplatePage{Body: rawPage})
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
|
@ -138,3 +138,54 @@ func TestAssignsOneLogicPageToRenderedSimplates(t *testing.T) {
|
||||
"of logic pages assigned!: %v", len(s.LogicPages))
|
||||
}
|
||||
}
|
||||
|
||||
func TestAssignsOneTemplatePageToRenderedSimplates(t *testing.T) {
|
||||
s := SimplateFromString("basic-rendered.txt", BASIC_RENDERED_TXT_SIMPLATE)
|
||||
if s.TemplatePage == nil {
|
||||
t.Errorf("Rendered simplate had no template page assigned!: %v", s.TemplatePage)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAssignsAnInitPageToJSONSimplates(t *testing.T) {
|
||||
s := SimplateFromString("basic.json", BASIC_JSON_SIMPLATE)
|
||||
if s.InitPage == nil {
|
||||
t.Errorf("JSON simplate had no init page assigned!: %v", s.InitPage)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAssignsOneLogicPageToJSONSimplates(t *testing.T) {
|
||||
s := SimplateFromString("basic.json", BASIC_JSON_SIMPLATE)
|
||||
if len(s.LogicPages) != 1 {
|
||||
t.Errorf("Rendered simplate unexpected number "+
|
||||
"of logic pages assigned!: %v", len(s.LogicPages))
|
||||
}
|
||||
}
|
||||
|
||||
func TestAssignsNoTemplatePageToJSONSimplates(t *testing.T) {
|
||||
s := SimplateFromString("basic.json", BASIC_JSON_SIMPLATE)
|
||||
if s.TemplatePage != nil {
|
||||
t.Errorf("JSON simplate had a template page assigned!: %v", s.TemplatePage)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAssignsAnInitPageToNegotiatedSimplates(t *testing.T) {
|
||||
s := SimplateFromString("basic-negotiated.txt", BASIC_NEGOTIATED_SIMPLATE)
|
||||
if s.InitPage == nil {
|
||||
t.Errorf("Negotiated simplate had no init page assigned!: %v", s.InitPage)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAssignsAtLeastOneLogicPageToNegotiatedSimplates(t *testing.T) {
|
||||
s := SimplateFromString("basic-negotiated.txt", BASIC_NEGOTIATED_SIMPLATE)
|
||||
if len(s.LogicPages) < 1 {
|
||||
t.Errorf("Negotiated simplate unexpected number "+
|
||||
"of logic pages assigned!: %v", len(s.LogicPages))
|
||||
}
|
||||
}
|
||||
|
||||
func TestAssignsNoTemplatePageToNegotiatedSimplates(t *testing.T) {
|
||||
s := SimplateFromString("basic-negotiated.txt", BASIC_NEGOTIATED_SIMPLATE)
|
||||
if s.TemplatePage != nil {
|
||||
t.Errorf("Negotiated simplate had a template page assigned!: %v", s.TemplatePage)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user