More assertions about simplate parsing
beyond simple type detection.
This commit is contained in:
parent
f61d845eca
commit
dcb060b246
@ -17,10 +17,17 @@ type Simplate struct {
|
||||
Filename string
|
||||
Type string
|
||||
ContentType string
|
||||
InitPage *SimplatePage
|
||||
LogicPages []*SimplatePage
|
||||
}
|
||||
|
||||
type SimplatePage struct {
|
||||
Body string
|
||||
}
|
||||
|
||||
func SimplateFromString(filename, content string) *Simplate {
|
||||
nbreaks := strings.Count(content, "")
|
||||
rawPages := strings.Split(content, "")
|
||||
nbreaks := len(rawPages) - 1
|
||||
|
||||
s := &Simplate{
|
||||
Filename: filename,
|
||||
@ -35,6 +42,8 @@ func SimplateFromString(filename, content string) *Simplate {
|
||||
|
||||
if nbreaks == 2 {
|
||||
s.Type = SIMPLATE_TYPE_RENDERED
|
||||
s.InitPage = &SimplatePage{Body: rawPages[0]}
|
||||
s.LogicPages = append(s.LogicPages, &SimplatePage{Body: rawPages[1]})
|
||||
return s
|
||||
}
|
||||
|
||||
|
@ -18,12 +18,12 @@ type Dance struct {
|
||||
When time.Time
|
||||
}
|
||||
|
||||
d := &Dance{
|
||||
D := &Dance{
|
||||
Who: "Everybody",
|
||||
When: time.Now(),
|
||||
}
|
||||
|
||||
{{d.Who}} Dance {{d.When}}!
|
||||
{{.D.Who}} Dance {{.D.When}}!
|
||||
`
|
||||
BASIC_STATIC_TXT_SIMPLATE = `
|
||||
Everybody Dance Now!
|
||||
@ -38,11 +38,11 @@ type Dance struct {
|
||||
When time.Time
|
||||
}
|
||||
|
||||
d := &Dance{
|
||||
D := &Dance{
|
||||
Who: "Everybody",
|
||||
When: time.Now(),
|
||||
}
|
||||
response.SetBody(d)
|
||||
response.SetBody(D)
|
||||
`
|
||||
BASIC_NEGOTIATED_SIMPLATE = `
|
||||
import (
|
||||
@ -54,15 +54,15 @@ type Dance struct {
|
||||
When time.Time
|
||||
}
|
||||
|
||||
d := &Dance{
|
||||
D := &Dance{
|
||||
Who: "Everybody",
|
||||
When: time.Now(),
|
||||
}
|
||||
text/plain
|
||||
{{d.Who}} Dance {{d.When}}!
|
||||
{{.D.Who}} Dance {{.D.When}}!
|
||||
|
||||
application/json
|
||||
{"who":"{{d.Who}}","when":"{{d.When}}"}
|
||||
{"who":"{{.D.Who}}","when":"{{.D.When}}"}
|
||||
`
|
||||
)
|
||||
|
||||
@ -112,3 +112,29 @@ func TestDetectsNegotiatedSimplates(t *testing.T) {
|
||||
s.Type, SIMPLATE_TYPE_NEGOTIATED)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAssignsNoGoPagesToStaticSimplates(t *testing.T) {
|
||||
s := SimplateFromString("basic-static.txt", BASIC_STATIC_TXT_SIMPLATE)
|
||||
if s.InitPage != nil {
|
||||
t.Errorf("Static simplate had init page assigned!: %v", s.InitPage)
|
||||
}
|
||||
|
||||
if len(s.LogicPages) > 0 {
|
||||
t.Errorf("Static simplate had logic pages assigned!: %v", s.LogicPages)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAssignsAnInitPageToRenderedSimplates(t *testing.T) {
|
||||
s := SimplateFromString("basic-rendered.txt", BASIC_RENDERED_TXT_SIMPLATE)
|
||||
if s.InitPage == nil {
|
||||
t.Errorf("Rendered simplate had no init page assigned!: %v", s.InitPage)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAssignsOneLogicPageToRenderedSimplates(t *testing.T) {
|
||||
s := SimplateFromString("basic-rendered.txt", BASIC_RENDERED_TXT_SIMPLATE)
|
||||
if len(s.LogicPages) != 1 {
|
||||
t.Errorf("Rendered simplate unexpected number "+
|
||||
"of logic pages assigned!: %v", len(s.LogicPages))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user