mirror of
https://gitee.com/johng/gf.git
synced 2024-11-30 11:18:02 +08:00
68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
// Copyright GoFrame Author(https://goframe.org). 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 (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/os/gview"
|
|
"github.com/gogf/gf/v2/test/gtest"
|
|
)
|
|
|
|
func Test_Config(t *testing.T) {
|
|
gtest.C(t, func(t *gtest.T) {
|
|
config := gview.Config{
|
|
Paths: []string{gtest.DataPath("config")},
|
|
Data: g.Map{
|
|
"name": "gf",
|
|
},
|
|
DefaultFile: "test.html",
|
|
Delimiters: []string{"${", "}"},
|
|
}
|
|
view := gview.New()
|
|
err := view.SetConfig(config)
|
|
t.AssertNil(err)
|
|
|
|
str := `hello ${.name},version:${.version}`
|
|
view.Assigns(g.Map{"version": "1.7.0"})
|
|
result, err := view.ParseContent(context.TODO(), str, nil)
|
|
t.AssertNil(err)
|
|
t.Assert(result, "hello gf,version:1.7.0")
|
|
|
|
result, err = view.ParseDefault(context.TODO())
|
|
t.AssertNil(err)
|
|
t.Assert(result, "name:gf")
|
|
})
|
|
}
|
|
|
|
func Test_ConfigWithMap(t *testing.T) {
|
|
gtest.C(t, func(t *gtest.T) {
|
|
view := gview.New()
|
|
err := view.SetConfigWithMap(g.Map{
|
|
"Paths": []string{gtest.DataPath("config")},
|
|
"DefaultFile": "test.html",
|
|
"Delimiters": []string{"${", "}"},
|
|
"Data": g.Map{
|
|
"name": "gf",
|
|
},
|
|
})
|
|
t.AssertNil(err)
|
|
|
|
str := `hello ${.name},version:${.version}`
|
|
view.Assigns(g.Map{"version": "1.7.0"})
|
|
result, err := view.ParseContent(context.TODO(), str, nil)
|
|
t.AssertNil(err)
|
|
t.Assert(result, "hello gf,version:1.7.0")
|
|
|
|
result, err = view.ParseDefault(context.TODO())
|
|
t.AssertNil(err)
|
|
t.Assert(result, "name:gf")
|
|
})
|
|
}
|