gf/os/gview/gview_unit_encode_test.go

43 lines
1.1 KiB
Go

// Copyright 2020 gf Author(https://github.com/gogf/gf). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package gview_test
import (
"github.com/gogf/gf/debug/gdebug"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/gfile"
"github.com/gogf/gf/os/gview"
"github.com/gogf/gf/test/gtest"
"testing"
)
func Test_Encode_Parse(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
v := gview.New()
v.SetPath(gdebug.TestDataPath("tpl"))
v.SetAutoEncode(true)
result, err := v.Parse("encode.tpl", g.Map{
"title": "<b>my title</b>",
})
t.Assert(err, nil)
t.Assert(result, "<div>&lt;b&gt;my title&lt;/b&gt;</div>")
})
}
func Test_Encode_ParseContent(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
v := gview.New()
tplContent := gfile.GetContents(gdebug.TestDataPath("tpl", "encode.tpl"))
v.SetAutoEncode(true)
result, err := v.ParseContent(tplContent, g.Map{
"title": "<b>my title</b>",
})
t.Assert(err, nil)
t.Assert(result, "<div>&lt;b&gt;my title&lt;/b&gt;</div>")
})
}