예제 #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
파일: node_test.go 프로젝트: Palats/stdweb
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
파일: node_test.go 프로젝트: Palats/stdweb
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
파일: page_test.go 프로젝트: Palats/stdweb
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)
		}
	}
}