2019-03-12 23:26:10 +08:00
|
|
|
// 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 (
|
2019-06-19 09:06:52 +08:00
|
|
|
"fmt"
|
|
|
|
"github.com/gogf/gf/g/frame/gins"
|
|
|
|
"github.com/gogf/gf/g/os/gfile"
|
|
|
|
"github.com/gogf/gf/g/os/gtime"
|
|
|
|
"github.com/gogf/gf/g/test/gtest"
|
|
|
|
"testing"
|
2019-03-12 23:26:10 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func Test_View(t *testing.T) {
|
2019-06-19 09:06:52 +08:00
|
|
|
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)
|
2019-03-12 23:26:10 +08:00
|
|
|
|
2019-06-19 09:06:52 +08:00
|
|
|
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)
|
2019-03-12 23:26:10 +08:00
|
|
|
|
2019-06-19 09:06:52 +08:00
|
|
|
b, e := gins.View().Parse("t.tpl", nil)
|
|
|
|
gtest.Assert(e, nil)
|
|
|
|
gtest.Assert(string(b), "中国人")
|
|
|
|
})
|
2019-03-12 23:26:10 +08:00
|
|
|
}
|