mirror of
https://gitee.com/johng/gf.git
synced 2024-12-02 12:17:53 +08:00
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
// Copyright 2017 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 gins_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/gogf/gf/frame/gins"
|
|
"github.com/gogf/gf/os/gfile"
|
|
"github.com/gogf/gf/os/gtime"
|
|
"github.com/gogf/gf/test/gtest"
|
|
)
|
|
|
|
func Test_View(t *testing.T) {
|
|
gtest.Case(t, func() {
|
|
gtest.AssertNE(gins.View(), nil)
|
|
b, e := gins.View().ParseContent(`{{"我是中国人" | substr 2 -1}}`, nil)
|
|
gtest.Assert(e, nil)
|
|
gtest.Assert(string(b), "中国人")
|
|
})
|
|
gtest.Case(t, func() {
|
|
tpl := "t.tpl"
|
|
err := gfile.PutContents(tpl, `{{"我是中国人" | substr 2 -1}}`)
|
|
gtest.Assert(err, nil)
|
|
defer gfile.Remove(tpl)
|
|
|
|
b, e := gins.View().Parse("t.tpl", nil)
|
|
gtest.Assert(e, nil)
|
|
gtest.Assert(string(b), "中国人")
|
|
})
|
|
gtest.Case(t, func() {
|
|
path := fmt.Sprintf(`%s/%d`, gfile.TempDir(), gtime.Nanosecond())
|
|
tpl := fmt.Sprintf(`%s/%s`, path, "t.tpl")
|
|
err := gfile.PutContents(tpl, `{{"我是中国人" | substr 2 -1}}`)
|
|
gtest.Assert(err, nil)
|
|
defer gfile.Remove(tpl)
|
|
err = gins.View().AddPath(path)
|
|
gtest.Assert(err, nil)
|
|
|
|
b, e := gins.View().Parse("t.tpl", nil)
|
|
gtest.Assert(e, nil)
|
|
gtest.Assert(string(b), "中国人")
|
|
})
|
|
}
|