internal/shape/render_test.go
Ref: Size: 965 B History
package shape
import (
"strings"
"testing"
)
func TestRenderJSONIsSortedAndStable(t *testing.T) {
j1, err := RenderJSON(Build(sample()))
if err != nil {
t.Fatal(err)
}
j2, _ := RenderJSON(Build(sample()))
if string(j1) != string(j2) {
t.Fatal("RenderJSON not stable across calls")
}
if !strings.HasSuffix(string(j1), "\n") {
t.Error("RenderJSON output must end with a trailing newline")
}
if !strings.Contains(string(j1), `"importPath": "internal/pb"`) {
t.Errorf("expected pretty-printed importPath in output:\n%s", j1)
}
}
func TestRenderHTMLInlinesExactJSONBytes(t *testing.T) {
j, _ := RenderJSON(Build(sample()))
html := RenderHTML(j)
if !strings.Contains(html, string(j)) {
t.Error("HTML must contain the JSON bytes verbatim")
}
if strings.Contains(html, dataMarker) {
t.Error("data marker must be replaced")
}
if !strings.Contains(html, `id="shape-data"`) {
t.Error("viewer template missing shape-data script block")
}
}