Skip to content

Commit 3368691

Browse files
chore: add screenstring information to all unit tests
## Details Using screenstring for each row & column we can get a much better idea of how things actually look to users. Store this in an array of lines and compare to an expected value. Keep the existing tests using extmarks since those validate additional information like highlights which we cannot get from the grid alone. The only strange thing is we need to trigger a redraw since we're running in headless mode which does not draw anything by default. Does take longer for the tests to run, but still pretty fast in general.
1 parent d80acb3 commit 3368691

17 files changed

+412
-86
lines changed

benches/medium_spec.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local util = require('benches.util')
44

55
describe('medium.md', function()
66
it('default', function()
7-
local base_marks = 61
7+
local base_marks = 85
88
util.less_than(util.setup('temp/medium.md'), 35)
99
util.num_marks(base_marks)
1010

benches/medium_table_spec.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ local util = require('benches.util')
44

55
describe('medium-table.md', function()
66
it('default', function()
7-
local base_marks = 241
8-
util.less_than(util.setup('temp/medium-table.md'), 110)
7+
local base_marks = 337
8+
util.less_than(util.setup('temp/medium-table.md'), 120)
99
util.num_marks(base_marks)
1010

1111
util.less_than(util.move_down(1), 0.5)

benches/readme_spec.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ local util = require('benches.util')
44

55
describe('README.md', function()
66
it('default', function()
7-
local base_marks = 73
8-
util.less_than(util.setup('README.md'), 50)
7+
local base_marks = 100
8+
util.less_than(util.setup('README.md'), 60)
99
util.num_marks(base_marks)
1010

1111
util.less_than(util.move_down(1), 0.5)

doc/render-markdown.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.10.0 Last change: 2024 November 08
1+
*render-markdown.txt* For 0.10.0 Last change: 2024 November 10
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*

tests/ad_hoc_spec.lua

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,18 @@ describe('ad_hoc.md', function()
7171
bullet_link(row:increment(), 59, '', 'Link', nil),
7272
})
7373

74-
local actual = util.get_actual_marks()
75-
util.marks_are_equal(expected, actual)
74+
util.assert_view(expected, {
75+
'󰫎 1 󰲡 Heading',
76+
' 2',
77+
'󰫎 3 󰲣 Heading 2 Line 1',
78+
' 4 Heading 2 Line 2',
79+
' 5',
80+
' 6',
81+
' 7 ● Normal Shortcut',
82+
' 8 ● 󱗖 Basic One Then normal text',
83+
' 9 ● 󱗖 With Alias Something important',
84+
' 10 ● 󰀓 [email protected] Email',
85+
' 11 ●  Youtube Link',
86+
})
7687
end)
7788
end)

tests/box_dash_quote_spec.lua

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ local function dash(row)
2525
return {
2626
row = { row },
2727
col = { 0 },
28-
virt_text = { { string.rep('', vim.opt.columns:get()), util.hl('Dash') } },
28+
virt_text = { { string.rep('', vim.o.columns), util.hl('Dash') } },
2929
virt_text_pos = 'overlay',
3030
}
3131
end
@@ -52,7 +52,18 @@ describe('box_dash_quote.md', function()
5252
util.quote(row:increment(), ' %s ', 'Quote'),
5353
})
5454

55-
local actual = util.get_actual_marks()
56-
util.marks_are_equal(expected, actual)
55+
util.assert_view(expected, {
56+
'󰫎 1 󰲡 Checkbox / Dash / Quote',
57+
' 2',
58+
' 3 󰄱 Unchecked Checkbox',
59+
' 4 󰱒 Checked Checkbox',
60+
' 5 󰥔 Todo Checkbox',
61+
' 6 ● Regular List Item',
62+
' 7',
63+
' 8 ──────────────────────────────────────────────────────────────────────────',
64+
' 9',
65+
' 10 ▋ Quote line 1',
66+
' 11 ▋ Quote line 2',
67+
})
5768
end)
5869
end)

