package server import ( "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("hi", w) s := strings.ReplaceAll(strings.TrimSpace(string(w.Body.Bytes())), "\n", ".") if ok, err := regexp.MatchString("
.*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("

.*hi.*<.h2>", s); err != nil { t.Fatal(err, s) } else if !ok { t.Fatal(ok, s) } }