-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocument_attribute_test.go
100 lines (93 loc) · 1.81 KB
/
document_attribute_test.go
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
// SPDX-FileCopyrightText: 2024 M. Shulhan <[email protected]>
// SPDX-License-Identifier: GPL-3.0-or-later
package asciidoctor
import (
"testing"
"git.sr.ht/~shulhan/pakakeh.go/lib/test"
)
func TestDocumentAttributeApply(t *testing.T) {
type testCase struct {
desc string
key string
val string
expError string
exp DocumentAttribute
}
var docAttr = DocumentAttribute{
Entry: map[string]string{
`key1`: ``,
`key2`: ``,
},
}
var listCase = []testCase{{
key: `key3`,
exp: docAttr,
}, {
desc: `prefix negation`,
key: `!key1`,
exp: DocumentAttribute{
Entry: map[string]string{
`key2`: ``,
`key3`: ``,
},
},
}, {
desc: `suffix negation`,
key: `key2!`,
exp: DocumentAttribute{
Entry: map[string]string{
`key3`: ``,
},
},
}, {
desc: `leveloffset +`,
key: docAttrLevelOffset,
val: `+2`,
exp: DocumentAttribute{
Entry: map[string]string{
`key3`: ``,
`leveloffset`: `+2`,
},
LevelOffset: 2,
},
}, {
desc: `leveloffset -`,
key: docAttrLevelOffset,
val: `-2`,
exp: DocumentAttribute{
Entry: map[string]string{
`key3`: ``,
`leveloffset`: `-2`,
},
LevelOffset: 0,
},
}, {
desc: `leveloffset`,
key: docAttrLevelOffset,
val: `1`,
exp: DocumentAttribute{
Entry: map[string]string{
`key3`: ``,
`leveloffset`: `1`,
},
LevelOffset: 1,
},
}, {
desc: `leveloffset: invalid`,
key: docAttrLevelOffset,
val: `*1`,
expError: `DocumentAttribute: leveloffset: invalid value "*1"`,
}}
var (
tc testCase
err error
)
for _, tc = range listCase {
err = docAttr.apply(tc.key, tc.val)
if err != nil {
test.Assert(t, `apply: `+tc.desc, tc.expError, err.Error())
continue
}
test.Assert(t, `apply: `+tc.desc, tc.exp, docAttr)
}
}