All checks were successful
check / check (pull_request) Successful in 30s
- a list item with no text (only an image or a link without a label) has no empty bullet,
its links are still written
- paragraphs and table cells of a list item do not stick together, and a preformatted
block in an item stays a block after its bullet
- spaces in the address of a link line are written as %20
- a wide table with an empty first cell has no empty heading, a wide table with only a
header or only one column is written as bullets, and the header is not lost
- a post in another language than the news has its own line in .meta, before the lines
of the folders: the server uses the first line that matches a document (checked with
Agate 3.3.25)
- an empty {{news_archive}} or {{categories_list}} leaves nothing, with its heading, so
a site without news says so once
- images of the layout (class logo, mark or decorative, role presentation or none) leave
no link line and the file is not copied
- the command test names files instead of counting them, and -clean and the warning
about old files work for the gemini command too
Refs #10
523 lines
23 KiB
Go
523 lines
23 KiB
Go
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package build
|
|
|
|
import (
|
|
"io/fs"
|
|
"os"
|
|
"path/filepath"
|
|
"regexp"
|
|
"sort"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// buildGem builds the Gemini output of the site made of files, with the options changed by tune.
|
|
func buildGem(t *testing.T, files map[string]string, tune func(*GeminiOptions)) (string, error) {
|
|
t.Helper()
|
|
out := filepath.Join(t.TempDir(), "capsule")
|
|
opts := GeminiOptions{SiteDir: writeFiles(t, files), OutDir: out, Version: "1.2.3", Now: fixedNow, Language: "it"}
|
|
if tune != nil {
|
|
tune(&opts)
|
|
}
|
|
_, err := BuildGemini(opts)
|
|
return out, err
|
|
}
|
|
|
|
// gemSite is the base site with a services page that has a table and an image, a Spanish news page left out and
|
|
// the news index of the English pages.
|
|
func gemSite(extra map[string]string) map[string]string {
|
|
files := withFiles(map[string]string{
|
|
"lang/en.json": blogLangEn, "lang/it.json": blogLangIt,
|
|
"content/en/services.md": page("services", "Services", "", "Write to **{{contact_shown}}**.\n\n<table class=\"data\">\n<thead><tr><th>Service</th><th>Kept</th></tr></thead>\n<tbody><tr><td>Mail</td><td>30 days</td></tr></tbody>\n</table>\n\n\n"),
|
|
"content/en/news/index.md": page("news", "News", "Layout: bare\n", "# News\n\n{{news_list}}\n\n## Categories\n\n{{categories_list}}\n\n## Archive\n\n{{news_archive}}\n\n[Feed](/news/feed.xml)\n"),
|
|
"news/shop.md": "Title: A shop\nAuthor: squid\nDate: 2026-11-14T12:00:00+0100\nCategories: FLUG\nDescription: About the shop.\nMastodon: https://social.kmalloc.org/@squid/115\n-\nThere is a shop. Mail me at squid@kmalloc.org or visit [the site](https://kmalloc.org/).\n",
|
|
})
|
|
for k, v := range extra {
|
|
if v == "" {
|
|
delete(files, k)
|
|
continue
|
|
}
|
|
files[k] = v
|
|
}
|
|
return files
|
|
}
|
|
|
|
// gemFiles returns every file of the output, as slash paths relative to it.
|
|
func gemFiles(t *testing.T, out string) []string {
|
|
t.Helper()
|
|
var files []string
|
|
err := filepath.WalkDir(out, func(path string, d fs.DirEntry, err error) error {
|
|
if err != nil || d.IsDir() {
|
|
return err
|
|
}
|
|
rel, _ := filepath.Rel(out, path)
|
|
files = append(files, filepath.ToSlash(rel))
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sort.Strings(files)
|
|
return files
|
|
}
|
|
|
|
// TestGeminiTree checks which files the capsule has, with Italian at the root.
|
|
func TestGeminiTree(t *testing.T) {
|
|
out, err := buildGem(t, gemSite(nil), nil)
|
|
if err != nil {
|
|
t.Fatalf("BuildGemini() error = %v", err)
|
|
}
|
|
have := map[string]bool{}
|
|
for _, f := range gemFiles(t, out) {
|
|
have[f] = true
|
|
}
|
|
for _, want := range []string{
|
|
"index.gmi", "manifesto.gmi", "persone.gmi", "servizi.gmi", "cronologia-manifesto.gmi", "progetti.gmi",
|
|
"en/index.gmi", "en/manifesto.gmi", "en/people.gmi", "en/services.gmi", "es/manifesto.gmi",
|
|
"news/index.gmi", "news/feed.gmi", "news/2026/11/shop.gmi", "news/2026/11/status.gmi", "news/2026/09/gnu-linux-day-2026.gmi",
|
|
"news/category/flug.gmi", "news/category/linux-day.gmi", "news/2026/index.gmi", "news/2026/11/index.gmi", "news/2026/09/index.gmi",
|
|
".meta", "logo.svg",
|
|
} {
|
|
if !have[want] {
|
|
t.Errorf("the capsule has no %s", want)
|
|
}
|
|
}
|
|
for f := range have {
|
|
if strings.HasSuffix(f, ".html") || strings.HasPrefix(f, "it/") || strings.HasPrefix(f, "en/news/") || strings.HasPrefix(f, "es/news/") || strings.HasSuffix(f, "robots.txt") {
|
|
t.Errorf("the capsule has %s, which it should not", f)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestGeminiRootLanguage checks the language at the root: the option, site.json, then the default language.
|
|
func TestGeminiRootLanguage(t *testing.T) {
|
|
plain, err := buildGem(t, gemSite(nil), func(o *GeminiOptions) { o.Language = "" })
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
mustContain(t, "index.gmi", readOut(t, plain, "index.gmi"), "# kmalloc.org")
|
|
if !exists(t, plain, "it/index.gmi") || exists(t, plain, "en/index.gmi") {
|
|
t.Error("without a choice the default language is at the root and the others under their code")
|
|
}
|
|
files := gemSite(map[string]string{"site.json": strings.Replace(baseFiles()["site.json"], `"languages"`, `"gemini_language": "it", "languages"`, 1)})
|
|
fromSite, err := buildGem(t, files, func(o *GeminiOptions) { o.Language = "" })
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !exists(t, fromSite, "en/index.gmi") || exists(t, fromSite, "it/index.gmi") {
|
|
t.Error("gemini_language in site.json does not put Italian at the root")
|
|
}
|
|
for name, tune := range map[string]func(*GeminiOptions){"xx": func(o *GeminiOptions) { o.Language = "xx" }, "es has no home": func(o *GeminiOptions) { o.Language = "es" }} {
|
|
if _, err := buildGem(t, gemSite(nil), tune); err == nil {
|
|
t.Errorf("language %s: no error", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestGeminiMeta checks the .meta file that sets the language of the documents.
|
|
func TestGeminiMeta(t *testing.T) {
|
|
out, err := buildGem(t, gemSite(nil), nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want := "en/*:;lang=en\nen/**/*:;lang=en\nes/*:;lang=es\nes/**/*:;lang=es\nnews/*:;lang=en\nnews/**/*:;lang=en\n"
|
|
if got := readOut(t, out, ".meta"); got != want {
|
|
t.Errorf(".meta =\n%q\nwant\n%q", got, want)
|
|
}
|
|
plain, err := buildGem(t, gemSite(nil), func(o *GeminiOptions) { o.Language = "en" })
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want = "it/*:;lang=it\nit/**/*:;lang=it\nes/*:;lang=es\nes/**/*:;lang=es\n"
|
|
if got := readOut(t, plain, ".meta"); got != want {
|
|
t.Errorf(".meta with English at the root =\n%q\nwant\n%q (the news are in the language of the root: no lines for them)", got, want)
|
|
}
|
|
for _, f := range gemFiles(t, out) {
|
|
if strings.HasSuffix(f, ".gmi") && strings.Contains(readOut(t, out, f), ".meta") {
|
|
t.Errorf("%s mentions .meta", f)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestGeminiPages checks the headings, the layouts and the navigation of a page.
|
|
func TestGeminiPages(t *testing.T) {
|
|
out, err := buildGem(t, gemSite(nil), nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
services := readOut(t, out, "en/services.gmi")
|
|
mustContain(t, "en/services.gmi", services, "# Services\n", "Write to squid (at) kmalloc.org.\n",
|
|
"```\nService Kept\n------- -------\nMail 30 days\n```\n", "=> /logo.svg The mark of kmalloc\n")
|
|
if strings.Contains(services, "<") || strings.Contains(services, "**") {
|
|
t.Errorf("the page has markup left:\n%s", services)
|
|
}
|
|
mustContain(t, "en/services.gmi navigation", services,
|
|
"=> /en/ kmalloc.org\n", "=> /en/manifesto.gmi Manifesto\n", "=> /en/people.gmi People\n", "=> /en/services.gmi Services\n", "=> /news/ News\n",
|
|
"=> /servizi.gmi Italiano\n")
|
|
manifesto := readOut(t, out, "es/manifesto.gmi")
|
|
mustContain(t, "es/manifesto.gmi", manifesto, "# Manifiesto\n", "Version 1.0, 2026-11-12\n", "Traduccion de la version 1.0.\n", "=> /es/manifesto.gmi Manifiesto\n")
|
|
home := readOut(t, out, "index.gmi")
|
|
mustContain(t, "index.gmi", home, "=> /news/ Tutte le news\n", "=> /news/2026/11/shop.gmi 2026-11-14 A shop\n", "=> /en/ English\n")
|
|
if strings.HasPrefix(home, "# ") && !strings.Contains(home, "kmalloc.org") {
|
|
t.Errorf("home has no title:\n%s", home)
|
|
}
|
|
}
|
|
|
|
// TestGeminiHomesLinkToTheNews checks that every home links to the one copy of the news.
|
|
func TestGeminiHomesLinkToTheNews(t *testing.T) {
|
|
out, err := buildGem(t, gemSite(nil), nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, rel := range []string{"index.gmi", "en/index.gmi"} {
|
|
mustContain(t, rel, readOut(t, out, rel), "=> /news/ ", "=> /news/2026/11/shop.gmi 2026-11-14 A shop\n")
|
|
}
|
|
}
|
|
|
|
// TestGeminiNews checks a post, the index, a category, the archive and the feed.
|
|
func TestGeminiNews(t *testing.T) {
|
|
out, err := buildGem(t, blogGem(), nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
post := readOut(t, out, "news/2026/11/shop.gmi")
|
|
mustContain(t, "post", post, "# A shop\n", "14 November 2026 · squid · FLUG · 1 min read\n", "About the shop.\n",
|
|
"There is a shop. Mail me at squid@kmalloc.org or visit the site.\n", "=> https://kmalloc.org/ the site\n",
|
|
"=> /news/category/flug.gmi FLUG\n", "=> https://social.kmalloc.org/@squid/115 Reply on Mastodon\n",
|
|
"=> /news/2026/11/status.gmi Older: Status page\n", "=> /news/ All news\n", "=> /en/manifesto.gmi Manifesto\n")
|
|
if strings.Contains(post, "Newer:") {
|
|
t.Error("the newest post has a link to a newer one")
|
|
}
|
|
gnu := readOut(t, out, "news/2026/09/gnu-linux-day-2026.gmi")
|
|
mustContain(t, "older post", gnu, "=> /en/people.gmi people\n", "=> /news/2026/11/status.gmi Newer: Status page\n")
|
|
index := readOut(t, out, "news/index.gmi")
|
|
mustContain(t, "index", index, "# News\n",
|
|
"=> /news/2026/11/shop.gmi 2026-11-14 A shop\nAbout the shop.\n", "=> /news/2026/11/status.gmi 2026-11-12 Status page\n",
|
|
"=> /news/category/flug.gmi FLUG (2)\n", "=> /news/2026/ 2026 (3)\n", "=> /news/2026/11/ November 2026 (2)\n", "=> /news/feed.gmi Feed\n")
|
|
category := readOut(t, out, "news/category/flug.gmi")
|
|
mustContain(t, "category", category, "# Category: FLUG\n", "=> /news/2026/11/shop.gmi 2026-11-14 A shop\n", "=> /news/2026/09/gnu-linux-day-2026.gmi 2026-09-18 GNU/Linux Day 2026\n")
|
|
month := readOut(t, out, "news/2026/11/index.gmi")
|
|
mustContain(t, "month", month, "# Archive: November 2026\n", "=> /news/2026/ Archive of the year 2026\n", "A shop")
|
|
if strings.Contains(month, "GNU/Linux") {
|
|
t.Error("the archive of November lists a post of September")
|
|
}
|
|
year := readOut(t, out, "news/2026/index.gmi")
|
|
mustContain(t, "year", year, "# Archive: 2026\n", "=> /news/2026/09/ September 2026 (1)\n", "=> /news/2026/11/ November 2026 (2)\n")
|
|
}
|
|
|
|
// blogGem is the site of the tests of the news pages.
|
|
func blogGem() map[string]string { return gemSite(nil) }
|
|
|
|
// TestGeminiFeed checks the feed: newest first, a date before each title.
|
|
func TestGeminiFeed(t *testing.T) {
|
|
out, err := buildGem(t, blogGem(), nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
feed := readOut(t, out, "news/feed.gmi")
|
|
want := "=> /news/2026/11/shop.gmi 2026-11-14 A shop\n=> /news/2026/11/status.gmi 2026-11-12 Status page\n=> /news/2026/09/gnu-linux-day-2026.gmi 2026-09-18 GNU/Linux Day 2026\n"
|
|
mustContain(t, "feed", feed, "# kmalloc.org: News\n", want)
|
|
if first := strings.Index(feed, "A shop"); first > strings.Index(feed, "Status page") {
|
|
t.Error("the feed is not newest first")
|
|
}
|
|
}
|
|
|
|
// TestGeminiNeverHasBrokenLinksOrEmptyFiles walks the whole capsule: no empty file, and every
|
|
// link that stays in the capsule leads to a file.
|
|
func TestGeminiNeverHasBrokenLinksOrEmptyFiles(t *testing.T) {
|
|
out, err := buildGem(t, blogGem(), nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
link := regexp.MustCompile(`(?m)^=> (\S+)`)
|
|
for _, f := range gemFiles(t, out) {
|
|
data, err := os.ReadFile(filepath.Join(out, filepath.FromSlash(f)))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(strings.TrimSpace(string(data))) == 0 && f != ".meta" {
|
|
t.Errorf("%s is empty", f)
|
|
}
|
|
if !strings.HasSuffix(f, ".gmi") {
|
|
continue
|
|
}
|
|
for _, m := range link.FindAllStringSubmatch(string(data), -1) {
|
|
target := m[1]
|
|
if strings.Contains(target, ":") || !strings.HasPrefix(target, "/") {
|
|
if !strings.Contains(target, ":") {
|
|
t.Errorf("%s has the relative link %s", f, target)
|
|
}
|
|
continue
|
|
}
|
|
rel := strings.TrimPrefix(target, "/")
|
|
if rel == "" || strings.HasSuffix(rel, "/") {
|
|
rel += "index.gmi"
|
|
}
|
|
if !exists(t, out, rel) {
|
|
t.Errorf("%s links to %s, which is not in the capsule", f, target)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestGeminiLinksMustResolve checks that a link to nothing stops the build and names the page and the address.
|
|
func TestGeminiLinksMustResolve(t *testing.T) {
|
|
for name, extra := range map[string]map[string]string{
|
|
"page": {"content/en/people.md": page("people", "People", "", "See [nowhere](/nowhere.html).\n")},
|
|
"post": {"news/broken.md": "Title: Broken\nDate: 2026-11-01T12:00:00+0100\n-\nSee [nowhere](/nowhere.html).\n"},
|
|
"unsafe scheme": {"content/en/people.md": page("people", "People", "", "[x](javascript:alert(1))\n")},
|
|
} {
|
|
t.Run(name, func(t *testing.T) {
|
|
_, err := buildGem(t, gemSite(extra), nil)
|
|
if err == nil || !strings.Contains(err.Error(), "nowhere.html") && !strings.Contains(err.Error(), "javascript") {
|
|
t.Errorf("error = %v, want one that names the address", err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestGeminiOnlyReferencedAssets checks that an asset is copied when a page uses it and not otherwise.
|
|
func TestGeminiOnlyReferencedAssets(t *testing.T) {
|
|
out, err := buildGem(t, gemSite(map[string]string{"content/en/services.md": page("services", "Services", "", "No image.\n")}), nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if exists(t, out, "logo.svg") {
|
|
t.Error("an asset no page uses is copied")
|
|
}
|
|
}
|
|
|
|
// TestGeminiDraftsAndFuture checks that hidden posts stay out of the capsule, as in the site.
|
|
func TestGeminiDraftsAndFuture(t *testing.T) {
|
|
out, err := buildGem(t, gemSite(postNews()), nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, f := range gemFiles(t, out) {
|
|
if strings.Contains(f, "a-draft") || strings.Contains(f, "in-future") || strings.Contains(f, "secret") {
|
|
t.Errorf("the capsule has %s, but the post is hidden", f)
|
|
}
|
|
}
|
|
with, err := buildGem(t, gemSite(postNews()), func(o *GeminiOptions) { o.Drafts = true })
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !exists(t, with, "news/2026/11/a-draft.gmi") {
|
|
t.Error("a build with drafts lacks the draft")
|
|
}
|
|
}
|
|
|
|
// TestGeminiBlockMustStandAlone checks the rule of the generated blocks.
|
|
func TestGeminiBlockMustStandAlone(t *testing.T) {
|
|
_, err := buildGem(t, gemSite(map[string]string{"content/en/people.md": page("people", "People", "", "Text {{news_list}} text.\n")}), nil)
|
|
if err == nil || !strings.Contains(err.Error(), "news_list") {
|
|
t.Errorf("error = %v, want one about {{news_list}}", err)
|
|
}
|
|
}
|
|
|
|
// TestGeminiWebPaths checks that a path the website serves by other means can stay a link to the website.
|
|
func TestGeminiWebPaths(t *testing.T) {
|
|
files := gemSite(map[string]string{
|
|
"site.json": strings.Replace(baseFiles()["site.json"], `"languages"`, `"gemini_web_paths": "/~, /pastes/", "languages"`, 1),
|
|
"content/en/people.md": page("people", "People", "", "Pages of the [people](/~squid/) and the [pastes](/pastes/x).\n"),
|
|
})
|
|
out, err := buildGem(t, files, nil)
|
|
if err != nil {
|
|
t.Fatalf("BuildGemini() error = %v", err)
|
|
}
|
|
mustContain(t, "en/people.gmi", readOut(t, out, "en/people.gmi"),
|
|
"=> https://kmalloc.org/~squid/ people\n", "=> https://kmalloc.org/pastes/x pastes\n")
|
|
if _, err := buildGem(t, gemSite(map[string]string{"content/en/people.md": page("people", "People", "", "[x](/~squid/)\n")}), nil); err == nil {
|
|
t.Error("a path of the website is a link when the site did not say so")
|
|
}
|
|
}
|
|
|
|
// TestGeminiHeadings checks that a page has one first level heading and that code is left alone.
|
|
func TestGeminiHeadings(t *testing.T) {
|
|
out, err := buildGem(t, gemSite(map[string]string{
|
|
"content/en/people.md": page("people", "People", "", "# People\n\n# Other\n\n```\n# a comment in code\n```\n"),
|
|
}), nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got := readOut(t, out, "en/people.gmi")
|
|
mustContain(t, "en/people.gmi", got, "# People\n\n## Other\n\n```\n# a comment in code\n```\n")
|
|
if strings.Count(got, "# People") != 1 {
|
|
t.Errorf("the title is repeated:\n%s", got)
|
|
}
|
|
home := readOut(t, out, "en/index.gmi")
|
|
mustContain(t, "en/index.gmi", home, "# kmalloc.org\n\n## Technology.\n")
|
|
}
|
|
|
|
// TestGeminiKeepsLinksToOtherProtocols checks the protocols that leave the capsule as they are.
|
|
func TestGeminiKeepsLinksToOtherProtocols(t *testing.T) {
|
|
out, err := buildGem(t, gemSite(map[string]string{"content/en/people.md": page("people", "People", "",
|
|
"[Mail](mailto:squid@kmalloc.org) [Pay](bitcoin:bc1qxyz) [Chat](xmpp:squid@kmalloc.org) [Capsule](gemini://example.org/)\n")}), nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
mustContain(t, "en/people.gmi", readOut(t, out, "en/people.gmi"),
|
|
"=> mailto:squid@kmalloc.org Mail\n", "=> bitcoin:bc1qxyz Pay\n", "=> xmpp:squid@kmalloc.org Chat\n", "=> gemini://example.org/ Capsule\n")
|
|
}
|
|
|
|
// TestGeminiTitleThatSaysTheHeading checks that a heading the title already says is not repeated, as in
|
|
// the real site where the page title is "kmalloc.org: Services" and the text starts with "# Services".
|
|
func TestGeminiTitleThatSaysTheHeading(t *testing.T) {
|
|
out, err := buildGem(t, gemSite(map[string]string{
|
|
"content/en/people.md": page("people", "kmalloc.org: People", "", "# People\n\nText.\n"),
|
|
}), nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got := readOut(t, out, "en/people.gmi")
|
|
if !strings.HasPrefix(got, "# kmalloc.org: People\n\nText.\n") {
|
|
t.Errorf("en/people.gmi starts with\n%q", got)
|
|
}
|
|
}
|
|
|
|
// TestGeminiFeedTitleIsNotPrefixedTwice checks the feed title when the news page title has the prefix already.
|
|
func TestGeminiFeedTitleIsNotPrefixedTwice(t *testing.T) {
|
|
out, err := buildGem(t, gemSite(map[string]string{
|
|
"content/en/news/index.md": page("news", "kmalloc.org: News", "", "{{news_list}}\n"),
|
|
}), nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := readOut(t, out, "news/feed.gmi"); !strings.HasPrefix(got, "# kmalloc.org: News\n") {
|
|
t.Errorf("news/feed.gmi starts with %q", got)
|
|
}
|
|
}
|
|
|
|
// TestGeminiTranslationNote checks that the note of a machine translated language reads as one sentence.
|
|
func TestGeminiTranslationNote(t *testing.T) {
|
|
files := gemSite(map[string]string{
|
|
"lang/es.json": strings.Replace(baseFiles()["lang/es.json"], `"translation_note": "Traduccion automatica."`, `"translation_note": "Traduccion automatica, avisa si ves un error:"`, 1),
|
|
})
|
|
out, err := buildGem(t, files, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
mustContain(t, "es/manifesto.gmi", readOut(t, out, "es/manifesto.gmi"),
|
|
"Traduccion automatica, avisa si ves un error: avisar.\n=> https://git.kmalloc.org/squid/kmalloc.org/issues avisar\n")
|
|
}
|
|
|
|
// TestGeminiMetaForPostsInAnotherLanguage checks that a post with its own Language has a line of its own in
|
|
// .meta, with the real path of its file and before the lines of the folders: the server uses the first line that
|
|
// matches a file, and the line of the news folder would hide a line that comes after it.
|
|
func TestGeminiMetaForPostsInAnotherLanguage(t *testing.T) {
|
|
files := gemSite(map[string]string{
|
|
"news/ciao.md": "Title: Ciao\nDate: 2026-11-05T09:00:00+0100\nLanguage: it\n-\nUn testo.\n",
|
|
"news/hola.md": "Title: Hola\nDate: 2026-11-04T09:00:00+0100\nLanguage: es\n-\nUn texto.\n",
|
|
"news/same.md": "Title: Same\nDate: 2026-11-03T09:00:00+0100\nLanguage: en\n-\nText.\n",
|
|
})
|
|
out, err := buildGem(t, files, nil)
|
|
if err != nil {
|
|
t.Fatalf("BuildGemini() error = %v", err)
|
|
}
|
|
want := "news/2026/11/ciao.gmi:;lang=it\nnews/2026/11/hola.gmi:;lang=es\n" +
|
|
"en/*:;lang=en\nen/**/*:;lang=en\nes/*:;lang=es\nes/**/*:;lang=es\nnews/*:;lang=en\nnews/**/*:;lang=en\n"
|
|
if got := readOut(t, out, ".meta"); got != want {
|
|
t.Errorf(".meta =\n%q\nwant\n%q", got, want)
|
|
}
|
|
for _, rel := range []string{"news/2026/11/ciao.gmi", "news/2026/11/hola.gmi"} {
|
|
if !exists(t, out, rel) {
|
|
t.Errorf("the .meta names %s, which is not in the capsule", rel)
|
|
}
|
|
}
|
|
// With English at the root and the news in English too, only the posts in other languages have a line.
|
|
plain, err := buildGem(t, files, func(o *GeminiOptions) { o.Language = "en" })
|
|
if err != nil {
|
|
t.Fatalf("BuildGemini() error = %v", err)
|
|
}
|
|
want = "news/2026/11/ciao.gmi:;lang=it\nnews/2026/11/hola.gmi:;lang=es\n" +
|
|
"it/*:;lang=it\nit/**/*:;lang=it\nes/*:;lang=es\nes/**/*:;lang=es\n"
|
|
if got := readOut(t, plain, ".meta"); got != want {
|
|
t.Errorf(".meta with English at the root =\n%q\nwant\n%q", got, want)
|
|
}
|
|
}
|
|
|
|
// TestGeminiNoNewsAtAll checks that a site without posts says so once, in the news list, and that the empty
|
|
// lists leave their headings out.
|
|
func TestGeminiNoNewsAtAll(t *testing.T) {
|
|
index := "# News\n\n{{news_list}}\n\n## Categories\n\n{{categories_list}}\n\n## Archive\n\n{{news_archive}}\n"
|
|
out, err := buildGem(t, gemSite(map[string]string{
|
|
"content/en/news/index.md": page("news", "News", "Layout: bare\n", index),
|
|
"news/shop.md": "", "news/gnu-linux-day-2026.md": "", "news/status.md": "",
|
|
}), nil)
|
|
if err != nil {
|
|
t.Fatalf("BuildGemini() error = %v", err)
|
|
}
|
|
got := readOut(t, out, "news/index.gmi")
|
|
if n := strings.Count(got, "No news yet."); n != 1 {
|
|
t.Errorf("the index says there is no news %d times, want once:\n%s", n, got)
|
|
}
|
|
for _, heading := range []string{"## Categories", "## Archive"} {
|
|
if strings.Contains(got, heading) {
|
|
t.Errorf("the index keeps the heading %q of an empty list:\n%s", heading, got)
|
|
}
|
|
}
|
|
mustContain(t, "news/index.gmi", got, "# News\n")
|
|
mustContain(t, "news/feed.gmi", readOut(t, out, "news/feed.gmi"), "# kmalloc.org: News\n")
|
|
home := readOut(t, out, "index.gmi")
|
|
if strings.Contains(home, "Tutte le news") {
|
|
t.Errorf("the home links to the news list of a site with no news:\n%s", home)
|
|
}
|
|
mustContain(t, "index.gmi", home, "# kmalloc.org\n")
|
|
}
|
|
|
|
// TestGeminiOnlyOnePost checks that a single post has no link to a newer or an older one, but has the one to all the news.
|
|
func TestGeminiOnlyOnePost(t *testing.T) {
|
|
out, err := buildGem(t, gemSite(map[string]string{"news/gnu-linux-day-2026.md": "", "news/status.md": ""}), nil)
|
|
if err != nil {
|
|
t.Fatalf("BuildGemini() error = %v", err)
|
|
}
|
|
post := readOut(t, out, "news/2026/11/shop.gmi")
|
|
for _, absent := range []string{"Older", "Newer"} {
|
|
if strings.Contains(post, absent) {
|
|
t.Errorf("the only post has %q:\n%s", absent, post)
|
|
}
|
|
}
|
|
mustContain(t, "the post", post, "=> /news/ All news\n")
|
|
}
|
|
|
|
// TestGeminiUnusualTitle checks that a title with quotes, an ampersand, a tag and non Latin letters is written as it is.
|
|
func TestGeminiUnusualTitle(t *testing.T) {
|
|
title := `Say "hi" & <b>go</b> ünï 日本語`
|
|
out, err := buildGem(t, gemSite(map[string]string{
|
|
"news/odd.md": "Title: " + title + "\nDate: 2026-11-15T09:00:00+0100\nCategories: Odd\n-\nText.\n",
|
|
}), nil)
|
|
if err != nil {
|
|
t.Fatalf("BuildGemini() error = %v", err)
|
|
}
|
|
mustContain(t, "the post", readOut(t, out, "news/2026/11/odd.gmi"), "# "+title+"\n")
|
|
mustContain(t, "news/feed.gmi", readOut(t, out, "news/feed.gmi"), "=> /news/2026/11/odd.gmi 2026-11-15 "+title+"\n")
|
|
mustContain(t, "news/index.gmi", readOut(t, out, "news/index.gmi"), "=> /news/2026/11/odd.gmi 2026-11-15 "+title+"\n")
|
|
mustContain(t, "the post below", readOut(t, out, "news/2026/11/shop.gmi"), "Newer: "+title)
|
|
for _, rel := range []string{"news/2026/11/odd.gmi", "news/index.gmi", "news/category/odd.gmi"} {
|
|
if strings.Contains(readOut(t, out, rel), "<") || strings.Contains(readOut(t, out, rel), "&") {
|
|
t.Errorf("%s has an HTML escape in the title", rel)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestGeminiLeavesTheLogoOut checks that the logo of the home page leaves no link line and no copied file.
|
|
func TestGeminiLeavesTheLogoOut(t *testing.T) {
|
|
out, err := buildGem(t, gemSite(map[string]string{
|
|
"content/en/services.md": page("services", "Services", "", "No image.\n"),
|
|
"content/en/index.md": page("home", "kmalloc.org", "Layout: bare\n", "<img class=\"logo\" src=\"/logo.svg\" alt=\"kmalloc\" width=\"112\">\n\n<h1 class=\"hero\">Technology.</h1>\n\n{{latest_news}}\n"),
|
|
}), nil)
|
|
if err != nil {
|
|
t.Fatalf("BuildGemini() error = %v", err)
|
|
}
|
|
home := readOut(t, out, "en/index.gmi")
|
|
if strings.Contains(home, "logo.svg") {
|
|
t.Errorf("the home links to the logo:\n%s", home)
|
|
}
|
|
if !strings.HasPrefix(home, "# kmalloc.org\n\n## Technology.\n") {
|
|
t.Errorf("the home starts with %q", home)
|
|
}
|
|
if exists(t, out, "logo.svg") {
|
|
t.Error("the logo is copied, and nothing points to it")
|
|
}
|
|
}
|