-
Notifications
You must be signed in to change notification settings - Fork 2
/
html_test.go
51 lines (43 loc) · 1.58 KB
/
html_test.go
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
// 2019, Georg Sauthoff <[email protected]>
// SPDX-License-Identifier: GPL-3.0-or-later
package main
import (
"bytes"
"testing"
)
func Test_remove_tags(t *testing.T) {
var b bytes.Buffer
w := new_remove_tags_writer(new_close_writer(&b))
w.Write([]byte("<!DOCTYPE html>\n" +
"<!--a0a0a0a0-a0a0-a0a0-a0a0-a0a0a0a0a0a0_a01-->\n" +
"<html> Hello <head> World </head>"))
w.Close()
if !bytes.Equal(b.Bytes(), []byte(" \n\n Hello World ")) {
t.Errorf("Unexpected result: |%v|", b.Bytes())
}
}
func Test_remove_tags_comment_with_gt(t *testing.T) {
var b bytes.Buffer
w := new_remove_tags_writer(new_close_writer(&b))
w.Write([]byte("<!DOCTYPE html>\n" +
"<!-- bla bla bal > lol -->\n" +
"<html> Hello <head> World </head>"))
w.Close()
if !bytes.Equal(b.Bytes(), []byte(" \n\n Hello World ")) {
t.Errorf("Unexpected result: |%v|", b.Bytes())
}
}
func Test_unescape_entity(t *testing.T) {
if v := unescape_entity([]byte("­")); !bytes.Equal(v, []byte("")) {
t.Errorf("Should translate to the empty string, got : |%v|", v)
}
if v := unescape_entity([]byte("­")); !bytes.Equal(v, []byte("")) {
t.Errorf("Should translate to the empty string, got : |%v|", v)
}
if v := unescape_entity([]byte(" ")); !bytes.Equal(v, []byte(" ")) {
t.Errorf("Should translate to space, got : |%v|", v)
}
if v := unescape_entity([]byte("ä")); !bytes.Equal(v, []byte("ä")) {
t.Errorf("Unexpected result: |%v|", v)
}
}