Skip to content

Commit 8b6663b

Browse files
chore: add row class for unit testing
## Details Add a Row class used in unit tests which tracks the current row and implements a get and increment method. This allows new lines to be inserted in any test files without needing to modify the row numbers manually for all marks below the added one. This is because all marks are already sorted by row so adding an additional increment call will automatically shift all lower marks down. This only works if the same row instance is used to generate all the expected marks which is why it has been added to all test classes as the only way to get the row value, no hard coded integers.
1 parent 275f289 commit 8b6663b

11 files changed

+235
-207
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
- anti-conceal margin [abc02f3](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/abc02f35cd6cb28e9b8eb37c88fc863a546367bf)
99
- log error when mark is skipped [#132](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/132)
1010
[7986be4](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/7986be47531d652e950776536987e01dd5b55b94)
11+
- checkbox: position [#140](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/140)
12+
[275f289](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/275f28943ab9ce6017f90bab56c5b5b3c651c269)
1113

1214
### Bug Fixes
1315

tests/ad_hoc_spec.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ describe('ad_hoc.md', function()
2222
it('default', function()
2323
util.setup('tests/data/ad_hoc.md')
2424

25-
local expected = {}
25+
local expected, row = {}, util.row()
2626

27-
vim.list_extend(expected, util.heading(0, 1))
27+
vim.list_extend(expected, util.heading(row:get(), 1))
2828

2929
vim.list_extend(expected, {
30-
wiki_link(4, 0, 13, 'Basic One'),
31-
wiki_link(6, 0, 23, 'With Alias'),
30+
wiki_link(row:increment(4), 0, 13, 'Basic One'),
31+
wiki_link(row:increment(2), 0, 23, 'With Alias'),
3232
})
3333

3434
local actual = util.get_actual_marks()

tests/box_dash_quote_spec.lua

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,22 @@ describe('box_dash_quote.md', function()
4040
it('default', function()
4141
util.setup('demo/box_dash_quote.md')
4242

43-
local expected = {}
43+
local expected, row = {}, util.row()
4444

45-
vim.list_extend(expected, util.heading(0, 1))
45+
vim.list_extend(expected, util.heading(row:get(), 1))
4646

4747
vim.list_extend(expected, {
48-
checkbox(2, '󰄱 ', 'Unchecked'),
49-
checkbox(3, '󰱒 ', 'Checked'),
50-
checkbox(4, '󰥔 ', 'Todo'),
51-
util.bullet(5, 0, 1),
48+
checkbox(row:increment(2), '󰄱 ', 'Unchecked'),
49+
checkbox(row:increment(), '󰱒 ', 'Checked'),
50+
checkbox(row:increment(), '󰥔 ', 'Todo'),
51+
util.bullet(row:increment(), 0, 1),
5252
})
5353

54-
table.insert(expected, dash(7))
54+
table.insert(expected, dash(row:increment(2)))
5555

5656
vim.list_extend(expected, {
57-
util.quote(9, ' %s ', 'Quote'),
58-
util.quote(10, ' %s ', 'Quote'),
57+
util.quote(row:increment(2), ' %s ', 'Quote'),
58+
util.quote(row:increment(), ' %s ', 'Quote'),
5959
})
6060

6161
local actual = util.get_actual_marks()

tests/callout_spec.lua

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -24,65 +24,59 @@ describe('callout.md', function()
2424
it('default', function()
2525
util.setup('demo/callout.md')
2626

27-
local info = 'Info'
28-
local ok = 'Success'
29-
local hint = 'Hint'
30-
local warn = 'Warn'
31-
local error = 'Error'
32-
33-
local expected = {}
27+
local expected, row = {}, util.row()
3428

35-
local note_start = 0
29+
local info = 'Info'
3630
vim.list_extend(expected, {
37-
util.heading(note_start, 1),
38-
util.quote(note_start + 2, '%s ', info),
39-
callout(note_start + 2, 2, 9, '󰋽 Note', info),
40-
util.quote(note_start + 3, '%s', info),
41-
util.quote(note_start + 4, '%s ', info),
42-
util.quote(note_start + 5, '%s', info),
43-
util.quote(note_start + 6, '%s ', info),
31+
util.heading(row:get(), 1),
32+
util.quote(row:increment(2), '%s ', info),
33+
callout(row:get(), 2, 9, '󰋽 Note', info),
34+
util.quote(row:increment(), '%s', info),
35+
util.quote(row:increment(), '%s ', info),
36+
util.quote(row:increment(), '%s', info),
37+
util.quote(row:increment(), '%s ', info),
4438
})
4539

46-
local tip_start = 8
40+
local ok = 'Success'
4741
vim.list_extend(expected, {
48-
util.heading(tip_start, 1),
49-
util.quote(tip_start + 2, '%s ', ok),
50-
callout(tip_start + 2, 2, 8, '󰌶 Tip', ok),
51-
util.quote(tip_start + 3, '%s', ok),
52-
util.quote(tip_start + 4, '%s ', ok),
53-
util.code_row(tip_start + 4, 2),
54-
util.code_language(tip_start + 4, 5, 8, 'lua'),
55-
util.quote(tip_start + 5, '%s ', ok),
56-
util.code_row(tip_start + 5, 2),
57-
util.quote(tip_start + 6, '%s ', ok),
58-
util.code_below(tip_start + 6, 2),
42+
util.heading(row:increment(2), 1),
43+
util.quote(row:increment(2), '%s ', ok),
44+
callout(row:get(), 2, 8, '󰌶 Tip', ok),
45+
util.quote(row:increment(), '%s', ok),
46+
util.quote(row:increment(), '%s ', ok),
47+
util.code_row(row:get(), 2),
48+
util.code_language(row:get(), 5, 8, 'lua'),
49+
util.quote(row:increment(), '%s ', ok),
50+
util.code_row(row:get(), 2),
51+
util.quote(row:increment(), '%s ', ok),
52+
util.code_below(row:get(), 2),
5953
})
6054

61-
local important_start = 16
55+
local hint = 'Hint'
6256
vim.list_extend(expected, {
63-
util.heading(important_start, 1),
64-
util.quote(important_start + 2, '%s ', hint),
65-
callout(important_start + 2, 2, 14, '󰅾 Important', hint),
66-
util.quote(important_start + 3, '%s ', hint),
57+
util.heading(row:increment(2), 1),
58+
util.quote(row:increment(2), '%s ', hint),
59+
callout(row:get(), 2, 14, '󰅾 Important', hint),
60+
util.quote(row:increment(1), '%s ', hint),
6761
})
6862

69-
local warning_start = 21
63+
local warn = 'Warn'
7064
vim.list_extend(expected, {
71-
util.heading(warning_start, 1),
72-
util.quote(warning_start + 2, '%s ', warn),
73-
callout(warning_start + 2, 2, 12, '󰀪 Custom Title', warn, ''),
74-
util.quote(warning_start + 3, '%s ', warn),
65+
util.heading(row:increment(2), 1),
66+
util.quote(row:increment(2), '%s ', warn),
67+
callout(row:get(), 2, 12, '󰀪 Custom Title', warn, ''),
68+
util.quote(row:increment(), '%s ', warn),
7569
})
7670

77-
local caution_start = 26
71+
local error = 'Error'
7872
vim.list_extend(expected, {
79-
util.heading(caution_start, 1),
80-
util.quote(caution_start + 2, '%s ', error),
81-
callout(caution_start + 2, 2, 12, '󰳦 Caution', error),
82-
util.quote(caution_start + 3, '%s ', error),
73+
util.heading(row:increment(2), 1),
74+
util.quote(row:increment(2), '%s ', error),
75+
callout(row:get(), 2, 12, '󰳦 Caution', error),
76+
util.quote(row:increment(), '%s ', error),
8377
})
8478

85-
vim.list_extend(expected, util.heading(31, 1))
79+
vim.list_extend(expected, util.heading(row:increment(2), 1))
8680

8781
local actual = util.get_actual_marks()
8882
util.marks_are_equal(expected, actual)

tests/code_spec.lua

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@ describe('code.md', function()
66
it('default', function()
77
util.setup('tests/data/code.md')
88

9-
local expected = {}
9+
local expected, row = {}, util.row()
1010

11-
vim.list_extend(expected, util.heading(0, 1))
11+
vim.list_extend(expected, util.heading(row:get(), 1))
1212

1313
vim.list_extend(expected, {
14-
util.bullet(2, 0, 1),
15-
util.code_row(4, 2),
16-
util.code_language(4, 5, 8, 'lua'),
17-
util.code_row(5, 2),
18-
util.code_row(6, 2),
19-
util.code_below(7, 2),
14+
util.bullet(row:increment(2), 0, 1),
15+
util.code_row(row:increment(2), 2),
16+
util.code_language(row:get(), 5, 8, 'lua'),
17+
util.code_row(row:increment(), 2),
18+
util.code_row(row:increment(), 2),
19+
util.code_below(row:increment(), 2),
2020
})
2121

2222
vim.list_extend(expected, {
23-
util.bullet(9, 0, 1),
24-
util.code_row(11, 2),
25-
util.code_language(11, 5, 8, 'lua'),
26-
util.code_row(12, 2),
27-
util.code_row(13, 0),
28-
util.padding(13, 2),
29-
util.code_row(14, 2),
30-
util.code_below(15, 2),
23+
util.bullet(row:increment(2), 0, 1),
24+
util.code_row(row:increment(2), 2),
25+
util.code_language(row:get(), 5, 8, 'lua'),
26+
util.code_row(row:increment(), 2),
27+
util.code_row(row:increment(), 0),
28+
util.padding(row:get(), 2),
29+
util.code_row(row:increment(), 2),
30+
util.code_below(row:increment(), 2),
3131
})
3232

3333
local actual = util.get_actual_marks()

tests/custom_handler_spec.lua

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ describe('custom_handler.md', function()
4242
it('default', function()
4343
util.setup('tests/data/custom_handler.md')
4444

45-
local expected = {
46-
util.heading(0, 1), -- Heading
47-
util.inline_code(2, 0, 8), -- Inline code
45+
local expected, row = {}, util.row()
46+
vim.list_extend(expected, {
47+
util.heading(row:get(), 1), -- Heading
48+
util.inline_code(row:increment(2), 0, 8), -- Inline code
4849
{}, -- No backslash escapes
49-
}
50+
})
5051

5152
local actual = util.get_actual_marks()
5253
util.marks_are_equal(expected, actual)
@@ -61,11 +62,12 @@ describe('custom_handler.md', function()
6162
},
6263
})
6364

64-
local expected = {
65-
util.heading(0, 1), -- Heading
65+
local expected, row = {}, util.row()
66+
vim.list_extend(expected, {
67+
util.heading(row:get(), 1), -- Heading
6668
{}, -- No inline code
67-
{ backslash(4, 0), backslash(4, 7) }, -- Backslash escapes
68-
}
69+
{ backslash(row:increment(4), 0), backslash(row:get(), 7) }, -- Backslash escapes
70+
})
6971

7072
local actual = util.get_actual_marks()
7173
util.marks_are_equal(expected, actual)
@@ -81,11 +83,12 @@ describe('custom_handler.md', function()
8183
},
8284
})
8385

84-
local expected = {
85-
util.heading(0, 1), -- Heading
86-
util.inline_code(2, 0, 8), -- Inline code
87-
{ backslash(4, 0), backslash(4, 7) }, -- Backslash escapes
88-
}
86+
local expected, row = {}, util.row()
87+
vim.list_extend(expected, {
88+
util.heading(row:get(), 1), -- Heading
89+
util.inline_code(row:increment(2), 0, 8), -- Inline code
90+
{ backslash(row:increment(2), 0), backslash(row:get(), 7) }, -- Backslash escapes
91+
})
8992

9093
local actual = util.get_actual_marks()
9194
util.marks_are_equal(expected, actual)

tests/heading_code_spec.lua

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@ describe('heading_code.md', function()
66
it('default', function()
77
util.setup('demo/heading_code.md')
88

9-
local expected = {}
9+
local expected, row = {}, util.row()
1010

1111
vim.list_extend(expected, {
12-
util.heading(0, 1),
13-
util.heading(2, 3),
14-
util.heading(4, 4),
15-
util.heading(6, 5),
16-
util.heading(8, 6),
12+
util.heading(row:get(), 1),
13+
util.heading(row:increment(2), 3),
14+
util.heading(row:increment(2), 4),
15+
util.heading(row:increment(2), 5),
16+
util.heading(row:increment(2), 6),
1717
})
1818

19-
table.insert(expected, util.link(10, 0, 21, 'image'))
19+
table.insert(expected, util.link(row:increment(2), 0, 21, 'image'))
2020

2121
vim.list_extend(expected, {
22-
util.code_row(12, 0),
23-
util.code_language(12, 3, 9, 'python'),
22+
util.code_row(row:increment(2), 0),
23+
util.code_language(row:get(), 3, 9, 'python'),
2424
})
25-
for i = 13, 21 do
26-
table.insert(expected, util.code_row(i, 0))
25+
for _ = 13, 21 do
26+
table.insert(expected, util.code_row(row:increment(), 0))
2727
end
28-
table.insert(expected, util.code_below(22, 0))
28+
table.insert(expected, util.code_below(row:increment(), 0))
2929

3030
local actual = util.get_actual_marks()
3131
util.marks_are_equal(expected, actual)

tests/latex_spec.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ describe('latex.md', function()
4545
})
4646
util.setup('demo/latex.md')
4747

48-
local expected = {}
48+
local expected, row = {}, util.row()
4949

50-
vim.list_extend(expected, util.heading(0, 1))
50+
vim.list_extend(expected, util.heading(row:get(), 1))
5151

5252
vim.list_extend(expected, {
53-
latex(2, 2, 21, { '√(3x-1)+(1+x)^2' }), -- Inline
54-
latex(4, 7, 2, { ' f(x,y) = x + √(y)', ' f(x,y) = √(y) + x^2/4y' }), -- Block
53+
latex(row:increment(2), 2, 21, { '√(3x-1)+(1+x)^2' }), -- Inline
54+
latex(row:increment(2), 7, 2, { ' f(x,y) = x + √(y)', ' f(x,y) = √(y) + x^2/4y' }), -- Block
5555
})
5656

5757
local actual = util.get_actual_marks()

0 commit comments

Comments
 (0)