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
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
|
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
local clear = n.clear
local command = n.command
local exec = n.exec
local feed = n.feed
local api = n.api
local expect_pos = function(row, col)
return t.eq({ row, col }, n.eval('[screenrow(), screencol()]'))
end
describe('Conceal', function()
before_each(function()
clear()
command('set nohlsearch')
end)
-- oldtest: Test_conceal_two_windows()
it('works', function()
local screen = Screen.new(75, 12)
exec([[
let lines = ["one one one one one", "two |hidden| here", "three |hidden| three"]
call setline(1, lines)
syntax match test /|hidden|/ conceal
set conceallevel=2
set concealcursor=
exe "normal /here\r"
new
call setline(1, lines)
call setline(4, "Second window")
syntax match test /|hidden|/ conceal
set conceallevel=2
set concealcursor=nc
exe "normal /here\r"
]])
-- Check that cursor line is concealed
screen:expect([[
one one one one one |
two ^here |
three three |
Second window |
{1:~ }|
{3:[No Name] [+] }|
one one one one one |
two here |
three three |
{1:~ }|
{2:[No Name] [+] }|
/here |
]])
-- Check that with concealed text vertical cursor movement is correct.
feed('k')
screen:expect([[
one one one o^ne one |
two here |
three three |
Second window |
{1:~ }|
{3:[No Name] [+] }|
one one one one one |
two here |
three three |
{1:~ }|
{2:[No Name] [+] }|
/here |
]])
-- Check that with cursor line is not concealed
feed('j')
command('set concealcursor=')
screen:expect([[
one one one one one |
two |hidden| ^here |
three three |
Second window |
{1:~ }|
{3:[No Name] [+] }|
one one one one one |
two here |
three three |
{1:~ }|
{2:[No Name] [+] }|
/here |
]])
-- Check that with cursor line is not concealed when moving cursor down
feed('j')
screen:expect([[
one one one one one |
two here |
three |hidden^| three |
Second window |
{1:~ }|
{3:[No Name] [+] }|
one one one one one |
two here |
three three |
{1:~ }|
{2:[No Name] [+] }|
/here |
]])
-- Check that with cursor line is not concealed when switching windows
feed('<C-W><C-W>')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{1:~ }|
{2:[No Name] [+] }|
one one one one one |
two |hidden| ^here |
three three |
{1:~ }|
{3:[No Name] [+] }|
/here |
]])
-- Check that with cursor line is only concealed in Normal mode
command('set concealcursor=n')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{1:~ }|
{2:[No Name] [+] }|
one one one one one |
two ^here |
three three |
{1:~ }|
{3:[No Name] [+] }|
/here |
]])
feed('a')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{1:~ }|
{2:[No Name] [+] }|
one one one one one |
two |hidden| h^ere |
three three |
{1:~ }|
{3:[No Name] [+] }|
{5:-- INSERT --} |
]])
feed('<Esc>/e')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{1:~ }|
{2:[No Name] [+] }|
one one one one one |
two |hidden| h{2:e}re |
three three |
{1:~ }|
{3:[No Name] [+] }|
/e^ |
]])
feed('<Esc>v')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{1:~ }|
{2:[No Name] [+] }|
one one one one one |
two |hidden| ^here |
three three |
{1:~ }|
{3:[No Name] [+] }|
{5:-- VISUAL --} |
]])
feed('<Esc>')
-- Check that with cursor line is only concealed in Insert mode
command('set concealcursor=i')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{1:~ }|
{2:[No Name] [+] }|
one one one one one |
two |hidden| ^here |
three three |
{1:~ }|
{3:[No Name] [+] }|
|
]])
feed('a')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{1:~ }|
{2:[No Name] [+] }|
one one one one one |
two h^ere |
three three |
{1:~ }|
{3:[No Name] [+] }|
{5:-- INSERT --} |
]])
feed('<Esc>/e')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{1:~ }|
{2:[No Name] [+] }|
one one one one one |
two |hidden| h{2:e}re |
three three |
{1:~ }|
{3:[No Name] [+] }|
/e^ |
]])
feed('<Esc>v')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{1:~ }|
{2:[No Name] [+] }|
one one one one one |
two |hidden| ^here |
three three |
{1:~ }|
{3:[No Name] [+] }|
{5:-- VISUAL --} |
]])
feed('<Esc>')
-- Check that with cursor line is only concealed in Visual mode
command('set concealcursor=v')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{1:~ }|
{2:[No Name] [+] }|
one one one one one |
two |hidden| ^here |
three three |
{1:~ }|
{3:[No Name] [+] }|
|
]])
feed('a')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{1:~ }|
{2:[No Name] [+] }|
one one one one one |
two |hidden| h^ere |
three three |
{1:~ }|
{3:[No Name] [+] }|
{5:-- INSERT --} |
]])
feed('<Esc>/e')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{1:~ }|
{2:[No Name] [+] }|
one one one one one |
two |hidden| h{2:e}re |
three three |
{1:~ }|
{3:[No Name] [+] }|
/e^ |
]])
feed('<Esc>v')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{1:~ }|
{2:[No Name] [+] }|
one one one one one |
two ^here |
three three |
{1:~ }|
{3:[No Name] [+] }|
{5:-- VISUAL --} |
]])
feed('<Esc>')
-- Check moving the cursor while in insert mode.
command('set concealcursor=')
feed('a')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{1:~ }|
{2:[No Name] [+] }|
one one one one one |
two |hidden| h^ere |
three three |
{1:~ }|
{3:[No Name] [+] }|
{5:-- INSERT --} |
]])
feed('<Down>')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{1:~ }|
{2:[No Name] [+] }|
one one one one one |
two here |
three |hidden|^ three |
{1:~ }|
{3:[No Name] [+] }|
{5:-- INSERT --} |
]])
feed('<Esc>')
-- Check the "o" command
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{1:~ }|
{2:[No Name] [+] }|
one one one one one |
two here |
three |hidden^| three |
{1:~ }|
{3:[No Name] [+] }|
|
]])
feed('o')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{1:~ }|
{2:[No Name] [+] }|
one one one one one |
two here |
three three |
^ |
{3:[No Name] [+] }|
{5:-- INSERT --} |
]])
feed('<Esc>')
end)
-- oldtest: Test_conceal_with_cursorcolumn()
it('CursorColumn and ColorColumn on wrapped line', function()
local screen = Screen.new(40, 10)
screen:add_extra_attr_ids {
[100] = { background = Screen.colors.LightRed },
}
-- Check that cursorcolumn and colorcolumn don't get broken in presence of
-- wrapped lines containing concealed text
-- luacheck: push ignore 613 (trailing whitespace in a string)
exec([[
let lines = ["one one one |hidden| one one one one one one one one",
\ "two two two two |hidden| here two two",
\ "three |hidden| three three three three three three three three"]
call setline(1, lines)
set wrap linebreak
set showbreak=\ >>>\
syntax match test /|hidden|/ conceal
set conceallevel=2
set concealcursor=
exe "normal /here\r"
set cursorcolumn
set colorcolumn=50
]])
-- luacheck: pop
screen:expect([[
one one one one one one {21:o}ne |
{1: >>> }one {100:o}ne one one |
two two two two |hidden| ^here two two |
three three three three {21:t}hree |
{1: >>> }thre{100:e} three three three |
{1:~ }|*4
/here |
]])
-- move cursor to the end of line (the cursor jumps to the next screen line)
feed('$')
screen:expect([[
one one one one one one one |
{1: >>> }one {100:o}ne one one |
two two two two |hidden| here two tw^o |
three three three three three |
{1: >>> }thre{100:e} three three three |
{1:~ }|*4
/here |
]])
end)
-- oldtest: Test_conceal_wrapped_cursorline_wincolor()
it('CursorLine highlight on wrapped lines', function()
local screen = Screen.new(40, 4)
screen:add_extra_attr_ids {
[100] = { background = Screen.colors.WebGreen },
}
exec([[
call setline(1, 'one one one |hidden| one one one one one one one one')
syntax match test /|hidden|/ conceal
set conceallevel=2 concealcursor=n cursorline
normal! g$
hi! CursorLine guibg=Green
]])
screen:expect([[
{100:one one one one one one one on^e }|
{100: one one one }|
{1:~ }|
|
]])
command('hi! CursorLine guibg=NONE guifg=Red')
screen:expect([[
{19:one one one one one one one on^e }|
{19: one one one }|
{1:~ }|
|
]])
end)
-- oldtest: Test_conceal_wrapped_cursorline_wincolor_rightleft()
it('CursorLine highlight on wrapped lines with rightleft', function()
local screen = Screen.new(40, 4)
screen:add_extra_attr_ids {
[100] = { background = Screen.colors.WebGreen },
}
exec([[
call setline(1, 'one one one |hidden| one one one one one one one one')
syntax match test /|hidden|/ conceal
set conceallevel=2 concealcursor=n cursorline rightleft
normal! g$
hi! CursorLine guibg=Green
]])
screen:expect([[
{100: ^eno eno eno eno eno eno eno eno}|
{100: eno eno eno }|
{1: ~}|
|
]])
command('hi! CursorLine guibg=NONE guifg=Red')
screen:expect([[
{19: ^eno eno eno eno eno eno eno eno}|
{19: eno eno eno }|
{1: ~}|
|
]])
end)
-- oldtest: Test_conceal_resize_term()
it('resize editor', function()
local screen = Screen.new(75, 6)
exec([[
call setline(1, '`one` `two` `three` `four` `five`, the backticks should be concealed')
setl cocu=n cole=3
syn region CommentCodeSpan matchgroup=Comment start=/`/ end=/`/ concealends
normal fb
]])
screen:expect([[
one two three four five, the ^backticks should be concealed |
{1:~ }|*4
|
]])
screen:try_resize(75, 7)
screen:expect([[
one two three four five, the ^backticks should be concealed |
{1:~ }|*5
|
]])
end)
-- oldtest: Test_conceal_linebreak()
it('with linebreak', function()
local screen = Screen.new(75, 8)
exec([[
let &wrap = v:true
let &conceallevel = 2
let &concealcursor = 'nc'
let &linebreak = v:true
let &showbreak = '+ '
let line = 'a`a`a`a`'
\ .. 'a'->repeat(&columns - 15)
\ .. ' b`b`'
\ .. 'b'->repeat(&columns - 10)
\ .. ' cccccc'
eval ['x'->repeat(&columns), '', line]->setline(1)
syntax region CodeSpan matchgroup=Delimiter start=/\z(`\+\)/ end=/\z1/ concealends
]])
screen:expect([[
^xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
{1:+ }bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb |
{1:+ }cccccc |
{1:~ }|*2
|
]])
end)
-- Tests for correct display (cursor column position) with +conceal and tabulators.
-- oldtest: Test_conceal_cursor_pos()
it('cursor and column position with conceal and tabulators', function()
exec([[
let l = ['start:', '.concealed. text', "|concealed|\ttext"]
let l += ['', "\t.concealed.\ttext", "\t|concealed|\ttext", '']
let l += [".a.\t.b.\t.c.\t.d.", "|a|\t|b|\t|c|\t|d|"]
call append(0, l)
call cursor(1, 1)
" Conceal settings.
set conceallevel=2
set concealcursor=nc
syntax match test /|/ conceal
]])
feed('ztj')
expect_pos(2, 1)
-- We should end up in the same column when running these commands on the
-- two lines.
feed('ft')
expect_pos(2, 17)
feed('$')
expect_pos(2, 20)
feed('0j')
expect_pos(3, 1)
feed('ft')
expect_pos(3, 17)
feed('$')
expect_pos(3, 20)
feed('j0j')
expect_pos(5, 8)
-- Same for next test block.
feed('ft')
expect_pos(5, 25)
feed('$')
expect_pos(5, 28)
feed('0j')
expect_pos(6, 8)
feed('ft')
expect_pos(6, 25)
feed('$')
expect_pos(6, 28)
feed('0j0j')
expect_pos(8, 1)
-- And check W with multiple tabs and conceals in a line.
feed('W')
expect_pos(8, 9)
feed('W')
expect_pos(8, 17)
feed('W')
expect_pos(8, 25)
feed('$')
expect_pos(8, 27)
feed('0j')
expect_pos(9, 1)
feed('W')
expect_pos(9, 9)
feed('W')
expect_pos(9, 17)
feed('W')
expect_pos(9, 25)
feed('$')
expect_pos(9, 26)
command('set lbr')
feed('$')
expect_pos(9, 26)
command('set list listchars=tab:>-')
feed('0')
expect_pos(9, 1)
feed('W')
expect_pos(9, 9)
feed('W')
expect_pos(9, 17)
feed('W')
expect_pos(9, 25)
feed('$')
expect_pos(9, 26)
end)
local function test_conceal_virtualedit_after_eol(wrap)
local screen = Screen.new(60, 3)
api.nvim_set_option_value('wrap', wrap, {})
exec([[
call setline(1, 'abcdefgh|hidden|ijklmnpop')
syntax match test /|hidden|/ conceal
set conceallevel=2 concealcursor=n virtualedit=all
normal! $
]])
screen:expect([[
abcdefghijklmnpo^p |
{1:~ }|
|
]])
feed('l')
screen:expect([[
abcdefghijklmnpop^ |
{1:~ }|
|
]])
feed('l')
screen:expect([[
abcdefghijklmnpop ^ |
{1:~ }|
|
]])
feed('l')
screen:expect([[
abcdefghijklmnpop ^ |
{1:~ }|
|
]])
feed('rr')
screen:expect([[
abcdefghijklmnpop ^r |
{1:~ }|
|
]])
end
-- oldtest: Test_conceal_virtualedit_after_eol()
describe('cursor drawn at correct column with virtualedit', function()
it('with wrapping', function()
test_conceal_virtualedit_after_eol(true)
end)
it('without wrapping', function()
test_conceal_virtualedit_after_eol(false)
end)
end)
local function test_conceal_virtualedit_after_eol_rightleft(wrap)
local screen = Screen.new(60, 3)
api.nvim_set_option_value('wrap', wrap, {})
exec([[
call setline(1, 'abcdefgh|hidden|ijklmnpop')
syntax match test /|hidden|/ conceal
set conceallevel=2 concealcursor=n virtualedit=all rightleft
normal! $
]])
screen:expect([[
^popnmlkjihgfedcba|
{1: ~}|
|
]])
feed('h')
screen:expect([[
^ popnmlkjihgfedcba|
{1: ~}|
|
]])
feed('h')
screen:expect([[
^ popnmlkjihgfedcba|
{1: ~}|
|
]])
feed('h')
screen:expect([[
^ popnmlkjihgfedcba|
{1: ~}|
|
]])
feed('rr')
screen:expect([[
^r popnmlkjihgfedcba|
{1: ~}|
|
]])
end
-- oldtest: Test_conceal_virtualedit_after_eol_rightleft()
describe('cursor drawn correctly with virtualedit and rightleft', function()
it('with wrapping', function()
test_conceal_virtualedit_after_eol_rightleft(true)
end)
it('without wrapping', function()
test_conceal_virtualedit_after_eol_rightleft(false)
end)
end)
local function test_conceal_double_width(wrap)
local screen = Screen.new(60, 4)
screen:add_extra_attr_ids {
[100] = { background = Screen.colors.LightRed },
}
api.nvim_set_option_value('wrap', wrap, {})
exec([[
call setline(1, ['aaaaa口=口bbbbb口=口ccccc', 'foobar'])
syntax match test /口=口/ conceal cchar=β
set conceallevel=2 concealcursor=n colorcolumn=30
normal! $
]])
screen:expect([[
aaaaa{14:β}bbbbb{14:β}cccc^c {100: } |
foobar {100: } |
{1:~ }|
|
]])
feed('gM')
screen:expect([[
aaaaa{14:β}bb^bbb{14:β}ccccc {100: } |
foobar {100: } |
{1:~ }|
|
]])
command('set conceallevel=3')
screen:expect([[
aaaaabb^bbbccccc {100: } |
foobar {100: } |
{1:~ }|
|
]])
feed('$')
screen:expect([[
aaaaabbbbbcccc^c {100: } |
foobar {100: } |
{1:~ }|
|
]])
end
-- oldtest: Test_conceal_double_width()
describe('cursor drawn correctly when double-width chars are concealed', function()
it('with wrapping', function()
test_conceal_double_width(true)
end)
it('without wrapping', function()
test_conceal_double_width(false)
end)
end)
-- oldtest: Test_conceal_double_width_wrap()
it('line wraps correctly when double-width chars are concealed', function()
local screen = Screen.new(20, 4)
screen:add_extra_attr_ids {
[100] = { background = Screen.colors.LightRed },
}
exec([[
call setline(1, 'aaaaaaaaaa口=口bbbbbbbbbb口=口cccccccccc')
syntax match test /口=口/ conceal cchar=β
set conceallevel=2 concealcursor=n
normal! $
]])
screen:expect([[
aaaaaaaaaa{14:β}bbbbb |
bbbbb{14:β}ccccccccc^c |
{1:~ }|
|
]])
feed('gM')
screen:expect([[
aaaaaaaaaa{14:β}bbbbb |
^bbbbb{14:β}cccccccccc |
{1:~ }|
|
]])
command('set conceallevel=3')
screen:expect([[
aaaaaaaaaabbbbb |
^bbbbbcccccccccc |
{1:~ }|
|
]])
feed('$')
screen:expect([[
aaaaaaaaaabbbbb |
bbbbbccccccccc^c |
{1:~ }|
|
]])
end)
end)
|