github.com/zhongdalu/gf@v1.0.0/g/encoding/ghtml/ghtml_test.go (about) 1 // Copyright 2017 gf Author(https://github.com/zhongdalu/gf). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/zhongdalu/gf. 6 package ghtml_test 7 8 import ( 9 "github.com/zhongdalu/gf/g/encoding/ghtml" 10 "github.com/zhongdalu/gf/g/test/gtest" 11 "testing" 12 ) 13 14 func TestStripTags(t *testing.T) { 15 src := `<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>` 16 dst := `Test paragraph. Other text` 17 gtest.Assert(ghtml.StripTags(src), dst) 18 } 19 20 func TestEntities(t *testing.T) { 21 src := `A 'quote' "is" <b>bold</b>` 22 dst := `A 'quote' "is" <b>bold</b>` 23 gtest.Assert(ghtml.Entities(src), dst) 24 gtest.Assert(ghtml.EntitiesDecode(dst), src) 25 } 26 27 func TestSpecialChars(t *testing.T) { 28 src := `A 'quote' "is" <b>bold</b>` 29 dst := `A 'quote' "is" <b>bold</b>` 30 gtest.Assert(ghtml.SpecialChars(src), dst) 31 gtest.Assert(ghtml.SpecialCharsDecode(dst), src) 32 }