mirror of
https://github.com/axllent/mailpit.git
synced 2025-06-25 00:37:17 +02:00
Tests: Add html2text tests
This commit is contained in:
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
@ -24,7 +24,7 @@ jobs:
|
|||||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-go-
|
${{ 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=.
|
- run: go test ./internal/storage -bench=.
|
||||||
|
|
||||||
# build the assets
|
# build the assets
|
||||||
|
56
internal/tools/html2text/html2text_test.go
Normal file
56
internal/tools/html2text/html2text_test.go
Normal file
@ -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["<h1>This is a test.</h1> "] = "This is a test."
|
||||||
|
tests["<p>Paragraph 1</p><p>Paragraph 2</p>"] = "Paragraph 1 Paragraph 2"
|
||||||
|
tests["<h1>Heading</h1><p>Paragraph</p>"] = "Heading Paragraph"
|
||||||
|
tests["<span>Alpha</span>bet <strong>chars</strong>"] = "Alphabet chars"
|
||||||
|
tests["<span><b>A</b>lpha</span>bet chars."] = "Alphabet chars."
|
||||||
|
tests["<table><tr><td>First</td><td>Second</td></table>"] = "First Second"
|
||||||
|
tests[`<h1>Heading</h1>
|
||||||
|
<p>Paragraph</p>`] = "Heading Paragraph"
|
||||||
|
tests[`<h1>Heading</h1><p> <a href="https://github.com">linked text</a></p>`] = "Heading linked text"
|
||||||
|
// broken html
|
||||||
|
tests[`<h1>Heading</h3><p> <a href="https://github.com">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["<h1>This is a test.</h1> "] = "This is a test."
|
||||||
|
tests["<p>Paragraph 1</p><p>Paragraph 2</p>"] = "Paragraph 1 Paragraph 2"
|
||||||
|
tests["<h1>Heading</h1><p>Paragraph</p>"] = "Heading Paragraph"
|
||||||
|
tests["<span>Alpha</span>bet <strong>chars</strong>"] = "Alphabet chars"
|
||||||
|
tests["<span><b>A</b>lpha</span>bet chars."] = "Alphabet chars."
|
||||||
|
tests["<table><tr><td>First</td><td>Second</td></table>"] = "First Second"
|
||||||
|
tests["<h1>Heading</h1><p>Paragraph</p>"] = "Heading Paragraph"
|
||||||
|
tests[`<h1>Heading</h1>
|
||||||
|
<p>Paragraph</p>`] = "Heading Paragraph"
|
||||||
|
tests[`<h1>Heading</h1><p> <a href="https://github.com">linked text</a></p>`] = "Heading https://github.com linked text"
|
||||||
|
// broken html
|
||||||
|
tests[`<h1>Heading</h3><p> <a href="https://github.com">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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user