示例#1
0
func TestSimpleTemplate(t *testing.T) {
	pub := testutils.NewPublisher()
	s := core.NewTree("test", pub).Slot()

	tpl := MustParseTemplate("foo{{.Data}}bar").New(s)

	if exp, got := "foobar", testutils.Render(s.Node()); exp != got {
		t.Errorf("Expected %q, got %q", exp, got)
	}

	tpl.SetData(314)

	if pub.Last("test") != "foo314bar" {
		t.Errorf("Expected update with content 'foo314bar'; published:\n%s", pub.Dump())
	}
	if exp, got := "foo314bar", testutils.Render(s.Node()); exp != got {
		t.Errorf("Expected %q, got %q", exp, got)
	}
}
示例#2
0
func TestNestedTemplate(t *testing.T) {
	pub := testutils.NewPublisher()
	s := core.NewTree("test", pub).Slot()

	tpl := MustParseTemplate(`{{slot "foo" "span"}}`).New(s)

	if exp, got := `<span id='test-foo'></span>`, testutils.Render(s.Node()); exp != got {
		t.Errorf("Expected %q, got %q", exp, got)
	}

	tpl.Slot("foo").Set("bar")

	if pub.Last("test-foo") != "bar" {
		t.Errorf("Expected update with content 'bar'; published:\n%s", pub.Dump())
	}
	if exp, got := `<span id='test-foo'>bar</span>`, testutils.Render(s.Node()); exp != got {
		t.Errorf("Expected %q, got %q", exp, got)
	}
}
示例#3
0
func TestBasicNode(t *testing.T) {
	pub := testutils.NewPublisher()
	s := core.NewTree("test", pub).Slot()
	s.Set("foobar")
	n := s.Node()

	if exp, got := "foobar", testutils.Render(n); exp != got {
		t.Errorf("Expected %q, got %q", exp, got)
	}

	if pub.Last("test") != "foobar" {
		t.Errorf("Expected update with content 'foobar'; published:\n%s", pub.Dump())
	}
}
示例#4
0
func TestCustomRenderer(t *testing.T) {
	pub := testutils.NewPublisher()
	s := core.NewTree("test", pub).Slot()
	core.NewConst(s, "other")
	n := s.Node()

	if exp, got := "other", testutils.Render(n); exp != got {
		t.Errorf("Expected %q, got %q", exp, got)
	}

	if pub.Last("test") != "other" {
		t.Errorf("Expected update with content 'other'; published:\n%s", pub.Dump())
	}

}
示例#5
0
func TestPageRender(t *testing.T) {
	s := core.NewTree("test", testutils.NewPublisher()).Slot()
	page := NewPage(s)

	page.SetTitle("footitle")
	page.Body().Set("foobody")
	page.CSS("bar").Set("foocss")

	content := testutils.Render(s.Node())
	for _, s := range []string{"footitle", "foobody", "foocss"} {
		if !strings.Contains(content, s) {
			t.Errorf("Rendered page should have contained %q; generated content:\n%s", s, content)
		}
	}
}