|
|
@@ -5,71 +5,43 @@ package sanitizer
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
-func TestTruncateHTMWithTextLowerThanLimitL(t *testing.T) {
|
|
|
- input := `This is a <strong>bug 🐛</strong>.`
|
|
|
- expected := `This is a bug 🐛.`
|
|
|
- output := TruncateHTML(input, 50)
|
|
|
-
|
|
|
- if expected != output {
|
|
|
- t.Errorf(`Wrong output: %q != %q`, expected, output)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-func TestTruncateHTMLWithTextAboveLimit(t *testing.T) {
|
|
|
- input := `This is <strong>HTML</strong>.`
|
|
|
- expected := `This…`
|
|
|
- output := TruncateHTML(input, 4)
|
|
|
-
|
|
|
- if expected != output {
|
|
|
- t.Errorf(`Wrong output: %q != %q`, expected, output)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-func TestTruncateHTMLWithUnicodeTextAboveLimit(t *testing.T) {
|
|
|
- input := `This is a <strong>bike 🚲</strong>.`
|
|
|
- expected := `This…`
|
|
|
- output := TruncateHTML(input, 4)
|
|
|
-
|
|
|
- if expected != output {
|
|
|
- t.Errorf(`Wrong output: %q != %q`, expected, output)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-func TestTruncateHTMLWithMultilineTextAboveLimit(t *testing.T) {
|
|
|
- input := `
|
|
|
- This is a <strong>bike
|
|
|
- 🚲</strong>.
|
|
|
-
|
|
|
- `
|
|
|
- expected := `This is a bike…`
|
|
|
- output := TruncateHTML(input, 15)
|
|
|
-
|
|
|
- if expected != output {
|
|
|
- t.Errorf(`Wrong output: %q != %q`, expected, output)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-func TestTruncateHTMLWithMultilineTextLowerThanLimit(t *testing.T) {
|
|
|
- input := `
|
|
|
- This is a <strong>bike
|
|
|
- 🚲</strong>.
|
|
|
-
|
|
|
- `
|
|
|
- expected := `This is a bike 🚲.`
|
|
|
- output := TruncateHTML(input, 20)
|
|
|
-
|
|
|
- if expected != output {
|
|
|
- t.Errorf(`Wrong output: %q != %q`, expected, output)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-func TestTruncateHTMLWithMultipleSpaces(t *testing.T) {
|
|
|
+func TestTruncateHTML(t *testing.T) {
|
|
|
tests := []struct {
|
|
|
name string
|
|
|
input string
|
|
|
maxLen int
|
|
|
expected string
|
|
|
}{
|
|
|
+ {
|
|
|
+ name: "text lower than limit",
|
|
|
+ input: "This is a <strong>bug 🐛</strong>.",
|
|
|
+ maxLen: 50,
|
|
|
+ expected: "This is a bug 🐛.",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "text above limit",
|
|
|
+ input: "This is <strong>HTML</strong>.",
|
|
|
+ maxLen: 4,
|
|
|
+ expected: "This…",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "unicode text above limit",
|
|
|
+ input: "This is a <strong>bike 🚲</strong>.",
|
|
|
+ maxLen: 4,
|
|
|
+ expected: "This…",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "multiline text above limit",
|
|
|
+ input: "\n\t\tThis is a <strong>bike\n\t\t🚲</strong>.\n\n\t",
|
|
|
+ maxLen: 15,
|
|
|
+ expected: "This is a bike…",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "multiline text lower than limit",
|
|
|
+ input: "\n\t\tThis is a <strong>bike\n 🚲</strong>.\n\n\t",
|
|
|
+ maxLen: 20,
|
|
|
+ expected: "This is a bike 🚲.",
|
|
|
+ },
|
|
|
{
|
|
|
name: "multiple spaces",
|
|
|
input: "hello world test",
|