Skip to content

Commit abc6983

Browse files
committed
test: migrate batch 2 specs to Lua/Plenary (alphabetic, renumber, checkboxes)
Additional learnings added to minimal_init.lua: - set noexpandtab globally to prevent user config leaking \t → spaces - new_buffer() positions cursor at last line, so tests navigating from line 1 must prefix 'gg' before their first motion - expandtab contamination affects <C-t> indent tests; fixed globally
1 parent f60b24e commit abc6983

4 files changed

Lines changed: 767 additions & 0 deletions

File tree

test/alphabetic_bullets_spec.lua

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
local helpers = require("test.helpers")
2+
3+
describe("Bullets.vim", function()
4+
describe("alphabetic bullets", function()
5+
before_each(function()
6+
helpers.reset_config()
7+
end)
8+
9+
it("adds a new upper case bullet", function()
10+
helpers.new_buffer({
11+
"# Hello there",
12+
"A. this is the first bullet",
13+
})
14+
helpers.feedkeys(
15+
"A<CR>second bullet<CR>third bullet<CR>fourth bullet<CR>fifth bullet"
16+
.. "<CR>sixth bullet<CR>seventh bullet<CR>eighth bullet<CR>ninth bullet<CR>tenth bullet<Esc>"
17+
)
18+
assert.are.same({
19+
"# Hello there",
20+
"A. this is the first bullet",
21+
"B. second bullet",
22+
"C. third bullet",
23+
"D. fourth bullet",
24+
"E. fifth bullet",
25+
"F. sixth bullet",
26+
"G. seventh bullet",
27+
"H. eighth bullet",
28+
"I. ninth bullet",
29+
"J. tenth bullet",
30+
}, helpers.get_lines())
31+
end)
32+
33+
it("adds a new lower case bullet", function()
34+
helpers.new_buffer({
35+
"# Hello there",
36+
"a. this is the first bullet",
37+
})
38+
helpers.feedkeys(
39+
"A<CR>second bullet<CR>third bullet<CR>fourth bullet<CR>fifth bullet"
40+
.. "<CR>sixth bullet<CR>seventh bullet<CR>eighth bullet<CR>ninth bullet<CR>tenth bullet<Esc>"
41+
)
42+
assert.are.same({
43+
"# Hello there",
44+
"a. this is the first bullet",
45+
"b. second bullet",
46+
"c. third bullet",
47+
"d. fourth bullet",
48+
"e. fifth bullet",
49+
"f. sixth bullet",
50+
"g. seventh bullet",
51+
"h. eighth bullet",
52+
"i. ninth bullet",
53+
"j. tenth bullet",
54+
}, helpers.get_lines())
55+
end)
56+
57+
it("adds a new bullet and loops at z", function()
58+
vim.g.bullets_renumber_on_change = 0
59+
helpers.new_buffer({
60+
"# Hello there",
61+
"y. this is the first bullet",
62+
})
63+
-- Type through "third bullet", then press CR twice:
64+
-- first CR inserts "ab. " (next bullet after "aa."),
65+
-- second CR on empty bullet line triggers delete-last-bullet-if-empty,
66+
-- leaving an empty line in normal mode.
67+
helpers.feedkeys("A<CR>second bullet<CR>third bullet<CR><CR>")
68+
-- Now in normal mode on empty line 5. Use 'A' to enter insert at end,
69+
-- type the override bullet, then continue with remaining bullets.
70+
helpers.feedkeys("AAY. fourth bullet<CR>fifth bullet<CR>sixth bullet<Esc>")
71+
assert.are.same({
72+
"# Hello there",
73+
"y. this is the first bullet",
74+
"z. second bullet",
75+
"aa. third bullet",
76+
"AY. fourth bullet",
77+
"AZ. fifth bullet",
78+
"BA. sixth bullet",
79+
}, helpers.get_lines())
80+
end)
81+
82+
it("does not add a new bullet when mixed case", function()
83+
-- "Ab." is mixed case so the plugin doesn't recognise it as a bullet.
84+
-- CR is therefore deferred via feedkeys('n'); the 'tx' flag in our outer
85+
-- feedkeys drains that deferred CR, leaving normal mode on a new empty line.
86+
-- Use the two-step non-bullet-line pattern.
87+
helpers.new_buffer({
88+
"# Hello there",
89+
"Ab. this is the first bullet",
90+
})
91+
helpers.feedkeys("A<CR>")
92+
helpers.feedkeys("inot a bullet<Esc>")
93+
assert.are.same({
94+
"# Hello there",
95+
"Ab. this is the first bullet",
96+
"not a bullet",
97+
}, helpers.get_lines())
98+
end)
99+
100+
describe("g:bullets_max_alpha_characters", function()
101+
it("stops adding items after configured max (default 2)", function()
102+
vim.g.bullets_renumber_on_change = 0
103+
helpers.new_buffer({
104+
"# Hello there",
105+
"zy. this is the first bullet",
106+
})
107+
-- "A<CR>" inserts "zz. " (within max), type "second bullet",
108+
-- then <CR> on the "zz. second bullet" line: next would be "aaa." (3
109+
-- chars) which exceeds the default max of 2, so no bullet is inserted;
110+
-- instead a plain CR is deferred. The 'tx' flag drains it, leaving
111+
-- normal mode on a new empty line.
112+
helpers.feedkeys("A<CR>second bullet<CR>")
113+
helpers.feedkeys("inot a bullet<Esc>")
114+
assert.are.same({
115+
"# Hello there",
116+
"zy. this is the first bullet",
117+
"zz. second bullet",
118+
"not a bullet",
119+
}, helpers.get_lines())
120+
end)
121+
122+
it("does not bullets if configured as 0", function()
123+
vim.g.bullets_max_alpha_characters = 0
124+
helpers.new_buffer({
125+
"# Hello there",
126+
"a. this is the first bullet",
127+
})
128+
-- With max=0, alpha bullets are disabled entirely so "a." is not
129+
-- recognized as a bullet → CR defers via feedkeys('n')
130+
helpers.feedkeys("A<CR>")
131+
helpers.feedkeys("inot a bullet<Esc>")
132+
assert.are.same({
133+
"# Hello there",
134+
"a. this is the first bullet",
135+
"not a bullet",
136+
}, helpers.get_lines())
137+
end)
138+
end)
139+
end)
140+
end)

0 commit comments

Comments
 (0)