gf/encoding/ghtml/ghtml_test.go

41 lines
1.1 KiB
Go
Raw Normal View History

2019-04-19 17:04:43 +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.
2019-04-19 17:04:43 +08:00
package ghtml_test
import (
"testing"
2019-07-29 21:01:19 +08:00
"github.com/gogf/gf/encoding/ghtml"
"github.com/gogf/gf/test/gtest"
2019-04-19 17:04:43 +08:00
)
func TestStripTags(t *testing.T) {
2020-03-19 23:53:03 +08:00
gtest.C(t, func(t *gtest.T) {
src := `<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>`
dst := `Test paragraph. Other text`
t.Assert(ghtml.StripTags(src), dst)
})
2019-04-19 17:04:43 +08:00
}
func TestEntities(t *testing.T) {
2020-03-19 23:53:03 +08:00
gtest.C(t, func(t *gtest.T) {
src := `A 'quote' "is" <b>bold</b>`
dst := `A &#39;quote&#39; &#34;is&#34; &lt;b&gt;bold&lt;/b&gt;`
t.Assert(ghtml.Entities(src), dst)
t.Assert(ghtml.EntitiesDecode(dst), src)
})
2019-04-19 17:04:43 +08:00
}
func TestSpecialChars(t *testing.T) {
2020-03-19 23:53:03 +08:00
gtest.C(t, func(t *gtest.T) {
src := `A 'quote' "is" <b>bold</b>`
dst := `A &#39;quote&#39; &#34;is&#34; &lt;b&gt;bold&lt;/b&gt;`
t.Assert(ghtml.SpecialChars(src), dst)
t.Assert(ghtml.SpecialCharsDecode(dst), src)
})
2019-04-19 17:04:43 +08:00
}