-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathstyle_test.go
More file actions
105 lines (95 loc) · 2.95 KB
/
Copy pathstyle_test.go
File metadata and controls
105 lines (95 loc) · 2.95 KB
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
98
99
100
101
102
103
104
105
package main
import (
"strings"
"testing"
)
func TestScanStyleTokens(t *testing.T) {
data := []byte(" \t'hello'world")
advance, token, err := ScanStyleTokens(data, false)
if err != nil || advance != 9 || string(token) != "'hello'" {
t.Error(err, string(token), advance)
}
advance0, token0, err0 := ScanStyleTokens(data[advance:], false)
if err0 != nil || advance0 != 0 || token0 != nil {
t.Error(err0, string(token0), advance0)
}
advance1, token1, err1 := ScanStyleTokens(data[advance:], true)
if err1 != nil || advance1 != 5 || string(token1) != "world" {
t.Error(err1, string(token1), advance1)
}
}
func TestScanStyleTokens_comment(t *testing.T) {
data := []byte("%comment\nfoo bar")
adv, tok, err := ScanStyleTokens(data, false)
if err != nil || string(tok) != "foo" || adv != 12 {
t.Error(err, string(tok), adv)
}
data0 := []byte("\n%c\n\n%c\nfoo%c\nbar")
adv0, tok0, err0 := ScanStyleTokens(data0, false)
if err0 != nil || string(tok0) != "foo" || adv0 != 11 {
t.Error(err0, string(tok0), adv0)
}
adv1, tok1, err1 := ScanStyleTokens(data0[adv0:], true)
if err1 != nil || string(tok1) != "bar" || adv1 != 6 {
t.Error(err1, string(tok1), adv1)
}
}
func TestScanStyleTokensBacktick(t *testing.T) {
data := []byte("`hello` world")
advance, token, err := ScanStyleTokens(data, false)
if err != nil {
t.Fatal(err)
}
if string(token) != "`hello`" {
t.Fatalf("first token = %q, want %q", string(token), "`hello`")
}
if advance != len("`hello`") {
t.Fatalf("advance = %d, want %d", advance, len("`hello`"))
}
}
func TestUnquote(t *testing.T) {
if got := unquote(`"hello"`); got != "hello" {
t.Fatalf("unquote(\"\\\"hello\\\"\") = %q, want %q", got, "hello")
}
if got := unquote("`hello`"); got != "hello" {
t.Fatalf("unquote(%q) = %q, want %q", "`hello`", got, "hello")
}
}
func TestParseInt(t *testing.T) {
if got := parseInt("42"); got != 42 {
t.Fatalf("parseInt(%q) = %d, want %d", "42", got, 42)
}
if got := parseInt("0"); got != 0 {
t.Fatalf("parseInt(%q) = %d, want %d", "0", got, 0)
}
}
func TestNewInputStyle(t *testing.T) {
style := NewInputStyle()
if style.keyword != "\\indexentry" {
t.Fatalf("keyword = %q, want %q", style.keyword, "\\indexentry")
}
if style.arg_open != '{' {
t.Fatalf("arg_open = %q, want %q", style.arg_open, '{')
}
if style.level != '!' {
t.Fatalf("level = %q, want %q", style.level, '!')
}
if style.comment != '%' {
t.Fatalf("comment = %q, want %q", style.comment, '%')
}
}
func TestNewOutputStyle(t *testing.T) {
style := NewOutputStyle()
if !strings.Contains(style.preamble, "\\begin{theindex}") {
t.Fatalf("preamble = %q, want to contain %q", style.preamble, "\\begin{theindex}")
}
if style.delim_r != "--" {
t.Fatalf("delim_r = %q, want %q", style.delim_r, "--")
}
if style.page_precedence != "rnaRA" {
t.Fatalf("page_precedence = %q, want %q", style.page_precedence, "rnaRA")
}
if style.headings_flag != 0 {
t.Fatalf("headings_flag = %d, want %d", style.headings_flag, 0)
}
}