tests/callout_spec.lua

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,42 @@ describe('callout.md', function()
8282
util.quote(row:increment(), '%s ', error),
8383
})
8484

85-
local actual = util.get_actual_marks()
86-
util.marks_are_equal(expected, actual)
85+
util.assert_view(expected, {
86+
'󰫎 1 󰲡 Note',
87+
' 2',
88+
' 3 ▋ 󰋽 Note',
89+
' 4 ▋',
90+
' 5 ▋ A regular note',
91+
' 6 ▋',
92+
' 7 ▋ With a second paragraph',
93+
' 8',
94+
'󰫎 9 󰲡 Tip',
95+
' 10',
96+
' 11 ▋ 󰌶 Tip',
97+
' 12 ▋',
98+
'󰢱 13 ▋ 󰢱 lua',
99+
" 14 ▋ print('Standard tip')",
100+
' 15 ▋ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀',
101+
' 16',
102+
'󰫎 17 󰲡 Important',
103+
' 18',
104+
' 19 ▋ 󰅾 Important',
105+
' 20 ▋ Exceptional info',
106+
' 21',
107+
'󰫎 22 󰲡 Warning',
108+
' 23',
109+
' 24 ▋ 󰀪 Custom Title',
110+
' 25 ▋ Dastardly surprise',
111+
' 26',
112+
'󰫎 27 󰲡 Caution',
113+
' 28',
114+
' 29 ▋ 󰳦 Caution',
115+
' 30 ▋ Cautionary tale',
116+
' 31',
117+
'󰫎 32 󰲡 Bug',
118+
' 33',
119+
' 34 ▋ 󰨰 Bug',
120+
' 35 ▋ Custom bug',
121+
})
87122
end)
88123
end)

tests/code_spec.lua

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,36 @@ describe('code.md', function()
7070
util.code_border(row:increment(), 0, false),
7171
})
7272

73-
local actual = util.get_actual_marks()
74-
util.marks_are_equal(expected, actual)
73+
util.assert_view(expected, {
74+
'󰫎 1 󰲡 Heading',
75+
' 2',
76+
'󱘗 3 󱘗 rust',
77+
' 4 fn main() {',
78+
' 5 println!("Hello, World!");',
79+
' 6 }',
80+
' 7 ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀',
81+
' 8',
82+
' 9 ● Nested code',
83+
' 10',
84+
'󰢱 11 󰢱 lua',
85+
" 12 print('hello')",
86+
" 13 print('world')",
87+
' 14 ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀',
88+
' 15',
89+
' 16 ● Nested code with blank',
90+
' 17',
91+
'󰢱 18 󰢱 lua',
92+
" 19 print('hello')",
93+
' 20',
94+
" 21 print('world')",
95+
' 22 ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀',
96+
' 23',
97+
' 24 ● No language',
98+
' 25',
99+
' 26 ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄',
100+
" 27 print('Hello, World!')",
101+
' 28 ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀',
102+
})
75103
end)
76104

77105
it('block padding', function()
@@ -122,17 +150,45 @@ describe('code.md', function()
122150
end
123151
table.insert(expected, util.code_border(row:increment(), 2, false, width_3))
124152

125-
local width_4 = (2 * vim.opt.tabstop:get()) + 24
153+
local width_4 = (2 * vim.o.tabstop) + 24
126154
vim.list_extend(expected, {
127155
util.bullet(row:increment(2), 0, 1),
128156
util.code_border(row:increment(2), 0, true, width_4),
129-
padding(row:increment(), 0, 0, vim.opt.tabstop:get(), 0),
157+
padding(row:increment(), 0, 0, vim.o.tabstop, 0),
130158
util.code_hide(row:get(), 0, width_4),
131159
util.code_row(row:get(), 0),
132160
util.code_border(row:increment(), 0, false, width_4),
133161
})
134162

135-
local actual = util.get_actual_marks()
136-
util.marks_are_equal(expected, actual)
163+
util.assert_view(expected, {
164+
'󰫎 1 󰲡 Heading',
165+
' 2',
166+
'󱘗 3 󱘗 rust',
167+
' 4 fn main() {',
168+
' 5 println!("Hello, World!");',
169+
' 6 }',
170+
' 7 ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀',
171+
' 8',
172+
' 9 ● Nested code',
173+
' 10',
174+
'󰢱 11 󰢱 lua',
175+
" 12 print('hello')",
176+
" 13 print('world')",
177+
' 14 ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀',
178+
' 15',
179+
' 16 ● Nested code with blank',
180+
' 17',
181+
'󰢱 18 󰢱 lua',
182+
" 19 print('hello')",
183+
' 20',
184+
" 21 print('world')",
185+
' 22 ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀',
186+
' 23',
187+
' 24 ● No language',
188+
' 25',
189+
' 26 ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄',
190+
" 27 print('Hello, World!')",
191+
' 28 ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀',
192+
})
137193
end)
138194
end)

