HELLO·Android
系统源代码
IT资讯
技术文章
我的收藏
注册
登录
-
我收藏的文章
创建代码块
我的代码块
我的账号
Pie
|
9.0.0_r8
下载
查看原文件
收藏
根目录
prebuilts
go
darwin-x86
src
html
template
template_test.go
// Copyright 2016 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package template_test import ( "bytes" . "html/template" "strings" "testing" ) func TestTemplateClone(t *testing.T) { // https://golang.org/issue/12996 orig := New("name") clone, err := orig.Clone() if err != nil { t.Fatal(err) } if len(clone.Templates()) != len(orig.Templates()) { t.Fatalf("Invalid length of t.Clone().Templates()") } const want = "stuff" parsed := Must(clone.Parse(want)) var buf bytes.Buffer err = parsed.Execute(&buf, nil) if err != nil { t.Fatal(err) } if got := buf.String(); got != want { t.Fatalf("got %q; want %q", got, want) } } func TestRedefineNonEmptyAfterExecution(t *testing.T) { c := newTestCase(t) c.mustParse(c.root, `foo`) c.mustExecute(c.root, nil, "foo") c.mustNotParse(c.root, `bar`) } func TestRedefineEmptyAfterExecution(t *testing.T) { c := newTestCase(t) c.mustParse(c.root, ``) c.mustExecute(c.root, nil, "") c.mustNotParse(c.root, `foo`) c.mustExecute(c.root, nil, "") } func TestRedefineAfterNonExecution(t *testing.T) { c := newTestCase(t) c.mustParse(c.root, `{{if .}}<{{template "X"}}>{{end}}{{define "X"}}foo{{end}}`) c.mustExecute(c.root, 0, "") c.mustNotParse(c.root, `{{define "X"}}bar{{end}}`) c.mustExecute(c.root, 1, "<foo>") } func TestRedefineAfterNamedExecution(t *testing.T) { c := newTestCase(t) c.mustParse(c.root, `<{{template "X" .}}>{{define "X"}}foo{{end}}`) c.mustExecute(c.root, nil, "<foo>") c.mustNotParse(c.root, `{{define "X"}}bar{{end}}`) c.mustExecute(c.root, nil, "<foo>") } func TestRedefineNestedByNameAfterExecution(t *testing.T) { c := newTestCase(t) c.mustParse(c.root, `{{define "X"}}foo{{end}}`) c.mustExecute(c.lookup("X"), nil, "foo") c.mustNotParse(c.root, `{{define "X"}}bar{{end}}`) c.mustExecute(c.lookup("X"), nil, "foo") } func TestRedefineNestedByTemplateAfterExecution(t *testing.T) { c := newTestCase(t) c.mustParse(c.root, `{{define "X"}}foo{{end}}`) c.mustExecute(c.lookup("X"), nil, "foo") c.mustNotParse(c.lookup("X"), `bar`) c.mustExecute(c.lookup("X"), nil, "foo") } func TestRedefineSafety(t *testing.T) { c := newTestCase(t) c.mustParse(c.root, `
{{define "X"}}{{end}}`) c.mustExecute(c.root, nil, `
`) // Note: Every version of Go prior to Go 1.8 accepted the redefinition of "X" // on the next line, but luckily kept it from being used in the outer template. // Now we reject it, which makes clearer that we're not going to use it. c.mustNotParse(c.root, `{{define "X"}}" bar="baz{{end}}`) c.mustExecute(c.root, nil, `
`) } func TestRedefineTopUse(t *testing.T) { c := newTestCase(t) c.mustParse(c.root, `{{template "X"}}{{.}}{{define "X"}}{{end}}`) c.mustExecute(c.root, 42, `42`) c.mustNotParse(c.root, `{{define "X"}}
登录后可以享受更多权益
您还没有登录,登录后您可以:
收藏Android系统代码
收藏喜欢的文章
多个平台共享账号
去登录
首次使用?从这里
注册