-
Notifications
You must be signed in to change notification settings - Fork 35
/
nested_bullets_spec.rb
625 lines (543 loc) · 16.1 KB
/
nested_bullets_spec.rb
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Bullets.vim' do
describe 'nested bullets' do
it 'demotes an existing bullet' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
I. this is the first bullet
II. second bullet
III. third bullet
IV. fourth bullet
V. fifth bullet
VI. sixth bullet
VII. seventh bullet
VIII. eighth bullet
IX. ninth bullet
TEXT
vim.edit filename
vim.normal '2ji'
vim.feedkeys '\<C-t>'
vim.normal 'j'
vim.feedkeys '>>>>>>'
vim.normal 'j'
vim.feedkeys '>>>>>>>>'
vim.normal 'j'
vim.feedkeys '>>>>>>>>>>'
vim.normal 'j'
vim.feedkeys '>>>>>>>>'
vim.feedkeys '>>>>'
vim.normal 'j'
vim.feedkeys '>>>>>>>>'
vim.feedkeys '>>>>>>'
vim.normal 'j'
vim.feedkeys '>>>>>>>>'
vim.feedkeys '>>>>>>>>'
vim.normal 'j'
vim.feedkeys '>>>>>>>>'
vim.feedkeys '>>>>>>>>>>'
vim.write
file_contents = IO.read(filename)
expect(file_contents).to eq normalize_string_indent(<<-TEXT)
# Hello there
I. this is the first bullet
\tA. second bullet
\t\t\t1. third bullet
\t\t\t\ta. fourth bullet
\t\t\t\t\ti. fifth bullet
\t\t\t\t\t\t- sixth bullet
\t\t\t\t\t\t\t* seventh bullet
\t\t\t\t\t\t\t\t+ eighth bullet
\t\t\t\t\t\t\t\t\t+ ninth bullet
TEXT
end
it 'promotes an existing bullet' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
I. this is the first bullet
\tA. second bullet
\t\t\t1. third bullet
\t\t\t\ta. fourth bullet
\t\t\t\t\ti. fifth bullet
\t\t\t\t\t\t- sixth bullet
\t\t\t\t\t\t\t* seventh bullet
\t\t\t\t\t\t\t\t+ eighth bullet
TEXT
vim.edit filename
vim.normal '2j'
vim.feedkeys '<<'
vim.normal 'ji'
vim.feedkeys '\<C-d>'
vim.feedkeys '\<C-d>'
vim.normal 'j'
vim.feedkeys '<<<<<<'
vim.normal 'j'
vim.feedkeys '<<<<<<'
vim.feedkeys '<<<<'
vim.normal 'j'
vim.feedkeys '<<<<<<'
vim.feedkeys '<<<<<<'
vim.normal 'j'
vim.feedkeys '<<<<<<'
vim.feedkeys '<<<<<<<<'
vim.normal 'j'
vim.feedkeys '<<<<<<'
vim.feedkeys '<<<<<<'
vim.feedkeys '<<<<'
vim.write
file_contents = IO.read(filename)
expect(file_contents).to eq normalize_string_indent(<<-TEXT)
# Hello there
I. this is the first bullet
II. second bullet
\tA. third bullet
\tB. fourth bullet
III. fifth bullet
IV. sixth bullet
V. seventh bullet
VI. eighth bullet
TEXT
end
it 'demotes an empty bullet' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
I. this is the first bullet
TEXT
vim.edit filename
vim.normal 'GA'
vim.feedkeys '\<cr>'
vim.feedkeys '\<C-t>'
vim.type 'second bullet'
vim.write
file_contents = IO.read(filename)
expect(file_contents).to eq normalize_string_indent(<<-TEXT)
# Hello there
I. this is the first bullet
\tA. second bullet
TEXT
end
it 'promotes an empty bullet' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
I. this is the first bullet
\tA. second bullet
TEXT
vim.edit filename
vim.normal 'GA'
vim.feedkeys '\<cr>'
vim.feedkeys '\<C-d>'
vim.type 'third bullet'
vim.write
file_contents = IO.read(filename)
expect(file_contents).to eq normalize_string_indent(<<-TEXT)
# Hello there
I. this is the first bullet
\tA. second bullet
II. third bullet
TEXT
end
it 'restarts numbering with multiple outlines' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
I. this is the first bullet
\tA. second bullet
TEXT
vim.edit filename
vim.normal 'GA'
vim.feedkeys '\<cr>'
vim.feedkeys '\<cr>'
vim.feedkeys '\<cr>'
vim.type 'A. first bullet'
vim.feedkeys '\<cr>'
vim.feedkeys '\<C-t>'
vim.type 'second bullet'
vim.write
file_contents = IO.read(filename)
expect(file_contents).to eq normalize_string_indent(<<-TEXT)
# Hello there
I. this is the first bullet
\tA. second bullet
A. first bullet
\t1. second bullet
TEXT
end
it 'works with custom outline level definitions' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
TEXT
vim.edit filename
vim.command "let g:bullets_outline_levels=['num','ABC','std*']"
vim.normal 'GA'
vim.feedkeys '\<cr>'
vim.type '1. first bullet'
vim.feedkeys '\<cr>'
vim.type 'second bullet'
vim.feedkeys '\<cr>'
vim.feedkeys '\<C-t>'
vim.type 'third bullet'
vim.feedkeys '\<cr>'
vim.type 'fourth bullet'
vim.feedkeys '\<cr>'
vim.feedkeys '\<C-t>'
vim.type 'fifth bullet'
vim.feedkeys '\<cr>'
vim.type 'sixth bullet'
vim.feedkeys '\<cr>'
vim.feedkeys '\<C-t>'
vim.type 'seventh bullet'
vim.feedkeys '\<cr>'
vim.type 'eighth bullet'
vim.feedkeys '\<cr>'
vim.feedkeys '\<C-d>'
vim.feedkeys '\<C-d>'
vim.type 'ninth bullet'
vim.feedkeys '\<cr>'
vim.feedkeys '\<C-d>'
vim.type 'tenth bullet'
vim.feedkeys '\<cr>'
vim.type 'eleventh bullet'
vim.write
file_contents = IO.read(filename)
expect(file_contents).to eq normalize_string_indent(<<-TEXT)
# Hello there
1. first bullet
2. second bullet
\tA. third bullet
\tB. fourth bullet
\t\t* fifth bullet
\t\t* sixth bullet
\t\t\t* seventh bullet
\t\t\t* eighth bullet
\tC. ninth bullet
3. tenth bullet
4. eleventh bullet
TEXT
end
it 'promotes and demotes from different starting levels' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
1. this is the first bullet
\ta. second bullet
TEXT
vim.edit filename
vim.normal 'GA'
vim.feedkeys '\<C-d>'
vim.feedkeys '\<cr>'
vim.feedkeys '\<C-t>'
vim.type 'third bullet'
vim.feedkeys '\<cr>'
vim.feedkeys '\<cr>'
vim.type '+ fourth bullet'
vim.feedkeys '\<cr>'
vim.feedkeys '\<C-t>'
vim.type 'fifth bullet'
vim.feedkeys '\<cr>'
vim.feedkeys '\<cr>'
vim.type '* sixth bullet'
vim.feedkeys '\<cr>'
vim.type 'seventh bullet'
vim.feedkeys '\<C-t>'
vim.write
file_contents = IO.read(filename)
expect(file_contents).to eq normalize_string_indent(<<-TEXT)
# Hello there
1. this is the first bullet
2. second bullet
\ta. third bullet
+ fourth bullet
\t+ fifth bullet
* sixth bullet
\t+ seventh bullet
TEXT
end
it 'does not nest beyond defined levels' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
I. this is the first bullet
\tA. second bullet
\t\t1. third bullet
\t\t\ta. fourth bullet
\t\t\t\ti. fifth bullet
\t\t\t\tii. sixth bullet
\t\t\t\t\t- seventh bullet
\t\t\t\t\t\t* eighth bullet
\t\t\t\t\t\t\t+ ninth bullet
TEXT
vim.edit filename
vim.normal 'GA'
vim.feedkeys '\<cr>'
vim.feedkeys '\<C-t>'
vim.type 'tenth bullet'
vim.feedkeys '\<cr>'
vim.type 'eleventh bullet'
vim.write
file_contents = IO.read(filename)
expect(file_contents).to eq normalize_string_indent(<<-TEXT)
# Hello there
I. this is the first bullet
\tA. second bullet
\t\t1. third bullet
\t\t\ta. fourth bullet
\t\t\t\ti. fifth bullet
\t\t\t\tii. sixth bullet
\t\t\t\t\t- seventh bullet
\t\t\t\t\t\t* eighth bullet
\t\t\t\t\t\t\t+ ninth bullet
\t\t\t\t\t\t\t\t+ tenth bullet
\t\t\t\t\t\t\t\t+ eleventh bullet
TEXT
end
it 'removes bullet when promoting top level bullet' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
A. this is the first bullet
I. second bullet
\tA. third bullet
TEXT
vim.edit filename
vim.normal 'j'
vim.feedkeys '<<'
vim.normal '3ji'
vim.feedkeys '\<C-d>'
vim.feedkeys '\<C-d>'
vim.write
file_contents = IO.read(filename)
expect(file_contents).to eq normalize_string_indent(<<-TEXT)
# Hello there
this is the first bullet
I. second bullet
third bullet
TEXT
end
it 'handle standard bullets when they are not in outline list' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
1. this is the first bullet
\t- standard bullet
TEXT
vim.edit filename
vim.command "let g:bullets_outline_levels=['num','ABC']"
vim.normal 'GA'
vim.feedkeys '\<cr>'
vim.type 'second standard bullet'
vim.feedkeys '\<cr>'
vim.feedkeys '\<C-d>'
vim.type 'second bullet'
vim.feedkeys '\<cr>'
vim.type 'third bullet'
vim.write
file_contents = IO.read(filename)
expect(file_contents).to eq normalize_string_indent(<<-TEXT)
# Hello there
1. this is the first bullet
\t- standard bullet
\t- second standard bullet
2. second bullet
3. third bullet
TEXT
end
it 'adds new nested bullets with correct alpha/roman numerals' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
I. this is the first bullet
\tA. second bullet
TEXT
vim.edit filename
vim.normal 'GA'
vim.feedkeys '\<cr>'
vim.type 'third bullet'
vim.feedkeys '\<C-t>'
vim.feedkeys '\<cr>'
vim.type 'fourth bullet'
vim.feedkeys '\<C-t>'
vim.feedkeys '\<cr>'
vim.type 'fifth bullet'
vim.feedkeys '\<C-t>'
vim.feedkeys '\<cr>'
vim.type 'sixth bullet'
vim.feedkeys '\<C-t>'
vim.feedkeys '\<cr>'
vim.type 'seventh bullet'
vim.feedkeys '\<cr>'
vim.type 'eighth bullet'
vim.feedkeys '\<C-d>'
vim.feedkeys '\<cr>'
vim.type 'ninth bullet'
vim.feedkeys '\<C-d>'
vim.feedkeys '\<cr>'
vim.type 'tenth bullet'
vim.feedkeys '\<C-d>'
vim.feedkeys '\<cr>'
vim.type 'eleventh bullet'
vim.feedkeys '\<C-d>'
vim.feedkeys '\<cr>'
vim.type 'twelfth bullet'
vim.feedkeys '\<C-d>'
vim.write
file_contents = IO.read(filename)
expect(file_contents).to eq normalize_string_indent(<<-TEXT)
# Hello there
I. this is the first bullet
\tA. second bullet
\t\t1. third bullet
\t\t\ta. fourth bullet
\t\t\t\ti. fifth bullet
\t\t\t\t\t- sixth bullet
\t\t\t\t\t- seventh bullet
\t\t\t\tii. eighth bullet
\t\t\tb. ninth bullet
\t\t2. tenth bullet
\tB. eleventh bullet
II. twelfth bullet
TEXT
end
it 'changes levels in visual mode' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
1. first bullet
\ta. second bullet
\tb. third bullet
\t\t* fourth bullet
\t\t* fifth bullet
\t\t\tsixth bullet
\t\t* seventh bullet
2. eighth bullet
\t\ta. ninth bullet
\ta. tenth bullet
\tb. eleventh bullet
3. twelfth bullet
\t thirteenth bullet
\ta. fourteenth bullet
\t\t* fifteenth bullet
4. sixteenth bullet
TEXT
vim.edit filename
vim.command "let g:bullets_outline_levels=['num','abc','std*']"
vim.normal '3jv'
vim.feedkeys '<'
vim.normal 'jv2j'
vim.feedkeys '<'
vim.normal 'jvj'
vim.feedkeys '>'
vim.normal 'jvj'
vim.feedkeys '<'
vim.feedkeys '<'
vim.normal 'jv'
vim.feedkeys '>'
vim.normal '3jv2j'
vim.feedkeys '>'
vim.feedkeys '>'
vim.write
file_contents = IO.read(filename)
expect(file_contents).to eq normalize_string_indent(<<-TEXT)
# Hello there
1. first bullet
\ta. second bullet
2. third bullet
\ta. fourth bullet
\tb. fifth bullet
\t\tsixth bullet
\t\t\t* seventh bullet
\tc. eighth bullet
3. ninth bullet
tenth bullet
\t\ta. eleventh bullet
4. twelfth bullet
\t thirteenth bullet
\t\t\ta. fourteenth bullet
\t\t\t\t* fifteenth bullet
\t\ta. sixteenth bullet
TEXT
end
it 'add and change bullets with multiple line spacing and wrapped lines' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
I. this is the first bullet
TEXT
vim.edit filename
vim.command 'let g:bullets_line_spacing=2'
vim.normal 'GA'
vim.feedkeys '\<cr>'
vim.type 'second bullet'
vim.feedkeys '\<cr>'
vim.feedkeys '\<C-t>'
vim.type 'third bullet'
vim.feedkeys '\<cr>'
vim.normal 'dd'
vim.insert ' wrapped bullet'
vim.feedkeys '\<cr>'
vim.type 'fourth bullet'
vim.write
file_contents = IO.read(filename)
expect(file_contents).to eq normalize_string_indent(<<-TEXT)
# Hello there
I. this is the first bullet
II. second bullet
\tA. third bullet
\twrapped bullet
\tB. fourth bullet
TEXT
end
it 'indents after a line ending in a colon' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
a. this is the first bullet
TEXT
vim.command 'let g:bullets_auto_indent_after_colon = 1'
vim.edit filename
vim.type 'GA'
vim.feedkeys '\<cr>'
vim.type 'this is the second bullet:'
vim.feedkeys '\<cr>'
vim.type 'this bullet is indented'
vim.feedkeys '\<cr>'
vim.type 'this bullet is also indented'
vim.write
file_contents = IO.read(filename)
expect(file_contents.strip).to eq normalize_string_indent(<<-TEXT)
# Hello there
a. this is the first bullet
b. this is the second bullet:
\ti. this bullet is indented
\tii. this bullet is also indented
TEXT
write_file(filename, <<-TEXT)
# Hello there
a. this is the first bullet
TEXT
vim.command 'let g:bullets_auto_indent_after_colon = 1'
vim.edit filename
vim.feedkeys '\<ESC>'
vim.type 'GA'
vim.feedkeys '\<cr>'
vim.type 'this is the second bullet that ends with fullwidth colon:'
vim.feedkeys '\<cr>'
vim.type 'this bullet is indented'
vim.feedkeys '\<cr>'
vim.type 'this bullet is also indented'
vim.write
file_contents = IO.read(filename)
expect(file_contents.strip).to eq normalize_string_indent(<<-TEXT)
# Hello there
a. this is the first bullet
b. this is the second bullet that ends with fullwidth colon:
\ti. this bullet is indented
\tii. this bullet is also indented
TEXT
end
end
end