-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserializer_test.go
More file actions
57 lines (48 loc) · 1.92 KB
/
serializer_test.go
File metadata and controls
57 lines (48 loc) · 1.92 KB
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
package GoHtml_test
import (
"errors"
"os"
"strings"
"testing"
GoHtml "github.com/udan-jayanith/GoHTML"
)
func TestEncode1(t *testing.T) {
body := GoHtml.CreateNode("body")
h1 := GoHtml.CreateNode("h1")
h1.AppendText("This is a heading")
h1.SetAttribute("id", "first-heading'")
body.AppendChild(h1)
body.AppendChild(GoHtml.CreateNode("br"))
p := GoHtml.CreateNode("p")
p.AppendText("The <p> HTML tag is a fundamental element used for creating paragraphs in web development. It helps structure content, separating text into distinct blocks. When you wrap text within tags, you tell browsers to treat the enclosed content as a paragraph.")
body.AppendChild(p)
builder1 := &strings.Builder{}
GoHtml.Encode(builder1, body)
//It's hard compare exacted output. Because strings, prettier formats html code. htmlFormatter and prettier add extra stuffs to the html codes like dash in void tags. Exacted output is in the ./test-files/2.html.
}
type fakeWriter struct {
}
func (_ fakeWriter) Write(p []byte) (n int, err error) {
return 0, errors.New("Error")
}
func TestEncode2(t *testing.T) {
file, err := os.Open("./test-files/1.html")
if err != nil {
t.Fatal("1.html does not exists.")
}
defer file.Close()
node, _ := GoHtml.Decode(file)
var builder strings.Builder
err = GoHtml.Encode(&builder, node)
if err != nil {
t.Fatal(err.Error())
}
//It's hard compare exacted output. Because strings, prettier formats html code. htmlFormatter and prettier add extra stuffs to the html codes like dash in void tags. Exacted output is in the ./test-files/2.html.
}
func TestEncode3(t *testing.T) {
err := GoHtml.Encode(&fakeWriter{}, GoHtml.CreateTextNode(""))
if err == nil {
t.Fatal("Expected a error but got no error")
}
//It's hard compare exacted output. Because strings, prettier formats html code. htmlFormatter and prettier add extra stuffs to the html codes like dash in void tags. Exacted output is in the ./test-files/2.html.
}