tests/custom_handler_spec.lua

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,17 @@ describe('custom_handler.md', function()
9595
{}, -- No backslash escapes
9696
})
9797

98-
local actual = util.get_actual_marks()
99-
util.marks_are_equal(expected, actual)
98+
util.assert_view(expected, {
99+
'󰫎 1 󰲡 Heading',
100+
' 2',
101+
' 3 Inline code',
102+
' 4',
103+
' 5 \\$1.50 \\$3.55',
104+
' 6',
105+
' 7 Some ==highlighted text== line',
106+
' 8 Across ==multiple',
107+
' 9 lines== of text',
108+
})
100109
end)
101110

102111
it('custom conceal override', function()
@@ -113,8 +122,17 @@ describe('custom_handler.md', function()
113122
{ util.conceal(row:increment(4), 0, 1), util.conceal(row:get(), 7, 8) }, -- Backslash escapes
114123
})
115124

116-
local actual = util.get_actual_marks()
117-
util.marks_are_equal(expected, actual)
125+
util.assert_view(expected, {
126+
'󰫎 1 󰲡 Heading',
127+
' 2',
128+
' 3 Inline code',
129+
' 4',
130+
' 5 $1.50 $3.55',
131+
' 6',
132+
' 7 Some ==highlighted text== line',
133+
' 8 Across ==multiple',
134+
' 9 lines== of text',
135+
})
118136
end)
119137

120138
it('custom conceal extend', function()
@@ -131,8 +149,17 @@ describe('custom_handler.md', function()
131149
{ util.conceal(row:increment(2), 0, 1), util.conceal(row:get(), 7, 8) }, -- Backslash escapes
132150
})
133151

134-
local actual = util.get_actual_marks()
135-
util.marks_are_equal(expected, actual)
152+
util.assert_view(expected, {
153+
'󰫎 1 󰲡 Heading',
154+
' 2',
155+
' 3 Inline code',
156+
' 4',
157+
' 5 $1.50 $3.55',
158+
' 6',
159+
' 7 Some ==highlighted text== line',
160+
' 8 Across ==multiple',
161+
' 9 lines== of text',
162+
})
136163
end)
137164

138165
it('custom highlight extend', function()
@@ -152,7 +179,16 @@ describe('custom_handler.md', function()
152179
highlight_equals({ row:increment(), row:increment() }, { 7, 7 }), -- Highlight equals 2
153180
})
154181

155-
local actual = util.get_actual_marks()
156-
util.marks_are_equal(expected, actual)
182+
util.assert_view(expected, {
183+
'󰫎 1 󰲡 Heading',
184+
' 2',
185+
' 3 Inline code',
186+
' 4',
187+
' 5 $1.50 $3.55',
188+
' 6',
189+
' 7 Some highlighted text line',
190+
' 8 Across multiple',
191+
' 9 lines of text',
192+
})
157193
end)
158194
end)

tests/ft_override_spec.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ describe('ft_override.md', function()
66
it('default', function()
77
util.setup('tests/data/ft_override.md')
88

9-
local actual = util.get_actual_marks()
10-
util.marks_are_equal({}, actual)
9+
util.assert_marks({})
1110
end)
1211
end)

0 commit comments

Comments
 (0)