package web
import (
"errors"
"net/http"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"sourcecraft.dev/bigbes/sr-ht-dolt/browse"
"sourcecraft.dev/bigbes/sr-ht-dolt/core"
)
// --- the rendering itself ------------------------------------------------------
//
// These render with no index at all — the nil receiver, which is what a page
// gets when the database listing failed. Everything asserted here is therefore
// about the markdown and about what is allowed to reach the browser, not about
// the links.
// renderMemory is one memory body, rendered by a memoryLinks that knows no
// database.
func renderMemory(src string) string {
var noLinks *memoryLinks
return string(noLinks.Body(src))
}
// The shapes the memories are actually written in: a bold leader, code spans, a
// bullet list, a fenced recipe, and hard-wrapped prose that reflows into one
// paragraph rather than keeping the width its author's terminal had.
func TestMemoryBodyRendersMarkdown(t *testing.T) {
got := renderMemory("**Why:** the networks are declared `external: true` everywhere,\n" +
"and compose cannot create one.\n" +
"\n" +
"- first, `./prepare.sh`\n" +
"- then `labng push backup`\n" +
"\n" +
"```\n" +
"dolt clone https://dolt.srht.bigb.es/~bigbes/x\n" +
"```\n")
assert.Contains(t, got, "Why:")
assert.Contains(t, got, "external: true")
assert.Contains(t, got, "
./prepare.shdolt clone")
assert.Contains(t, got, "everywhere,\nand compose cannot create one.",
"a hard-wrapped paragraph reflows: the source's line breaks are not the document's")
assert.NotContains(t, got, "**", "the asterisks are markup and must not survive as text")
}
// A memory is stored text and is escaped on its way out, exactly as it was when
// the page printed paragraphs. Markup written in one renders as the characters
// somebody typed and never as an element.
func TestMemoryBodyEscapesStoredMarkup(t *testing.T) {
got := renderMemory("Supersedes the memory that asserted otherwise.\n" +
"\n" +
"\n")
assert.NotContains(t, got, "otherwise")
assert.Contains(t, got, "<b>otherwise</b>")
assert.NotContains(t, got, "