internal/termtext/org_test.go
45 lines · 1366 bytes
4 symbols in this file
1package termtext
2
3import (
4 "os"
5 "strings"
6 "testing"
7)
8
9func TestOrgGolden(t *testing.T) {
10 src, err := os.ReadFile("testdata/doc.org")
11 if err != nil {
12 t.Fatal(err)
13 }
14 golden(t, "doc.org.plain.golden", Org(string(src), Options{Base: "https://forge.test"}))
15 golden(t, "doc.org.60.golden", Org(string(src), Options{Width: 60, Base: "https://forge.test"}))
16 golden(t, "doc.org.60color.golden", Org(string(src), Options{Width: 60, Color: true, Base: "https://forge.test"}))
17}
18
19// #+INCLUDE reads nothing from the server's disk, and the keyword
20// itself renders nothing either.
21func TestOrgIncludeIsInert(t *testing.T) {
22 got := Org("#+INCLUDE: \"/etc/passwd\"\n\ntext\n", Options{})
23 if strings.Contains(got, "root:") {
24 t.Fatalf("include read a file: %q", got)
25 }
26 if strings.Contains(got, "#+INCLUDE") {
27 t.Fatalf("include rendered as text: %q", got)
28 }
29}
30
31// A keyword (dropped) followed by a blank line then a paragraph must
32// not leave the paragraph's leading LineBreak as a stray space.
33func TestOrgKeywordGapNoLeadingSpace(t *testing.T) {
34 got := Org("#+SETUPFILE: \"x\"\n\ntext\n", Options{})
35 if got != "text\n" {
36 t.Errorf("Org = %q, want %q", got, "text\n")
37 }
38}
39
40func TestOrgInlineDropsLinkTargets(t *testing.T) {
41 got := Inline("see [[https://x.test/a][the page]] now", "org")
42 if got != "see the page now" {
43 t.Errorf("Inline = %q", got)
44 }
45}