gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

removehtml_test.go (2178B)


      1 // GoToSocial
      2 // Copyright (C) GoToSocial Authors admin@gotosocial.org
      3 // SPDX-License-Identifier: AGPL-3.0-or-later
      4 //
      5 // This program is free software: you can redistribute it and/or modify
      6 // it under the terms of the GNU Affero General Public License as published by
      7 // the Free Software Foundation, either version 3 of the License, or
      8 // (at your option) any later version.
      9 //
     10 // This program is distributed in the hope that it will be useful,
     11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 // GNU Affero General Public License for more details.
     14 //
     15 // You should have received a copy of the GNU Affero General Public License
     16 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 
     18 package text
     19 
     20 import (
     21 	"testing"
     22 
     23 	"github.com/stretchr/testify/suite"
     24 )
     25 
     26 const (
     27 	test_removeHTML                 = `<p>Another test <span class="h-card"><a href="http://fossbros-anonymous.io/@foss_satan" class="u-url mention" rel="nofollow noreferrer noopener" target="_blank">@<span>foss_satan</span></a></span><br/><br/><a href="http://localhost:8080/tags/Hashtag" class="mention hashtag" rel="tag nofollow noreferrer noopener" target="_blank">#<span>Hashtag</span></a><br/><br/>Text</p>`
     28 	test_removedHTML                = `Another test @foss_satan#HashtagText`
     29 	test_withEscapedLiteral         = `it\u0026amp;#39;s its it is`
     30 	test_withEscapedLiteralExpected = `it\u0026amp;#39;s its it is`
     31 	test_withEscaped                = "it\u0026amp;#39;s its it is"
     32 	test_withEscapedExpected        = "it&amp;#39;s its it is"
     33 )
     34 
     35 type RemoveHTMLTestSuite struct {
     36 	suite.Suite
     37 }
     38 
     39 func (suite *RemoveHTMLTestSuite) TestSanitizeWithEscapedLiteral() {
     40 	s := removeHTML(test_withEscapedLiteral)
     41 	suite.Equal(test_withEscapedLiteralExpected, s)
     42 }
     43 
     44 func (suite *RemoveHTMLTestSuite) TestSanitizeWithEscaped() {
     45 	s := removeHTML(test_withEscaped)
     46 	suite.Equal(test_withEscapedExpected, s)
     47 }
     48 
     49 func (suite *RemoveHTMLTestSuite) TestRemoveHTML() {
     50 	s := removeHTML(test_removeHTML)
     51 	suite.Equal(test_removedHTML, s)
     52 }
     53 
     54 func TestRemoveHTMLTestSuite(t *testing.T) {
     55 	suite.Run(t, &RemoveHTMLTestSuite{})
     56 }