<commit_before>// 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 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_Config(t *testing.T) {
	gtest.Case(t, func() {
		config := gview.Config{
			Paths: []string{gfile.Join(gdebug.CallerDirectory(), "testdata", "config")},
			Data: g.Map{
				"name": "gf",
			},
			DefaultFile: "test.html",
			Delimiters:  []string{"${", "}"},
		}
		view := gview.New()
		err := view.SetConfig(config)
		gtest.Assert(err, nil)

		str := `hello ${.name},version:${.version}`
		view.Assigns(g.Map{"version": "1.7.0"})
		result, err := view.ParseContent(str, nil)
		gtest.Assert(err, nil)
		gtest.Assert(result, "hello gf,version:1.7.0")

		result, err = view.ParseDefault()
		gtest.Assert(err, nil)
		gtest.Assert(result, "name:gf")
	})
}<commit_msg>add more unit testing case for gview<commit_after>// 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 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_Config(t *testing.T) {
	gtest.Case(t, func() {
		config := gview.Config{
			Paths: []string{gfile.Join(gdebug.CallerDirectory(), "testdata", "config")},
			Data: g.Map{
				"name": "gf",
			},
			DefaultFile: "test.html",
			Delimiters:  []string{"${", "}"},
		}
		view := gview.New()
		err := view.SetConfig(config)
		gtest.Assert(err, nil)

		str := `hello ${.name},version:${.version}`
		view.Assigns(g.Map{"version": "1.7.0"})
		result, err := view.ParseContent(str, nil)
		gtest.Assert(err, nil)
		gtest.Assert(result, "hello gf,version:1.7.0")

		result, err = view.ParseDefault()
		gtest.Assert(err, nil)
		gtest.Assert(result, "name:gf")
	})
}

func Test_ConfigWithMap(t *testing.T) {
	gtest.Case(t, func() {
		view := gview.New()
		err := view.SetConfigWithMap(g.Map{
			"Paths":       []string{gfile.Join(gdebug.CallerDirectory(), "testdata", "config")},
			"DefaultFile": "test.html",
			"Delimiters":  []string{"${", "}"},
			"Data": g.Map{
				"name": "gf",
			},
		})
		gtest.Assert(err, nil)

		str := `hello ${.name},version:${.version}`
		view.Assigns(g.Map{"version": "1.7.0"})
		result, err := view.ParseContent(str, nil)
		gtest.Assert(err, nil)
		gtest.Assert(result, "hello gf,version:1.7.0")

		result, err = view.ParseDefault()
		gtest.Assert(err, nil)
		gtest.Assert(result, "name:gf")
	})
}
{'fraction_non_alphanumeric': 0.19446297531687792, 'fraction_numerical': 0.00867244829886591, 'mean_word_length': 3.7603174603174603, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6626881', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1186, 'n_words': 238}