-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathindent_spec.lua
More file actions
172 lines (143 loc) · 6.58 KB
/
indent_spec.lua
File metadata and controls
172 lines (143 loc) · 6.58 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
---@module 'luassert'
local util = require('tests.util')
describe('indent', function()
local lines = {
'',
'## Heading 2',
'',
'| Foo | Bar |',
'| --- | --- |',
'',
'# Heading 1',
'',
'Foo',
'',
'### Heading 3',
'',
'Bar',
}
---@return render.md.test.Marks
local function shared()
local marks, row = util.marks(), util.row()
marks:add(row:get(1), 0, util.heading.sign(2))
marks:add(row:get(0, 0), { 0, 2 }, util.heading.icon(2))
marks:add(row:get(0, 1), { 0, 0 }, util.heading.bg(2))
marks:add(row:get(1, 0), { 0, 1 }, util.table.pipe(true))
marks:add(row:get(0, 0), { 6, 7 }, util.table.pipe(true))
marks:add(row:get(0, 0), { 12, 13 }, util.table.pipe(true))
marks:add(
row:get(1, 0),
{ 0, 13 },
util.table.delimiter(0, { 5 }, { 5 })
)
marks:add(row:get(2), 0, util.heading.sign(1))
marks:add(row:get(0, 0), { 0, 1 }, util.heading.icon(1))
marks:add(row:get(0, 1), { 0, 0 }, util.heading.bg(1))
marks:add(row:get(3), 0, util.heading.sign(3))
marks:add(row:get(0, 0), { 0, 3 }, util.heading.icon(3))
marks:add(row:get(0, 1), { 0, 0 }, util.heading.bg(3))
return marks
end
---@return render.md.test.Marks
local function borders()
---@param level integer
---@param position 'above'|'below'
---@return vim.api.keyset.set_extmark
local function border(level, position)
local icon = position == 'above' and '▄' or '▀'
local background = ('Rm_RmH%dBg_bg_as_fg'):format(level)
---@type vim.api.keyset.set_extmark
return {
virt_text = { { icon:rep(vim.o.columns), background } },
virt_text_pos = 'overlay',
}
end
local marks, row = util.marks(), util.row()
marks:add(row:get(0), 0, border(2, 'above'))
marks:add(row:get(2), 0, border(2, 'below'))
marks:add(row:get(3), 0, border(1, 'above'))
marks:add(row:get(2), 0, border(1, 'below'))
marks:add(row:get(2), 0, border(3, 'above'))
marks:add(row:get(2), 0, border(3, 'below'))
return marks
end
it('with heading border & no icon', function()
util.setup.text(lines, {
heading = { border = true },
indent = { enabled = true, icon = '' },
})
local marks, row = shared(), util.row()
marks:extend(borders())
local l2, l3 = { 2 }, { 4 }
marks:add(row:get(0), 0, util.indent.inline(l2))
marks:add(row:get(1), 0, util.indent.inline(l2))
marks:add(row:get(1), 0, util.indent.inline(l2))
marks:add(
row:get(1),
0,
util.indent.virtual(util.table.border(true, true, 5, 5), l2)
)
marks:add(row:get(0), 0, util.indent.inline(l2))
marks:add(row:get(1), 0, util.indent.inline(l2))
marks:add(row:get(5), 0, util.indent.inline(l3))
marks:add(row:get(1), 0, util.indent.inline(l3))
marks:add(row:get(1), 0, util.indent.inline(l3))
marks:add(row:get(1), 0, util.indent.inline(l3))
util.assert_view(marks, {
' ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄',
' Heading 2',
' ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀',
' ┌─────┬─────┐',
' │ Foo │ Bar │',
' ├─────┼─────┤',
' ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄',
' Heading 1',
' ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀',
' Foo',
' ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄',
' Heading 3',
' ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀',
' Bar',
})
end)
it('with per_level & skip_level', function()
util.setup.text(lines, {
indent = { enabled = true, per_level = 4, skip_level = 0 },
})
local marks, row = shared(), util.row()
local l1, l2 = { 1, 3 }, { 1, 3, 1, 3 }
marks:add(row:get(0), 0, util.indent.inline(l2))
marks:add(row:get(1), 0, util.indent.inline(l2))
marks:add(row:get(1), 0, util.indent.inline(l2))
marks:add(
row:get(1),
0,
util.indent.virtual(util.table.border(true, true, 5, 5), l2)
)
marks:add(row:get(0), 0, util.indent.inline(l2))
marks:add(row:get(1), 0, util.indent.inline(l2))
for _ = 1, 4 do
marks:add(row:get(1), 0, util.indent.inline(l1))
end
for _ = 1, 4 do
marks:add(row:get(1), 0, util.indent.inline(l1))
marks:add(row:get(0), 0, util.indent.inline(l2))
end
util.assert_view(marks, {
' ▎ ▎',
' ▎ ▎ Heading 2',
' ▎ ▎',
' ▎ ▎ ┌─────┬─────┐',
' ▎ ▎ │ Foo │ Bar │',
' ▎ ▎ ├─────┼─────┤',
' ▎',
' ▎ Heading 1',
' ▎',
' ▎ Foo',
' ▎ ▎ ▎',
' ▎ ▎ ▎ Heading 3',
' ▎ ▎ ▎',
' ▎ ▎ ▎ Bar',
})
end)
end)