// 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 ghtml_test import ( "github.com/gogf/gf/frame/g" "testing" "github.com/gogf/gf/encoding/ghtml" "github.com/gogf/gf/test/gtest" ) func Test_StripTags(t *testing.T) { gtest.C(t, func(t *gtest.T) { src := `

Test paragraph.

Other text` dst := `Test paragraph. Other text` t.Assert(ghtml.StripTags(src), dst) }) } func Test_Entities(t *testing.T) { gtest.C(t, func(t *gtest.T) { src := `A 'quote' "is" bold` dst := `A 'quote' "is" <b>bold</b>` t.Assert(ghtml.Entities(src), dst) t.Assert(ghtml.EntitiesDecode(dst), src) }) } func Test_SpecialChars(t *testing.T) { gtest.C(t, func(t *gtest.T) { src := `A 'quote' "is" bold` dst := `A 'quote' "is" <b>bold</b>` t.Assert(ghtml.SpecialChars(src), dst) t.Assert(ghtml.SpecialCharsDecode(dst), src) }) } func Test_SpecialCharsMapOrStruct_Map(t *testing.T) { gtest.C(t, func(t *gtest.T) { a := g.Map{ "Title": "

T

", "Content": "
C
", } err := ghtml.SpecialCharsMapOrStruct(a) t.Assert(err, nil) t.Assert(a["Title"], `<h1>T</h1>`) t.Assert(a["Content"], `<div>C</div>`) }) gtest.C(t, func(t *gtest.T) { a := g.MapStrStr{ "Title": "

T

", "Content": "
C
", } err := ghtml.SpecialCharsMapOrStruct(a) t.Assert(err, nil) t.Assert(a["Title"], `<h1>T</h1>`) t.Assert(a["Content"], `<div>C</div>`) }) } func Test_SpecialCharsMapOrStruct_Struct(t *testing.T) { type A struct { Title string Content string } gtest.C(t, func(t *gtest.T) { a := &A{ Title: "

T

", Content: "
C
", } err := ghtml.SpecialCharsMapOrStruct(a) t.Assert(err, nil) t.Assert(a.Title, `<h1>T</h1>`) t.Assert(a.Content, `<div>C</div>`) }) }