-- SPDX-FileCopyrightText: © 2022—2026 Vladimir Zorin -- SPDX-License-Identifier: LicenseRef-OWL-1.0-or-later -- Licensed under OWL v1.0+. See LICENSE. local testimony = require("testimony") local render = require("lilgit.render") local testify = testimony.new("== lilgit.render ==") testify:that("html_escape: escapes all five special characters", function() testimony.assert_equal("&<>"'", render.html_escape("&<>\"'")) end) testify:that("html_escape: does not double-escape ampersands in entities", function() testimony.assert_equal("&amp;", render.html_escape("&")) end) testify:that("href: escapes each segment, keeps ref slashes literal", function() testimony.assert_equal( "/repo/tree/feature/foo/a%20b/c/", render.href("repo", "tree", "feature/foo", { "a b", "c" }, true) ) testimony.assert_equal("/repo/blob/main/file.md", render.href("repo", "blob", "main", { "file.md" }, false)) end) testify:that("markdown: extracts the first h1 as title and removes it from the body", function() local html, title = render.markdown("# Hello *World*\n\nBody text.\n", "file.md") testimony.assert_equal("Hello World", title) testimony.assert_nil(html:match("${body}", templates.page) testimony.assert_not_nil(render.build_templates({}).page) end) testify:that("tree_page: fills the shell, escapes names, links entries", function() local state = { cfg = { site_title = "test site" }, templates = render.build_templates({}), } local repo = { name = "repo", default_branch = "main" } local listing = { { name = "sub", sha = string.rep("a", 40), kind = "tree", mode = "40000" }, { name = "areadme body

", "Readme Title") testimony.assert_match('href="/repo/tree/main/sub/"', html) testimony.assert_match('href="/repo/blob/main/a%%3Cb%.txt"', html) testimony.assert_match("a<b%.txt", html) testimony.assert_match("gl @ ccccccc", html) testimony.assert_match("readme body", html) testimony.assert_match("Readme Title", html) testimony.assert_match("test site", html) end) testify:conclude()