forked from nvim-mini/mini.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_align.lua
More file actions
2003 lines (1605 loc) · 71.8 KB
/
test_align.lua
File metadata and controls
2003 lines (1605 loc) · 71.8 KB
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
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local helpers = dofile('tests/helpers.lua')
local child = helpers.new_child_neovim()
local expect, eq = helpers.expect, helpers.expect.equality
local new_set = MiniTest.new_set
-- Helpers with child processes
--stylua: ignore start
local load_module = function(config) child.mini_load('align', config) end
local unload_module = function() child.mini_unload('align') end
local set_cursor = function(...) return child.set_cursor(...) end
local get_cursor = function(...) return child.get_cursor(...) end
local set_lines = function(...) return child.set_lines(...) end
local get_lines = function(...) return child.get_lines(...) end
local type_keys = function(...) return child.type_keys(...) end
local sleep = function(ms) helpers.sleep(ms, child) end
--stylua: ignore end
local set_config_steps = function(tbl)
for key, value in pairs(tbl) do
child.lua('MiniAlign.config.steps.' .. key .. ' = ' .. value)
end
end
local set_config_opts = function(tbl)
for key, value in pairs(tbl) do
child.lua('MiniAlign.config.options.' .. key .. ' = ' .. vim.inspect(value))
end
end
local validate_step = function(var_name, step_name)
eq(child.lua_get(('type(%s)'):format(var_name)), 'table')
local keys = child.lua_get(('vim.tbl_keys(%s)'):format(var_name))
table.sort(keys)
eq(keys, { 'action', 'name' })
eq(child.lua_get(('type(%s.name)'):format(var_name)), 'string')
if step_name ~= nil then eq(child.lua_get(('%s.name'):format(var_name)), step_name) end
eq(child.lua_get(('vim.is_callable(%s.action)'):format(var_name)), true)
end
local get_latest_message = function() return child.cmd_capture('1messages') end
local get_mode = function() return child.api.nvim_get_mode()['mode'] end
local eq_tostring = function(var_name1, var_name2)
local cmd = string.format('tostring(%s) == tostring(%s)', var_name1, var_name2)
eq(child.lua_get(cmd), true)
end
-- Time constants
local helper_message_delay, error_message_force_delay = 1000, 500
local small_time = helpers.get_time_const(10)
-- Output test set
local T = new_set({
hooks = {
pre_case = function()
child.setup()
load_module()
end,
post_once = child.stop,
},
n_retry = helpers.get_n_retry(1),
})
-- Unit tests =================================================================
T['setup()'] = new_set()
T['setup()']['creates side effects'] = function()
-- Global variable
eq(child.lua_get('type(_G.MiniAlign)'), 'table')
end
T['setup()']['creates `config` field'] = function()
eq(child.lua_get('type(_G.MiniAlign.config)'), 'table')
-- Check default values
local expect_config = function(field, value) eq(child.lua_get('MiniAlign.config.' .. field), value) end
local expect_config_type = function(field, type_val)
eq(child.lua_get('type(MiniAlign.config.' .. field .. ')'), type_val)
end
-- Check default values
expect_config('mappings.start', 'ga')
expect_config('mappings.start_with_preview', 'gA')
expect_config_type('modifiers.s', 'function')
expect_config_type('modifiers.j', 'function')
expect_config_type('modifiers.m', 'function')
expect_config_type('modifiers.f', 'function')
expect_config_type('modifiers.t', 'function')
expect_config_type('modifiers.p', 'function')
expect_config_type(
string.format('modifiers["%s"]', child.api.nvim_replace_termcodes('<BS>', true, true, true)),
'function'
)
expect_config_type('modifiers["="]', 'function')
expect_config_type('modifiers[","]', 'function')
expect_config_type('modifiers[" "]', 'function')
expect_config('options.split_pattern', '')
expect_config('options.justify_side', 'left')
expect_config('options.merge_delimiter', '')
expect_config('steps.pre_split', {})
expect_config('steps.split', vim.NIL)
expect_config('steps.pre_justify', {})
expect_config('steps.justify', vim.NIL)
expect_config('steps.pre_merge', {})
expect_config('steps.merge', vim.NIL)
expect_config('silent', false)
end
T['setup()']['respects `config` argument'] = function()
unload_module()
load_module({ options = { justify_side = 'center' } })
eq(child.lua_get('MiniAlign.config.options.justify_side'), 'center')
end
T['setup()']['validates `config` argument'] = function()
unload_module()
local expect_config_error = function(config, name, target_type)
expect.error(load_module, vim.pesc(name) .. '.*' .. vim.pesc(target_type), config)
end
expect_config_error('a', 'config', 'table')
expect_config_error({ mappings = 'a' }, 'mappings', 'table')
expect_config_error({ mappings = { start = 1 } }, 'mappings.start', 'string')
expect_config_error({ mappings = { start_with_preview = 1 } }, 'mappings.start_with_preview', 'string')
expect_config_error({ modifiers = 'a' }, 'modifiers', 'table')
expect_config_error({ modifiers = { x = 1 } }, 'modifiers["x"]', 'callable')
expect_config_error({ options = 'a' }, 'options', 'table')
expect_config_error({ steps = { pre_split = 1 } }, 'steps.pre_split', 'array of steps')
expect_config_error({ steps = { split = 1 } }, 'steps.split', 'step')
expect_config_error({ steps = { pre_justify = 1 } }, 'steps.pre_justify', 'array of steps')
expect_config_error({ steps = { justify = 1 } }, 'steps.justify', 'step')
expect_config_error({ steps = { pre_merge = 1 } }, 'steps.pre_merge', 'array of steps')
expect_config_error({ steps = { merge = 1 } }, 'steps.merge', 'step')
expect_config_error({ silent = 'a' }, 'silent', 'boolean')
end
T['setup()']['properly handles `config.mappings`'] = function()
local has_map = function(lhs, pattern) return child.cmd_capture('xmap ' .. lhs):find(pattern) ~= nil end
eq(has_map('ga', 'Align'), true)
unload_module()
child.api.nvim_del_keymap('x', 'ga')
-- Supplying empty string should mean "don't create keymap"
load_module({ mappings = { start = '' } })
eq(has_map('ga', 'Align'), false)
end
local validate_align_strings = function(input_strings, opts, ref_strings, steps)
local output = child.lua_get('MiniAlign.align_strings(...)', { input_strings, opts or {}, steps or {} })
eq(output, ref_strings)
end
T['align_strings()'] = new_set()
T['align_strings()']['works'] = function()
validate_align_strings({ 'a=b', 'aa=b' }, { split_pattern = '=' }, { 'a =b', 'aa=b' })
end
T['align_strings()']['validates `strings` argument'] = function()
expect.error(function() child.lua([[MiniAlign.align_strings({'a', 1})]]) end, 'string')
expect.error(function() child.lua([[MiniAlign.align_strings('a')]]) end, 'array')
end
T['align_strings()']['respects `strings` argument'] = function()
validate_align_strings({ 'aaa=b', 'aa=b' }, { split_pattern = '=' }, { 'aaa=b', 'aa =b' })
end
T['align_strings()']['respects `opts` argument'] = function()
-- Should take default values from `MiniAlign.config.options`
child.lua([[MiniAlign.config.options.test = 'xxx']])
child.lua([[ MiniAlign.config.steps.pre_split = {
MiniAlign.new_step('test', function(strings, opts) strings[1] = opts.test end)
}]])
eq(child.lua_get([[MiniAlign.align_strings({ 'a=b', 'aa=b' }, { split_pattern = '=' }, {})]]), { 'xxx', 'aa=b' })
end
T['align_strings()']['respects `opts.split_pattern`'] = function()
-- Single string
validate_align_strings({ 'a,b', 'aa,b' }, { split_pattern = ',' }, { 'a ,b', 'aa,b' })
-- Array of strings (should be recycled)
validate_align_strings(
{ 'a,b=c,d=e,', 'aa,bb=cc,dd=ee,' },
{ split_pattern = { ',', '=' } },
{ 'a ,b =c ,d =e ,', 'aa,bb=cc,dd=ee,' }
)
end
T['align_strings()']['respects `opts.justify_side` argument'] = function()
-- Single string
--stylua: ignore start
validate_align_strings({ 'a=b', 'aaa=b' }, { split_pattern = '=', justify_side = 'left' }, { 'a =b', 'aaa=b' })
validate_align_strings({ 'a=b', 'aaa=b' }, { split_pattern = '=', justify_side = 'center' }, { ' a =b', 'aaa=b' })
validate_align_strings({ 'a=b', 'aaa=b' }, { split_pattern = '=', justify_side = 'right' }, { ' a=b', 'aaa=b' })
validate_align_strings({ 'a=b', 'aaa=b' }, { split_pattern = '=', justify_side = 'none' }, { 'a=b', 'aaa=b' })
--stylua: ignore end
-- Array of strings (should be recycled)
validate_align_strings(
{ 'a=b=c=d=e', 'aaa =bbb =ccc =ddd =eee' },
{ split_pattern = '%s*=', justify_side = { 'left', 'center', 'right' } },
-- Part resulted from separator is treated the same as any other part
{ 'a = b= c =d = e', 'aaa =bbb =ccc =ddd =eee' }
)
end
T['align_strings()']['respects `opts.merge_delimiter` argument'] = function()
-- Single string
validate_align_strings({ 'a=b' }, { split_pattern = '=', merge_delimiter = '-' }, { 'a-=-b' })
-- Array of strings (should be recycled)
validate_align_strings(
{ 'a=b=c=' },
{ split_pattern = '=', merge_delimiter = { '-', '!' } },
-- Part resulted from separator is treated the same as any other part
{ 'a-=!b-=!c-=' }
)
end
T['align_strings()']['same `opts` is used for all steps'] = function()
-- So that it can be used by steps to pass information to later steps
set_config_steps({
pre_split = [[{ MiniAlign.new_step('sss', function(strings, opts) opts.sss = 'sss' end) }]],
merge = [[MiniAlign.new_step('mmm', function(parts, opts) return { opts.sss } end)]],
})
validate_align_strings({ 'a=b' }, { split_pattern = '=' }, { 'sss' })
end
T['align_strings()']['validates `steps` argument'] = function()
-- `split_pattern` is `''` by default but it is needed for `align_strings()`
set_config_opts({ split_pattern = '=' })
local validate = function(steps_str, error_pattern)
expect.error(function()
local cmd = string.format([[MiniAlign.align_strings({'a=b', 'aa=b'}, {}, %s)]], steps_str)
child.lua(cmd)
end, error_pattern)
end
validate([[{ pre_split = 1 }]], 'pre_split.*array of steps')
validate([[{ pre_split = { function() end } }]], 'pre_split.*array of steps')
validate([[{ split = 1 }]], 'split.*step')
validate([[{ split = function() end }]], 'split.*step')
validate([[{ pre_justify = 1 }]], 'pre_justify.*array of steps')
validate([[{ pre_justify = { function() end } }]], 'pre_justify.*array of steps')
validate([[{ justify = 1 }]], 'justify.*step')
validate([[{ justify = function() end }]], 'justify.*step')
validate([[{ pre_merge = 1 }]], 'pre_merge.*array of steps')
validate([[{ pre_merge = { function() end } }]], 'pre_merge.*array of steps')
validate([[{ merge = 1 }]], 'merge.*step')
validate([[{ merge = function() end }]], 'merge.*step')
end
T['align_strings()']['respects `steps.pre_split` argument'] = function()
set_config_opts({ split_pattern = '=' })
local step_str, cmd
-- Array of steps
step_str = [[MiniAlign.new_step('tmp', function(strings) strings[1] = 'a=b' end)]]
cmd = string.format([[MiniAlign.align_strings({ 'aaa=b', 'aa=b' }, {}, { pre_split = { %s } })]], step_str)
eq(child.lua_get(cmd), { 'a =b', 'aa=b' })
-- Should validate that step correctly modified in place
step_str = [[MiniAlign.new_step('tmp', function(strings) strings[1] = 1 end)]]
cmd = string.format([[MiniAlign.align_strings({ 'a=b', 'aa=b' }, {}, { pre_split = { %s } })]], step_str)
expect.error(child.lua, 'Step `tmp` of `pre_split` should preserve structure of `strings`.', cmd)
-- Uses `MiniAlign.config.steps` as default
set_config_steps({ pre_split = [[{ MiniAlign.new_step('tmp', function(strings) strings[1] = 'a=b' end) }]] })
validate_align_strings({ 'aaa=b', 'aa=b' }, { split_pattern = '=' }, { 'a =b', 'aa=b' })
-- Is called with `opts`
step_str = [[MiniAlign.new_step('tmp', function(strings, opts) strings[1] = opts.tmp end)]]
cmd =
string.format([[MiniAlign.align_strings({ 'aaa=b', 'aa=b' }, { tmp = 'xxx' }, { pre_split = { %s } })]], step_str)
eq(child.lua_get(cmd), { 'xxx', 'aa=b' })
end
T['align_strings()']['respects `steps.split` argument'] = function()
local step_str, cmd
-- Action output should be parts or convertible to it.
step_str = [[MiniAlign.new_step('tmp', function(strings) return { { 'a', 'b' }, {'aa', 'b'} } end)]]
cmd = string.format([[MiniAlign.align_strings({ 'a=b', 'aa=b' }, {}, { split = %s })]], step_str)
eq(child.lua_get(cmd), { 'a b', 'aab' })
step_str =
[[MiniAlign.new_step('tmp', function(strings) return MiniAlign.as_parts({ { 'a', 'b' }, {'aa', 'b'} }) end)]]
cmd = string.format([[MiniAlign.align_strings({ 'a=b', 'aa=b' }, {}, { split = %s })]], step_str)
eq(child.lua_get(cmd), { 'a b', 'aab' })
-- Uses `MiniAlign.config.steps` as default
set_config_steps({
split = [[MiniAlign.new_step('tmp', function(strings) return MiniAlign.as_parts({ { 'a', 'b' }, {'aa', 'b'} }) end)]],
})
validate_align_strings({ 'a,b', 'aa,b' }, {}, { 'a b', 'aab' })
-- Should validate that step's output is convertible to parts
step_str = [[MiniAlign.new_step('tmp', function(strings) return { { 'a', 1 }, {'aa', 'b'} } end)]]
cmd = string.format([[MiniAlign.align_strings({ 'a=b', 'aa=b' }, {}, { split = %s })]], step_str)
expect.error(child.lua, 'convertible to parts', cmd)
-- Is called with `opts`
step_str = [[MiniAlign.new_step('tmp', function(strings, opts) return MiniAlign.as_parts(opts.tmp) end)]]
cmd = string.format([[MiniAlign.align_strings({ 'a=b', 'aa=b' }, { tmp = { { 'xxx' } } }, { split = %s })]], step_str)
eq(child.lua_get(cmd), { 'xxx' })
end
T['align_strings()']['respects `steps.pre_justify` argument'] = function()
set_config_opts({ split_pattern = '=' })
local step_str, cmd
-- Array of steps
step_str = [[MiniAlign.new_step('tmp', function(parts) parts[1][1] = 'xxx' end)]]
cmd = string.format([[MiniAlign.align_strings({ 'aaa=b', 'aa=b' }, {}, { pre_justify = { %s } })]], step_str)
eq(child.lua_get(cmd), { 'xxx=b', 'aa =b' })
-- Should validate that step correctly modified in place
step_str = [[MiniAlign.new_step('tmp', function(parts) parts[1][1] = 1 end)]]
cmd = string.format([[MiniAlign.align_strings({ 'a=b', 'aa=b' }, {}, { pre_justify = { %s } })]], step_str)
expect.error(
child.lua,
vim.pesc('Step `tmp` of `pre_justify` should preserve structure of `parts`. See `:h MiniAlign.as_parts()`.'),
cmd
)
-- Uses `MiniAlign.config.steps` as default
set_config_steps({ pre_justify = [[{ MiniAlign.new_step('tmp', function(parts) parts[1][1] = 'xxx' end) }]] })
validate_align_strings({ 'aaa=b', 'aa=b' }, { split_pattern = '=' }, { 'xxx=b', 'aa =b' })
-- Is called with `opts`
step_str = [[MiniAlign.new_step('tmp', function(parts, opts) parts[1][1] = opts.tmp end)]]
cmd =
string.format([[MiniAlign.align_strings({ 'aaa=b', 'aa=b' }, { tmp = 'xxx' }, { pre_justify = { %s } })]], step_str)
eq(child.lua_get(cmd), { 'xxx=b', 'aa =b' })
end
T['align_strings()']['respects `steps.justify` argument'] = function()
set_config_opts({ split_pattern = '=' })
local step_str, cmd
-- Action should modify parts in place.
step_str = [[MiniAlign.new_step('tmp', function(parts) parts[1][1] = 'xxx' end)]]
cmd = string.format([[MiniAlign.align_strings({ 'a=b', 'aa=b' }, {}, { justify = %s })]], step_str)
eq(child.lua_get(cmd), { 'xxx=b', 'aa=b' })
-- Uses `MiniAlign.config.steps` as default
set_config_steps({
justify = [[MiniAlign.new_step('tmp', function(parts) parts[1][1] = 'xxx' end)]],
})
validate_align_strings({ 'a=b', 'aa=b' }, { split_pattern = '=' }, { 'xxx=b', 'aa=b' })
-- Should validate that step correctly modified in place
step_str = [[MiniAlign.new_step('tmp', function(parts) parts[1][1] = 1 end)]]
cmd = string.format([[MiniAlign.align_strings({ 'a=b', 'aa=b' }, {}, { justify = %s })]], step_str)
expect.error(
child.lua,
vim.pesc('Step `tmp` of `justify` should preserve structure of `parts`. See `:h MiniAlign.as_parts()`.'),
cmd
)
-- Is called with `opts`
step_str = [[MiniAlign.new_step('tmp', function(parts, opts) parts[1][1] = opts.tmp end)]]
cmd = string.format([[MiniAlign.align_strings({ 'a=b', 'aa=b' }, { tmp = 'xxx' }, { justify = %s })]], step_str)
eq(child.lua_get(cmd), { 'xxx=b', 'aa=b' })
end
T['align_strings()']['respects `steps.pre_merge` argument'] = function()
set_config_opts({ split_pattern = '=' })
local step_str, cmd
-- Array of steps
step_str = [[MiniAlign.new_step('tmp', function(parts) parts[1][1] = 'xxx' end)]]
cmd = string.format([[MiniAlign.align_strings({ 'aaa=b', 'aa=b' }, {}, { pre_merge = { %s } })]], step_str)
eq(child.lua_get(cmd), { 'xxx=b', 'aa =b' })
-- Should validate that step correctly modified in place
step_str = [[MiniAlign.new_step('tmp', function(parts) parts[1][1] = 1 end)]]
cmd = string.format([[MiniAlign.align_strings({ 'a=b', 'aa=b' }, {}, { pre_merge = { %s } })]], step_str)
expect.error(
child.lua,
vim.pesc('Step `tmp` of `pre_merge` should preserve structure of `parts`. See `:h MiniAlign.as_parts()`.'),
cmd
)
-- Uses `MiniAlign.config.steps` as default
set_config_steps({ pre_merge = [[{ MiniAlign.new_step('tmp', function(parts) parts[1][1] = 'xxx' end) }]] })
validate_align_strings({ 'aaa=b', 'aa=b' }, { split_pattern = '=' }, { 'xxx=b', 'aa =b' })
-- Is called with `opts`
step_str = [[MiniAlign.new_step('tmp', function(parts, opts) parts[1][1] = opts.tmp end)]]
cmd =
string.format([[MiniAlign.align_strings({ 'aaa=b', 'aa=b' }, { tmp = 'xxx' }, { pre_merge = { %s } })]], step_str)
eq(child.lua_get(cmd), { 'xxx=b', 'aa =b' })
end
T['align_strings()']['respects `steps.merge` argument'] = function()
set_config_opts({ split_pattern = '=' })
local step_str, cmd
-- Action should return array of strings.
step_str = [[MiniAlign.new_step('tmp', function(parts) return { 'xxx' } end)]]
cmd = string.format([[MiniAlign.align_strings({ 'a=b', 'aa=b' }, {}, { merge = %s })]], step_str)
eq(child.lua_get(cmd), { 'xxx' })
-- Uses `MiniAlign.config.steps` as default
set_config_steps({ merge = [[MiniAlign.new_step('tmp', function(parts) return { 'xxx' } end)]] })
validate_align_strings({ 'a=b' }, { split_pattern = '=' }, { 'xxx' })
-- Should validate that output is an array of strings
step_str = [[MiniAlign.new_step('tmp', function(parts) return { 'a', 1 } end)]]
cmd = string.format([[MiniAlign.align_strings({ 'a=b', 'aa=b' }, {}, { merge = %s })]], step_str)
expect.error(child.lua, vim.pesc('Output of `merge` step should be array of strings.'), cmd)
-- Is called with `opts`
step_str = [[MiniAlign.new_step('tmp', function(parts, opts) return { opts.tmp } end)]]
cmd = string.format([[MiniAlign.align_strings({ 'a=b', 'aa=b' }, { tmp = 'xxx' }, { merge = %s })]], step_str)
eq(child.lua_get(cmd), { 'xxx' })
end
T['align_strings()']['works with multibyte characters'] = function()
validate_align_strings(
{ 'ыффццц', 'ыыыффц' },
{ split_pattern = 'ф', justify_side = 'center', merge_delimiter = 'ю' },
{ ' ы юфюфюццц', 'ыыыюфюфю ц' }
)
end
T['align_strings()']['does not affect input array'] = function()
child.lua([[strings = { 'a=b', 'aa=b' }]])
child.lua([[pre_split = { MiniAlign.new_step('aaa', function(s, _) s[1] = 'xxx' end) }]])
child.lua([[MiniAlign.align_strings(strings, { split_pattern = '=' }, { pre_split = pre_split })]])
eq(child.lua_get('strings'), { 'a=b', 'aa=b' })
end
T['align_strings()']['respects `vim.b.minialign_config`'] = function()
child.b.minialign_config = { options = { split_pattern = '=' } }
validate_align_strings({ 'a=b', 'aa=b' }, {}, { 'a =b', 'aa=b' })
-- Should take precedence over global cofnfig
set_config_opts({ split_pattern = ',' })
validate_align_strings({ 'a=b', 'aa=b' }, {}, { 'a =b', 'aa=b' })
end
local is_parts = function(var_name)
local cmd = string.format('getmetatable(%s).class', var_name)
eq(child.lua_get(cmd), 'parts')
end
T['as_parts()'] = new_set()
T['as_parts()']['works'] = function()
child.lua([[parts = MiniAlign.as_parts({ { 'a', 'b' }, { 'c' } })]])
eq(child.lua_get('type(parts.get_dims)'), 'function')
end
T['as_parts()']['validates arguments'] = function()
local validate = function(input_str, err_pattern)
expect.error(function() child.lua('MiniAlign.as_parts(' .. input_str .. ')') end, err_pattern)
end
validate('', 'Input of `as_parts%(%)` should be table')
validate('1', 'table')
validate([[{ 'a' }]], 'Input of `as_parts%(%)` values should be an array of strings')
validate([[{ { 1 } }]], 'array of strings')
validate([[{ { 'a' }, 'a' }]], 'array of strings')
end
T['as_parts()']['works with empty table'] = function()
-- Empty parts
child.lua('empty = MiniAlign.as_parts({})')
is_parts('empty')
-- All methods should work
local validate_method = function(method_call, output, ...)
child.lua('empty = MiniAlign.as_parts({})')
local cmd = string.format('empty.%s', method_call)
if output ~= nil then
eq(child.lua_get(cmd, { ... }), output)
else
child.lua(cmd, { ... })
eq(child.lua_get('empty'), {})
end
end
validate_method([[apply_inplace(function(s) return 'a' end)]])
validate_method('group()')
validate_method('pair()')
validate_method('trim()')
validate_method('apply(function(s) return 1 end)', {})
validate_method('get_dims()', { row = 0, col = 0 })
validate_method('slice_col(1)', {})
validate_method('slice_row(1)', {})
end
T['as_parts()']['`apply()` method'] = function()
child.lua([[parts = MiniAlign.as_parts({ { 'a', 'b' }, { 'c' } })]])
eq(
child.lua_get('parts.apply(function(x, data) return x .. data.row .. data.col end)'),
{ { 'a11', 'b12' }, { 'c21' } }
)
end
T['as_parts()']['`apply_inplace()` method'] = function()
child.lua([[parts = MiniAlign.as_parts({ { 'a', 'b' }, { 'c' } })]])
child.lua('new_parts = parts.apply_inplace(function(x, data) return x .. data.row .. data.col end)')
eq(child.lua_get('parts'), { { 'a11', 'b12' }, { 'c21' } })
-- Should return itself to enable chaining
eq_tostring('parts', 'new_parts')
end
T['as_parts()']['`get_dims()` method'] = function()
local validate = function(arr2d_str, dims)
local cmd = string.format('MiniAlign.as_parts(%s).get_dims()', arr2d_str)
eq(child.lua_get(cmd), dims)
end
validate([[{ { 'a' } }]], { row = 1, col = 1 })
validate([[{ { 'a', 'b' } }]], { row = 1, col = 2 })
validate([[{ { 'a', 'b' }, { 'c' } }]], { row = 2, col = 2 })
validate([[{ { 'a', 'b' }, { 'c', 'd', 'e' } }]], { row = 2, col = 3 })
validate([[{}]], { row = 0, col = 0 })
end
local validate_parts_group = function(arr2d_str, mask_str, output, direction)
child.lua(('parts = MiniAlign.as_parts(%s)'):format(arr2d_str))
direction = direction == nil and '' or (', ' .. vim.inspect(direction))
child.lua(('new_parts = parts.group(%s%s)'):format(mask_str, direction))
eq(child.lua_get('parts'), output)
-- Should return itself to enable chaining
eq_tostring('parts', 'new_parts')
end
T['as_parts()']['`group()` method'] = new_set()
T['as_parts()']['`group()` method']['works'] = function()
validate_parts_group(
[[{ { 'a', 'b', 'c' }, { 'd' } }]],
'{ { false, false, true }, { true } }',
{ { 'abc' }, { 'd' } }
)
end
T['as_parts()']['`group()` method']['respects `mask` argument'] = function()
local arr2d_str
arr2d_str = [[{ { 'a', 'b' } }]]
validate_parts_group(arr2d_str, '{ { false, false } }', { { 'ab' } })
validate_parts_group(arr2d_str, '{ { false, true } }', { { 'ab' } })
validate_parts_group(arr2d_str, '{ { true, false } }', { { 'a', 'b' } })
validate_parts_group(arr2d_str, '{ { true, true } }', { { 'a', 'b' } })
arr2d_str = [[{ { 'a', 'b' }, { 'c', 'd', 'e' } }]]
validate_parts_group(arr2d_str, '{ { false, true }, { true, false, true } }', { { 'ab' }, { 'c', 'de' } })
-- Default direction is 'left'
arr2d_str = [[{ { 'a', 'b', 'c', 'd' } }]]
validate_parts_group(arr2d_str, '{ { false, true, false, false } }', { { 'ab', 'cd' } })
end
T['as_parts()']['`group()` method']['respects `direction` argument'] = function()
local validate = function(...)
local dots = { ... }
table.insert(dots, 'right')
validate_parts_group(unpack(dots))
end
local arr2d_str
arr2d_str = [[{ { 'a', 'b' } }]]
validate(arr2d_str, '{ { false, false } }', { { 'ab' } })
validate(arr2d_str, '{ { false, true } }', { { 'a', 'b' } })
validate(arr2d_str, '{ { true, false } }', { { 'ab' } })
validate(arr2d_str, '{ { true, true } }', { { 'a', 'b' } })
arr2d_str = [[{ { 'a', 'b' }, { 'c', 'd', 'e' } }]]
validate(arr2d_str, '{ { false, true }, { true, false, true } }', { { 'a', 'b' }, { 'cd', 'e' } })
-- Should differ from default 'left' direction
arr2d_str = [[{ { 'a', 'b', 'c', 'd' } }]]
validate(arr2d_str, '{ { false, true, false, false } }', { { 'a', 'bcd' } })
end
T['as_parts()']['`pair()` method'] = new_set()
T['as_parts()']['`pair()` method']['works'] = function()
child.lua([[parts = MiniAlign.as_parts({ { 'a' }, { 'b', 'c' }, { 'd', 'e', 'f' } })]])
child.lua('new_parts = parts.pair()')
eq(child.lua_get('parts'), { { 'a' }, { 'bc' }, { 'de', 'f' } })
-- Should return itself to enable chaining
eq_tostring('parts', 'new_parts')
end
T['as_parts()']['`pair()` method']['respects `direction` argument'] = function()
child.lua([[parts = MiniAlign.as_parts({ { 'a' }, { 'b', 'c' }, { 'd', 'e', 'f' } })]])
child.lua([[parts.pair('right')]])
eq(child.lua_get('parts'), { { 'a' }, { 'bc' }, { 'd', 'ef' } })
end
T['as_parts()']['`slice_col()` method'] = function()
child.lua([[parts = MiniAlign.as_parts({ { 'a' }, { 'b', 'c' }, { 'd' } })]])
eq(child.lua_get('parts.slice_col(0)'), {})
eq(child.lua_get('parts.slice_col(1)'), { 'a', 'b', 'd' })
-- `slice_col()` may not return array (table with only 1, ..., n keys)
eq(child.lua_get([[vim.deep_equal(parts.slice_col(2), { [2] = 'c' })]]), true)
eq(child.lua_get('parts.slice_col(3)'), {})
end
T['as_parts()']['`slice_row()` method'] = function()
child.lua([[parts = MiniAlign.as_parts({ { 'a' }, { 'b', 'c' } })]])
eq(child.lua_get('parts.slice_row(0)'), {})
eq(child.lua_get('parts.slice_row(1)'), { 'a' })
eq(child.lua_get('parts.slice_row(2)'), { 'b', 'c' })
eq(child.lua_get('parts.slice_col(3)'), {})
end
T['as_parts()']['`trim()` method'] = new_set()
T['as_parts()']['`trim()` method']['works'] = function()
child.lua([[parts = MiniAlign.as_parts({ { ' a ', ' b ', ' c', 'd ', 'e' }, { ' f ' } })]])
child.lua('new_parts = parts.trim()')
-- By default trims from both directions and keeps indentation (left
-- whitespace of every first row string)
eq(child.lua_get('parts'), { { ' a', 'b', 'c', 'd', 'e' }, { ' f' } })
-- Should return itself to enable chaining
eq_tostring('parts', 'new_parts')
end
T['as_parts()']['`trim()` method']['validates arguments'] = function()
child.lua([[parts = MiniAlign.as_parts({ { ' a ' } })]])
local err_pattern
-- `direction`
err_pattern = '`direction` should be one of "both", "left", "none", "right"'
expect.error(function() child.lua([[parts.trim(1)]]) end, err_pattern)
expect.error(function() child.lua([[parts.trim('a')]]) end, err_pattern)
-- `indent`
err_pattern = '`indent` should be one of "high", "keep", "low", "remove"'
expect.error(function() child.lua([[parts.trim('both', 1)]]) end, err_pattern)
expect.error(function() child.lua([[parts.trim('both', 'a')]]) end, err_pattern)
end
T['as_parts()']['`trim()` method']['respects `direction` argument'] = function()
local validate = function(direction, output)
child.lua([[parts = MiniAlign.as_parts({ { ' a ', ' b ', ' c', 'd ', 'e' }, { ' f ' } })]])
child.lua(([[parts.trim('%s')]]):format(direction))
eq(child.lua_get('parts'), output)
end
--stylua: ignore start
validate('both', { { ' a', 'b', 'c', 'd', 'e' }, { ' f' } })
validate('left', { { ' a ', 'b ', 'c', 'd ', 'e' }, { ' f ' } })
validate('right', { { ' a', ' b', ' c', 'd', 'e' }, { ' f' } })
validate('none', { { ' a ', ' b ', ' c', 'd ', 'e' }, { ' f ' } })
--stylua: ignore end
end
T['as_parts()']['`trim()` method']['respects `indent` argument'] = function()
local validate = function(indent, output)
child.lua([[parts = MiniAlign.as_parts({ { ' a ', ' b ' }, { ' c ', ' d ' } })]])
child.lua(([[parts.trim('both', '%s')]]):format(indent))
eq(child.lua_get('parts'), output)
end
--stylua: ignore start
validate('keep', { { ' a', 'b' }, { ' c', 'd' } })
validate('low', { { ' a', 'b' }, { ' c', 'd' } })
validate('high', { { ' a', 'b' }, { ' c', 'd' } })
validate('remove', { { 'a', 'b' }, { 'c', 'd' } })
--stylua: ignore end
end
T['new_step()'] = new_set()
T['new_step()']['works'] = function()
child.lua([[step = MiniAlign.new_step('aaa', function() end)]])
validate_step('step', 'aaa')
-- Allows callable table as action
child.lua([[action = setmetatable({}, { __call = function() end })]])
child.lua([[step = MiniAlign.new_step('aaa', action)]])
validate_step('step', 'aaa')
end
T['new_step()']['validates arguments'] = function()
local validate = function(args_str, err_pattern)
expect.error(function() child.lua('MiniAlign.new_step(' .. args_str .. ')') end, err_pattern)
end
validate([[1]], 'Step name should be string')
validate([['aaa', 1]], 'Step action should be callable')
end
T['gen_step'] = new_set()
T['gen_step']['default_split()'] = new_set({
hooks = { pre_case = function() set_config_steps({ split = [[MiniAlign.gen_step.default_split('test')]] }) end },
})
T['gen_step']['default_split()']['works'] = function()
-- Returns proper step
child.lua([[step = MiniAlign.gen_step.default_split()]])
validate_step('step', 'split')
-- Single string
validate_align_strings({ 'a,b', 'aa,b' }, { split_pattern = ',' }, { 'a ,b', 'aa,b' })
-- Array of strings (should be recycled)
validate_align_strings({ 'a,b', 'aa,b' }, { split_pattern = { ',' } }, { 'a ,b', 'aa,b' })
validate_align_strings(
{ 'a,b=c,d=e,', 'aa,bb=cc,dd=ee,' },
{ split_pattern = { ',', '=' } },
{ 'a ,b =c ,d =e ,', 'aa,bb=cc,dd=ee,' }
)
end
T['gen_step']['default_split()']['verifies relevant options'] = function()
expect.error(
function() child.lua([[MiniAlign.align_strings({ 'a' }, { split_pattern = 1 }, {})]]) end,
'Option `split_pattern`.*string or array of strings'
)
expect.error(
function() child.lua([[MiniAlign.align_strings({ 'a' }, { split_exclude_patterns = 1 }, {})]]) end,
'Option `split_exclude_patterns`.*array of strings'
)
end
T['gen_step']['default_split()']['allows split Lua pattern'] = function()
set_config_opts({ split_pattern = '%s*=%s*', merge_delimiter = '-' })
validate_align_strings({ 'a=b =c= d = e' }, {}, { 'a-=-b- =-c-= -d- = -e' })
end
T['gen_step']['default_split()']['verifies bad split pattern'] = function()
expect.error(
function() child.lua([[MiniAlign.align_strings({ 'a ' }, { split_pattern = '%f[%s]' })]]) end,
vim.pesc('(mini.align) Pattern "%f[%s]" can not advance search.')
)
end
T['gen_step']['default_split()']['works with different number of output parts'] = function()
set_config_opts({ split_pattern = ',', merge_delimiter = '-' })
validate_align_strings({ 'a', 'b,', 'c,d' }, {}, { 'a', 'b-,', 'c-,-d' })
end
T['gen_step']['default_split()']['works with empty input strings'] = function()
child.lua('step = MiniAlign.gen_step.default_split()')
eq(
child.lua_get([[step.action({ 'a=b', '', '=', '' }, { split_pattern = '=' })]]),
{ { 'a', '=', 'b' }, { '' }, { '', '=' }, { '' } }
)
end
T['gen_step']['default_split()']['works with no split pattern found'] = function()
set_config_opts({ split_pattern = ',', merge_delimiter = '-' })
-- In some lines
validate_align_strings({ 'a,b', 'a=b' }, { justify_side = 'center' }, { ' a -,-b', 'a=b' })
-- In all lines
validate_align_strings({ 'a=b', 'a=bb' }, {}, { 'a=b', 'a=bb' })
end
T['gen_step']['default_split()']['works with special split patterns'] = function()
set_config_opts({ merge_delimiter = '-' })
-- Treat `''` as no split pattern is found
set_config_opts({ split_pattern = '' })
validate_align_strings({ 'a=b', 'a=bbb' }, {}, { 'a=b', 'a=bbb' })
-- Treat `'.'` as any character is a split
set_config_opts({ split_pattern = '.' })
validate_align_strings({ 'a=b', 'a=bbb' }, {}, { 'a-=-b', 'a-=-b-b-b' })
-- Works with `^`
set_config_opts({ split_pattern = '^.' })
validate_align_strings({ 'a=b', 'a=bbb' }, {}, { 'a-=b', 'a-=bbb' })
-- Works with `$`
set_config_opts({ split_pattern = '.$' })
validate_align_strings({ 'a=b', 'a=bbb' }, {}, { 'a= -b', 'a=bb-b' })
end
T['gen_step']['default_split()']['respects `split_exclude_patterns` option'] = function()
validate_align_strings(
{ [[a="=="'=='b=c]], 'a=b=c' },
{ split_pattern = '=', split_exclude_patterns = { [[".-"]], [['.-']] } },
{ [[a="=="'=='b=c]], 'a=b =c' }
)
-- Split match should be ignored if any its edge is inside any forbidden span
validate_align_strings(
{ 'a"<"=b<"=c', 'a<"=b' },
{ split_pattern = '<"=', split_exclude_patterns = { [[".-"]] } },
{ 'a"<"=b<"=c', 'a <"=b' }
)
end
T['gen_step']['default_split()']['works with special exclude patterns'] = function()
local lines = { 'a=b', 'cc=d', 'eee=f' }
local output_lines = { 'a=b', 'cc =d', 'eee=f' }
-- Start of line
validate_align_strings(lines, { split_pattern = '=', split_exclude_patterns = { '^a.*' } }, output_lines)
-- End of line
validate_align_strings(lines, { split_pattern = '=', split_exclude_patterns = { 'a.*$' } }, output_lines)
-- Both start of line and end of line
validate_align_strings(lines, { split_pattern = '=', split_exclude_patterns = { '^a.*$' } }, output_lines)
end
--stylua: ignore
T['gen_step']['default_split()']['matches inside forbidden spans do not affect split pattern recycling'] = function()
validate_align_strings(
{ [[a,"b=b"=c,d]], 'aa,bb=cc,dd' },
{ split_pattern = { ',', '=' }, split_exclude_patterns = { [[".-"]] } },
{ [[a ,"b=b"=c ,d]], 'aa,bb =cc,dd' }
)
end
T['gen_step']['default_justify()'] = new_set({
hooks = {
pre_case = function() set_config_steps({ justify = [[MiniAlign.gen_step.default_justify('test')]] }) end,
},
})
T['gen_step']['default_justify()']['works'] = function()
-- Returns proper step
child.lua([[step = MiniAlign.gen_step.default_justify()]])
validate_step('step', 'justify')
-- Single string
set_config_opts({ split_pattern = '=' })
--stylua: ignore start
validate_align_strings({ 'a=b', 'aaa=b' }, { justify_side = 'left' }, { 'a =b', 'aaa=b' })
validate_align_strings({ 'a=b', 'aaa=b' }, { justify_side = 'center' }, { ' a =b', 'aaa=b' })
validate_align_strings({ 'a=b', 'aaa=b' }, { justify_side = 'right' }, { ' a=b', 'aaa=b' })
validate_align_strings({ 'a=b', 'aaa=b' }, { justify_side = 'none' }, { 'a=b', 'aaa=b' })
--stylua: ignore end
-- Array of strings (should be recycled)
set_config_opts({ split_pattern = '%s*=' })
validate_align_strings(
{ 'a=b=c=d=e', 'aaa =bbb =ccc =ddd =eee' },
{ justify_side = { 'left', 'center', 'right' } },
-- Part resulted from separator is treated the same as any other part
{ 'a = b= c =d = e', 'aaa =bbb =ccc =ddd =eee' }
)
end
T['gen_step']['default_justify()']['verifies relevant options'] = function()
expect.error(
function() child.lua([[MiniAlign.align_strings({ 'a' }, { justify_side = 1 }, {})]]) end,
'Option `justify_side`.*one of.*or array'
)
end
T['gen_step']['default_justify()']['works with multibyte characters'] = function()
set_config_opts({ split_pattern = '=' })
--stylua: ignore start
validate_align_strings({ 'ы=ю', 'ыыы=ююю' }, { justify_side = 'left' }, { 'ы =ю', 'ыыы=ююю' })
validate_align_strings({ 'ы=ю', 'ыыы=ююю' }, { justify_side = 'center' }, { ' ы = ю', 'ыыы=ююю' })
validate_align_strings({ 'ы=ю', 'ыыы=ююю' }, { justify_side = 'right' }, { ' ы= ю', 'ыыы=ююю' })
validate_align_strings({ 'ы=ю', 'ыыы=ююю' }, { justify_side = 'none' }, { 'ы=ю', 'ыыы=ююю' })
--stylua: ignore end
end
T['gen_step']['default_justify()']['does not add trailing whitespace'] = function()
set_config_opts({ split_pattern = '=' })
--stylua: ignore start
validate_align_strings({ 'a=b', '', 'a=bbb' }, { justify_side = 'left' }, { 'a=b', '', 'a=bbb' })
validate_align_strings({ 'a=b', '', 'a=bbb' }, { justify_side = 'center' }, { 'a= b', '', 'a=bbb' })
validate_align_strings({ 'a=b', '', 'a=bbb' }, { justify_side = 'right' }, { 'a= b', '', 'a=bbb' })
validate_align_strings({ 'a=b', '', 'a=bbb' }, { justify_side = 'none' }, { 'a=b', '', 'a=bbb' })
--stylua: ignore end
-- Also shouldn't add trailing whitespace in multicharacter split
validate_align_strings({ 'aa==bb', 'c=' }, { split_pattern = '=+' }, { 'aa==bb', 'c =' })
end
T['gen_step']['default_justify()']['last row element width is ignored for left justify side'] = function()
set_config_opts({ split_pattern = '=', justify_side = 'left' })
-- It won't be padded so shouldn't contribute to column width
validate_align_strings({ 'a=b', 'aa=b', 'aaaaa' }, {}, { 'a =b', 'aa=b', 'aaaaa' })
validate_align_strings({ 'a=b=c', 'a=bb=c', 'a=bbbbb' }, {}, { 'a=b =c', 'a=bb=c', 'a=bbbbb' })
end
T['gen_step']['default_justify()']['prefers padding left for center justify side'] = function()
set_config_opts({ split_pattern = '=', justify_side = 'center' })
validate_align_strings({ 'a=b', 'aaaa=b' }, {}, { ' a =b', 'aaaa=b' })
end
T['gen_step']['default_justify()']['output step uses `opts.justify_offsets`'] = function()
set_config_opts({ split_pattern = '=' })
-- Using `opts.justify_offsets` allows to respect string prefixes but without
-- processing them. So in this case output should be the same as with
-- `{ ' a=b', ' a=b', 'a=b' }` and equal offsets (but without indents).
validate_align_strings({ 'a=b', 'a=b', 'a=b' }, { justify_offsets = { 3, 2, 0 } }, { 'a=b', 'a =b', 'a =b' })
end
T['gen_step']['default_merge()'] = new_set({
hooks = {
pre_case = function() set_config_steps({ merge = [[MiniAlign.gen_step.default_merge('test')]] }) end,
},
})
T['gen_step']['default_merge()']['works'] = function()
set_config_opts({ split_pattern = '=' })
-- Returns proper step
child.lua([[step = MiniAlign.gen_step.default_merge()]])
validate_step('step', 'merge')
-- Single string
validate_align_strings({ 'a=b' }, { merge_delimiter = '-' }, { 'a-=-b' })
-- Array of strings (should be recycled)
validate_align_strings(
{ 'a=b=c=' },
{ merge_delimiter = { '-', '!' } },
-- Part resulted from separator is treated the same as any other part
{ 'a-=!b-=!c-=' }
)
end
T['gen_step']['default_merge()']['verifies relevant options'] = function()
expect.error(
function() child.lua([[MiniAlign.align_strings({ 'a' }, { merge_delimiter = 1 }, {})]]) end,
'Option `merge_delimiter`.*string or array of strings'
)
end
T['gen_step']['default_merge()']['does not merge empty strings in parts'] = function()
set_config_opts({ split_pattern = '=' })
-- Shouldn't result into adding extra merge
validate_align_strings({ 'a===b' }, { merge_delimiter = '-' }, { 'a-=-=-=-b' })
validate_align_strings({ '=a' }, { merge_delimiter = '-' }, { '=-a' })
end
T['gen_step']['default_merge()']['preserves indentation with whitespace in merge delimmiter'] = function()
set_config_opts({ split_pattern = '=' })
-- Should not add whitespace to the first part if all of them are indent
validate_align_strings({ ' =a=b', ' =c=d' }, { merge_delimiter = ' ' }, { ' = a = b', ' = c = d' })
validate_align_strings({ ' =a=b', '=c=d' }, { merge_delimiter = ' ' }, { ' = a = b', ' = c = d' })
validate_align_strings({ '=a=b', '=c=d' }, { merge_delimiter = ' ' }, { '= a = b', '= c = d' })
validate_align_strings({ ' =a=b', ' =c=d' }, { merge_delimiter = ' _' }, { ' _= _a _= _b', ' _= _c _= _d' })
validate_align_strings({ ' =a=b', 'x=c=d' }, { merge_delimiter = ' ' }, { ' = a = b', 'x = c = d' })
child.o.tabstop = 2
validate_align_strings({ '\t=a=b', '\t\t=c=d' }, { merge_delimiter = '\t' }, { '\t =\ta\t=\tb', '\t\t=\tc\t=\td' })
validate_align_strings({ '\t=a=b', '\t\t=c=d' }, { merge_delimiter = ' ' }, { '\t = a = b', '\t\t= c = d' })
end
T['gen_step']['filter()'] = new_set()
T['gen_step']['filter()']['works'] = function()
set_config_opts({ split_pattern = '=', justify_side = 'center' })
set_config_steps({ pre_justify = [[{ MiniAlign.gen_step.filter('n == 1') }]] })
validate_align_strings({ 'a=b=c', 'aaa=bbb=ccc' }, {}, { ' a = b=c', 'aaa=bbb=ccc' })
-- `nil` allowed as input
eq(child.lua_get('MiniAlign.gen_step.filter()'), vim.NIL)
end
T['gen_step']['filter()']['validates input'] = function()