aboutsummaryrefslogtreecommitdiff
path: root/internal/reader/sanitizer/truncate_test.go
blob: bb50f0392273bdc8181359b7143bcfc1eb35339e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

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)
	}
}