Add test cases (#26)

* Add tests for the Exists function

* Add tests for the StripHTMLTags function
This commit is contained in:
Shay Elmualem
2020-10-07 16:13:57 +03:00
committed by GitHub
parent 15f667f75d
commit 45320c8265
2 changed files with 69 additions and 0 deletions

26
utils/html_test.go Normal file
View File

@@ -0,0 +1,26 @@
package utils
import "testing"
func TestStripHTMLTags(t *testing.T) {
testCases := []struct {
htmlInput string
expect string
}{
{htmlInput: "<html><body<h1>Hello World!</h1></body></html>",
expect: "Hello World!"},
{htmlInput: "<h1>Hello World!</h1>",
expect: "Hello World!"},
{htmlInput: "<h1 style='color: #5e9ca0';>Hello World!</h1>",
expect: "Hello World!"},
{htmlInput: "<td><img style='margin: 1px 15px;' src='images/smiley.png' alt='laughing' width='40' height='16' /><strong>Hello World!</strong></td>", expect: "Hello World!"},
}
for _, tc := range testCases {
got := StripHTMLTags(tc.htmlInput)
expect := tc.expect
if got != expect {
t.Errorf("Expected %s, got %s", expect, got)
}
}
}