File: roff_test.go

package info (click to toggle)
go-md2man 1.0.8%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, buster-backports
  • size: 132 kB
  • sloc: sh: 18; makefile: 10
file content (97 lines) | stat: -rw-r--r-- 2,090 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package md2man

import (
	"bytes"
	"testing"
)

func TestTitleBlock(t *testing.T) {
	r := &roffRenderer{}
	buf := bytes.NewBuffer(nil)

	title := []byte("% stuff\n% more stuff\n% even more stuff")

	r.TitleBlock(buf, title)
	expected := ".TH \"stuff\" \"more stuff\" \"even more stuff\" \n.nh\n.ad l\n"
	actual := buf.String()
	if expected != actual {
		t.Fatalf("expected:\n%s\nactual:\n%s", expected, actual)
	}
}

func TestBlockCode(t *testing.T) {
	r := &roffRenderer{}
	buf := bytes.NewBuffer(nil)

	code := []byte("$ echo hello world\nhello world\n")
	r.BlockCode(buf, code, "")

	expected := `
.PP
.RS

.nf
$ echo hello world
hello world

.fi
.RE
`
	result := buf.String()
	if expected != result {
		t.Fatalf("got incorrect output:\nexpected:\n%v\n\ngot:\n%v", expected, result)
	}
}

func TestTableCell(t *testing.T) {
	r := &roffRenderer{}
	buf := bytes.NewBuffer(nil)
	cell := []byte{}

	r.TableCell(buf, cell, 0)
	expected := " "
	if buf.String() != expected {
		t.Fatalf("expected %q, got %q", expected, buf.String())
	}

	r.TableCell(buf, cell, 0)
	expected += "\t "
	if buf.String() != expected {
		t.Fatalf("expected %q, got %q", expected, buf.String())
	}

	cell = []byte("*")
	r.TableCell(buf, cell, 0)
	expected += "\t*"
	if buf.String() != expected {
		t.Fatalf("expected %q, got %q", expected, buf.String())
	}

	cell = []byte("this is a test with some really long string")
	r.TableCell(buf, cell, 0)
	expected += "\tT{\nthis is a test with some really long string\nT}"
	if buf.String() != expected {
		t.Fatalf("expected %q, got %q", expected, buf.String())
	}

	cell = []byte("some short string")
	r.TableCell(buf, cell, 0)
	expected += "\tsome short string"
	if buf.String() != expected {
		t.Fatalf("expected %q, got %q", expected, buf.String())
	}

	cell = []byte{}
	r.TableCell(buf, cell, 0)
	expected += "\t "
	if buf.String() != expected {
		t.Fatalf("expected %q, got %q", expected, buf.String())
	}

	cell = []byte("*")
	r.TableCell(buf, cell, 0)
	expected += "\t*"
	if buf.String() != expected {
		t.Fatalf("expected %q, got %q", expected, buf.String())
	}
}