Read HTML from a file instead of .tmpl

This commit is contained in:
Joakim Hellsén 2024-02-05 02:35:46 +01:00
commit c185d463e6
18 changed files with 369 additions and 591 deletions

50
html_test.go Normal file
View file

@ -0,0 +1,50 @@
package main
import (
"strings"
"testing"
)
// returns a minified version of the input HTML string
func TestMinifyHTML(t *testing.T) {
input := "<html><head><title>Test</title></head><body><h1>Hello, World!</h1></body></html>"
expected := "<title>Test</title><h1>Hello, World!</h1>"
result := minifyHTML(input)
if result != expected {
t.Errorf("Expected minified HTML: %s, but got: %s", expected, result)
}
}
func TestMinifyCSS(t *testing.T) {
cssString := `
body {
background-color: red;
color: blue;
}
`
expected := "body{background-color:red;color:blue}"
result := minifyCSS(cssString)
if result != expected {
t.Errorf("Expected minified CSS string to be %s, but got %s", expected, result)
}
}
// Displays error messages if there are any parse errors
func TestErrorMessages(t *testing.T) {
// Initialize test data
h := HTMLData{}
parseResult := []ParseResult{
{IsError: true, Msg: "Error 1"},
{IsError: true, Msg: "Error 2"},
}
// Invoke function under test
result := fullHTML(h, parseResult)
// Assert that the result contains the error messages
if !strings.Contains(result, "Error 1") || !strings.Contains(result, "Error 2") {
t.Errorf("Expected error messages, but got: %s", result)
}
}