notes-server/server/html_test.go

48 lines
1009 B
Go
Executable File

package server
import (
"gitea.inhome.blapointe.com/local/notes-server/config"
"net/http/httptest"
"regexp"
"strings"
"testing"
)
func TestHead(t *testing.T) {
config.Head = "A"
w := httptest.NewRecorder()
head(w, nil)
if s := strings.TrimSpace(string(w.Body.Bytes())); s != config.Head {
t.Fatal(s)
}
}
func TestFoot(t *testing.T) {
config.Foot = "A"
w := httptest.NewRecorder()
foot(w, nil)
if s := strings.TrimSpace(string(w.Body.Bytes())); s != config.Foot {
t.Fatal(s)
}
}
func TestBlock(t *testing.T) {
w := httptest.NewRecorder()
block(w, "hi")
s := strings.ReplaceAll(strings.TrimSpace(string(w.Body.Bytes())), "\n", ".")
if ok, err := regexp.MatchString("<div>.*hi.*<.div>", s); err != nil {
t.Fatal(err, s)
} else if !ok {
t.Fatal(ok, s)
}
}
func TestH(t *testing.T) {
s := strings.ReplaceAll(strings.TrimSpace(h2("hi")), "\n", ".")
if ok, err := regexp.MatchString("<h2[ ]*>.*hi.*<.h2>", s); err != nil {
t.Fatal(err, s)
} else if !ok {
t.Fatal(ok, s)
}
}