From e9d44c55a1fe87ec45071065c7b9b1625d828d2c Mon Sep 17 00:00:00 2001 From: Ralph Slooten Date: Sat, 14 Oct 2023 22:28:52 +1300 Subject: [PATCH] Tests: Add html2text tests --- .github/workflows/tests.yml | 2 +- internal/tools/html2text/html2text_test.go | 56 ++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 internal/tools/html2text/html2text_test.go diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e26ce529f..c26e25830 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -24,7 +24,7 @@ jobs: key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} restore-keys: | ${{ runner.os }}-go- - - run: go test ./internal/storage ./server ./internal/tools -v + - run: go test ./internal/storage ./server ./internal/tools ./internal/tools/html2text -v - run: go test ./internal/storage -bench=. # build the assets diff --git a/internal/tools/html2text/html2text_test.go b/internal/tools/html2text/html2text_test.go new file mode 100644 index 000000000..dd1763918 --- /dev/null +++ b/internal/tools/html2text/html2text_test.go @@ -0,0 +1,56 @@ +package html2text + +import "testing" + +func TestPlain(t *testing.T) { + tests := map[string]string{} + tests["this is a test"] = "this is a test" + tests["thiS IS a Test"] = "thiS IS a Test" + tests["thiS IS a Test :-)"] = "thiS IS a Test :-)" + tests["

This is a test.

"] = "This is a test." + tests["

Paragraph 1

Paragraph 2

"] = "Paragraph 1 Paragraph 2" + tests["

Heading

Paragraph

"] = "Heading Paragraph" + tests["Alphabet chars"] = "Alphabet chars" + tests["Alphabet chars."] = "Alphabet chars." + tests["
FirstSecond
"] = "First Second" + tests[`

Heading

+

Paragraph

`] = "Heading Paragraph" + tests[`

Heading

linked text

`] = "Heading linked text" + // broken html + tests[`

Heading

linked text.`] = "Heading linked text." + + for str, expected := range tests { + res := Strip(str, false) + if res != expected { + t.Log("error:", res, "!=", expected) + t.Fail() + } + } +} + +func TestWithLinks(t *testing.T) { + tests := map[string]string{} + tests["this is a test"] = "this is a test" + tests["thiS IS a Test"] = "thiS IS a Test" + tests["thiS IS a Test :-)"] = "thiS IS a Test :-)" + tests["

This is a test.

"] = "This is a test." + tests["

Paragraph 1

Paragraph 2

"] = "Paragraph 1 Paragraph 2" + tests["

Heading

Paragraph

"] = "Heading Paragraph" + tests["Alphabet chars"] = "Alphabet chars" + tests["Alphabet chars."] = "Alphabet chars." + tests["
FirstSecond
"] = "First Second" + tests["

Heading

Paragraph

"] = "Heading Paragraph" + tests[`

Heading

+

Paragraph

`] = "Heading Paragraph" + tests[`

Heading

linked text

`] = "Heading https://github.com linked text" + // broken html + tests[`

Heading

linked text.`] = "Heading https://github.com linked text." + + for str, expected := range tests { + res := Strip(str, true) + if res != expected { + t.Log("error:", res, "!=", expected) + t.Fail() + } + } +}