1
0
html/wrap_test.go

87 lines
2.0 KiB
Go
Raw Normal View History

2025-09-11 20:50:00 +02:00
package html_test
import (
"bytes"
"code.squareroundforest.org/arpio/html"
. "code.squareroundforest.org/arpio/html/tags"
"testing"
)
func TestWrap(t *testing.T) {
t.Run("broken unicode", func(t *testing.T) {
b := []byte{'f', 0xc2, 'o', 'o'}
span := Span(string(b))
var buf bytes.Buffer
if err := html.RenderIndent(&buf, html.Indentation{Indent: "\t"}, span); err == nil {
t.Fatal()
2025-09-11 20:50:00 +02:00
}
})
t.Run("multiple words", func(t *testing.T) {
span := Span("foo bar baz")
var buf bytes.Buffer
if err := html.RenderIndent(&buf, html.Indentation{Indent: "\t", PWidth: 2}, span); err != nil {
2025-09-11 20:50:00 +02:00
t.Fatal(err)
}
expect := "<span>\nfoo\nbar\nbaz\n</span>"
if buf.String() != expect {
printBytes(buf.String(), expect)
2025-09-11 20:50:00 +02:00
t.Fatal(buf.String())
}
})
t.Run("tag not split", func(t *testing.T) {
span := Span("foo ", Span("bar", Attr("qux", 42)), " baz")
2025-09-11 20:50:00 +02:00
var buf bytes.Buffer
if err := html.RenderIndent(&buf, html.Indentation{Indent: "X", PWidth: 2}, span); err != nil {
2025-09-11 20:50:00 +02:00
t.Fatal(err)
}
if buf.String() != "<span>\nfoo\n<span qux=\"42\">\nbar\n</span>\nbaz\n</span>" {
t.Fatal(buf.String())
2025-09-11 20:50:00 +02:00
}
})
t.Run("normal text", func(t *testing.T) {
div := Div(Span("foo bar baz qux quux corge"))
var buf bytes.Buffer
if err := html.RenderIndent(&buf, html.Indentation{Indent: "\t", PWidth: 9}, div); err != nil {
2025-09-11 20:50:00 +02:00
t.Fatal(err)
}
if buf.String() != "<div>\n\t<span>\n\tfoo bar\n\tbaz qux\n\tquux\n\tcorge\n\t</span>\n</div>" {
2025-09-11 20:50:00 +02:00
t.Fatal(buf.String())
}
})
t.Run("inline space preserved", func(t *testing.T) {
div := Div(Span("foo"), " ", Span("bar"))
var buf bytes.Buffer
if err := html.RenderIndent(&buf, html.Indentation{Indent: "\t"}, div); err != nil {
2025-09-11 20:50:00 +02:00
t.Fatal(err)
}
if buf.String() != "<div>\n\t<span>foo</span> <span>bar</span>\n</div>" {
2025-09-11 20:50:00 +02:00
t.Fatal(buf.String())
}
})
t.Run("multiple lines", func(t *testing.T) {
})
t.Run("special whitespace characters", func(t *testing.T) {
})
t.Run("spaces around tags", func(t *testing.T) {
})
t.Run("one line primitives", func(t *testing.T) {
})
2025-09-11 20:50:00 +02:00
}