-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.test.ts
1655 lines (1604 loc) · 44.3 KB
/
extension.test.ts
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
import * as assert from 'assert';
import * as vscode from 'vscode';
import * as myExtension from '../../extension';
async function openFileWithCursor(annotated: string, language: string): Promise<{
textEditor: vscode.TextEditor,
targetPos: vscode.Position
}> {
let source = annotated.indexOf('@');
let target = annotated.indexOf('^');
if (source < target) { --target; } else { --source; }
let content = annotated.replace('@', '').replace('^', '');
const doc = await vscode.workspace.openTextDocument({ language, content });
const sourcePos = doc.positionAt(source);
const targetPos = doc.positionAt(target);
const textEditor = await vscode.window.showTextDocument(doc);
textEditor.selection = new vscode.Selection(sourcePos, sourcePos);
return { textEditor, targetPos };
}
function getAnnotatedContent(textEditor: vscode.TextEditor, sourcePos: vscode.Position): string {
const doc = textEditor.document;
const source = doc.offsetAt(sourcePos);
const target = doc.offsetAt(textEditor.selection.active);
let content = textEditor.document.getText();
if (source < target) {
content = content.slice(0, source) + '@' + content.slice(source, target) + '^' + content.slice(target);
} else {
content = content.slice(0, target) + '^' + content.slice(target, source) + '@' + content.slice(source);
}
return content;
}
const isDebugSession = false;
function testCase(content: string, command: string, mode: string, language: string, debugThis?: boolean | undefined) {
if ((isDebugSession && !debugThis) || (!isDebugSession && debugThis)) { return; }
return async () => {
const { textEditor, targetPos } = await openFileWithCursor(content, language);
const sourcePos = textEditor.selection.active;
const commands = new Map(Object.entries({
'goPastNextScope': () => myExtension.goPastSiblingScope(textEditor, false, false),
'goPastPreviousScope': () => myExtension.goPastSiblingScope(textEditor, false, true),
'selectPastNextScope': () => myExtension.goPastSiblingScope(textEditor, true, false),
'selectPastPreviousScope': () => myExtension.goPastSiblingScope(textEditor, true, true),
'goToUpScope': () => myExtension.goToOuterScope(textEditor, false, true, false, false),
'goToDownScope': () => myExtension.goToOuterScope(textEditor, false, false, false, false),
'selectToUpScope': () => myExtension.goToOuterScope(textEditor, true, true, false, false),
'selectToDownScope': () => myExtension.goToOuterScope(textEditor, true, false, false, false),
'goUpOneLiner': () => myExtension.goOneLiner(textEditor, false, true),
'goDownOneLiner': () => myExtension.goOneLiner(textEditor, false, false),
'selectUpOneLiner': () => myExtension.goOneLiner(textEditor, true, true),
'selectDownOneLiner': () => myExtension.goOneLiner(textEditor, true, false),
'goToBeginScope': () => myExtension.goToOuterScope(textEditor, false, true, true, false),
'goToEndScope': () => myExtension.goToOuterScope(textEditor, false, false, true, false),
'selectToBeginScope': () => myExtension.goToOuterScope(textEditor, true, true, false, false),
'selectToEndScope': () => myExtension.goToOuterScope(textEditor, true, false, false, false),
'goBeginScopeOrArg': () => myExtension.goToOuterScope(textEditor, false, true, true, true),
'goEndScopeOrArg': () => myExtension.goToOuterScope(textEditor, false, false, true, true),
'selectBeginScopeOrArg': () => myExtension.goToOuterScope(textEditor, true, true, false, true),
'selectEndScopeOrArg': () => myExtension.goToOuterScope(textEditor, true, false, false, true),
'goPastNextWord': () => myExtension.goPastWord(textEditor, false, false),
'goPastPreviousWord': () => myExtension.goPastWord(textEditor, false, true),
'selectPastNextWord': () => myExtension.goPastWord(textEditor, true, false),
'selectPastPreviousWord': () => myExtension.goPastWord(textEditor, true, true),
'goToPreviousEmptyLine': () => myExtension.goToEmptyLine(textEditor, false, true),
'goToNextEmptyLine': () => myExtension.goToEmptyLine(textEditor, false, false),
'selectToPreviousEmptyLine': () => myExtension.goToEmptyLine(textEditor, true, true),
'selectToNextEmptyLine': () => myExtension.goToEmptyLine(textEditor, true, false),
'goRightOverDelims': () => myExtension.goPastCharacter(textEditor, false, false),
'goLeftOverDelims': () => myExtension.goPastCharacter(textEditor, false, true),
'selectRightOverDelims': () => myExtension.goPastCharacter(textEditor, true, false),
'selectLeftOverDelims': () => myExtension.goPastCharacter(textEditor, true, true),
}));
// TODO(2): enable symbol providers -- perhaps add mocks.
const modes = new Map([
['IND/JTB', ['Indentation', 'JumpToBracket', false]],
['IND/RAW', ['Indentation', 'Raw', false]],
['NON/JTB', ['None', 'JumpToBracket', false]],
['NON/RAW', ['None', 'Raw', false]],
['IND/NON', ['Indentation', 'None', false]],
['NON/NON', ['None', 'None', false]],
['IND/JTB/MM', ['Indentation', 'JumpToBracket', true]],
['IND/RAW/MM', ['Indentation', 'Raw', true]],
['NON/JTB/MM', ['None', 'JumpToBracket', true]],
['NON/RAW/MM', ['None', 'Raw', true]],
['IND/NON/MM', ['Indentation', 'None', true]],
['NON/NON/MM', ['None', 'None', true]],
]);
const modePair = modes.get(mode);
assert.notStrictEqual(modePair, undefined);
if (!modePair) { return; }
const [blockMode, bracketsMode, markmacsMode] = modePair;
vscode.workspace.onDidChangeConfiguration(myExtension.configurationChangeUpdate);
await vscode.workspace.getConfiguration().update("navi-parens.blockScopeMode", blockMode,
vscode.ConfigurationTarget.Global, true);
await vscode.workspace.getConfiguration().update("navi-parens.bracketScopeMode", bracketsMode,
vscode.ConfigurationTarget.Global, true);
await vscode.workspace.getConfiguration().update("navi-parens.isMarkmacsMode", markmacsMode,
vscode.ConfigurationTarget.Global, true);
// Wait extra for the bracket providers to settle.
if (bracketsMode === 'JumpToBracket') {
await new Promise(f => setTimeout(f, 800));
}
// We cannot use vscode.commands.executeCommand because that creates a different TextEditor.
const action = commands.get(command);
assert.notStrictEqual(action, undefined);
if (!action) { return; }
await action();
const result = getAnnotatedContent(textEditor, sourcePos);
// assert.deepEqual(result, content)
assert.deepStrictEqual(textEditor.selection.active, targetPos, result);
};
}
suite('Extension Test Suite', () => {
vscode.window.showInformationMessage('Start all tests.');
for (const mode of ['IND/RAW', 'IND/JTB']) {
// Basics.
test('Basic parentheses navigation: up from between parens ' + mode, testCase(
`(^(@()))`,
'goToUpScope', mode, 'typescript'
));
test('Basic parentheses navigation: down from between parens ' + mode, testCase(
`((@())^)`,
'goToDownScope', mode, 'typescript'
));
test('Basic parentheses navigation: up no-change ' + mode, testCase(
`^@((()))`,
'goToUpScope', mode, 'typescript'
));
test('Basic parentheses navigation: down no-change ' + mode, testCase(
`((()))@^`,
'goToDownScope', mode, 'typescript'
));
test('Basic parentheses navigation: left no-change ' + mode, testCase(
`((^@()))`,
'goPastPreviousScope', mode, 'typescript'
));
test('Basic parentheses navigation: right no-change ' + mode, testCase(
`((()@^))`,
'goPastNextScope', mode, 'typescript'
));
test('Basic parentheses navigation: left ' + mode, testCase(
`(^(())@)`,
'goPastPreviousScope', mode, 'typescript'
));
test('Basic parentheses navigation: right ' + mode, testCase(
`(@(())^)`,
'goPastNextScope', mode, 'typescript'
));
test('Basic parentheses navigation: beginning from between parens ' + mode, testCase(
`((^ ()@()))`,
'goToBeginScope', mode, 'typescript'
));
test('Basic parentheses navigation: end from between parens ' + mode, testCase(
`((()@() ^))`,
'goToEndScope', mode, 'typescript'
));
test('Basic parentheses navigation: beginning no-change ' + mode, testCase(
`((^@()))`,
'goToBeginScope', mode, 'typescript'
));
test('Basic parentheses navigation: end no-change ' + mode, testCase(
`((()@^))`,
'goToEndScope', mode, 'typescript'
));
// Simple syntaxes.
test('Basic syntax navigation: up bracket scope ' + mode, testCase(
`
for ^(let index = 0; index @< array.length; index++) {
const element = array[index];
}
`,
'goToUpScope', mode, 'typescript'
));
test('Basic syntax navigation: down bracket scope ' + mode, testCase(
`
for (let index = 0; index @< array.length; index++)^ {
const element = array[index];
}
`,
'goToDownScope', mode, 'typescript'
));
test('Basic syntax navigation: up bracket-overlap IND scope ' + mode, testCase(
// The bracket scope does not include the indentation scope, always prefer the bracket scope.
`
for (let index = 0; index < array.length; index++) ^{
const element = array@[index];
}
`,
'goToUpScope', mode, 'typescript'
));
test('Basic syntax navigation: down bracket scope 2 ' + mode, testCase(
// The bracket scope does not include the indentation scope, always prefer the bracket scope.
`
for (let index = 0; index < array.length; index++) {
const element = array@[index];
}^
`,
'goToDownScope', mode, 'typescript'
));
test('Basic syntax navigation: down inside-bracket IND scope ' + mode, testCase(
// The bracket scope strictly includes the indentation scope here, so the arguably-worse end-point is correct.
`
{
let index = 0;
const element = array@[index];
^}
`,
'goToDownScope', mode, 'typescript'
));
test('Basic syntax navigation: up bracket scope nested ' + mode, testCase(
`
for (let index = 0; index < array.length; index++) {
const element = array^[@index];
}
`,
'goToUpScope', mode, 'typescript'
));
test('Basic syntax navigation: down bracket scope nested ' + mode, testCase(
`
for (let index = 0; index < array.length; index++) {
const element = array[in@dex]^;
}
`,
'goToDownScope', mode, 'typescript'
));
test('Basic syntax navigation: next bracket scope ' + mode, testCase(
// As a special case, when the cursor is already inside the block scope (cannot happen for
// the bracket scope), we go past the bracket end scope.
`
fo@r (let index = 0; index < array.length; index++)^ {
const element = array[index];
}
`,
'goPastNextScope', mode, 'typescript'
));
test('Basic syntax navigation: previous bracket scope ' + mode, testCase(
`
for ^(let index = 0; index < array.length; index++) @{
const element = array[index];
}
`,
'goPastPreviousScope', mode, 'typescript'
));
test('Basic syntax navigation: next bracket scope inside ' + mode, testCase(
`
for (let index = 0; index < array.length; index++) {
c@onst element = array[index]^;
}
`,
'goPastNextScope', mode, 'typescript'
));
test('Basic syntax navigation: previous bracket scope inside ' + mode, testCase(
`
for (let index = 0; index < array.length; index++) {
const element = array^[index];
@ }
`,
'goPastPreviousScope', mode, 'typescript'
));
test('Basic syntax navigation: begin scope with IND ' + mode, testCase(
// (For indentation the less-indented line is a big delimiter, its start is outside but it is not inside.)
`
for (let index = 0; index < array.length; index++) {
^const element = @array[index];
}
`,
'goToBeginScope', mode, 'typescript'
));
test('Basic syntax navigation: end scope with IND ' + mode, testCase(
`
for (let index = 0; index < array.length; index++) {
const element = @array[index];^
}
`,
'goToEndScope', mode, 'typescript'
));
test('Tricky syntax navigation: next scope with IND from code line ' + mode, testCase(
`
@for (let index = 0; index < array.length; index++) {
const element = array[index];
}^
`,
'goPastNextScope', mode, 'typescript'
));
test('Tricky syntax navigation: next scope with IND from code line 2 ' + mode, testCase(
`
@{
let local = true;
}^
{
let local = 'true';
}
`,
'goPastNextScope', mode, 'typescript'
));
test('Tricky syntax navigation: next scope with IND from code line 3 ' + mode, testCase(
`
@{
let local = true; }
^{
let local = 'true';
}
`,
'goPastNextScope', mode, 'typescript'
));
test('Tricky syntax navigation: next scope with IND from empty line ' + mode, testCase(
`
@
for (let index = 0; index < array.length; index++) {
const element = array[index];
}^
`,
'goPastNextScope', mode, 'typescript'
));
test('Tricky syntax navigation: next scope with IND from empty line to empty line ' + mode, testCase(
`
@
def foo(bar, baz):
bar()
baz()
^
pass
`,
'goPastNextScope', mode, 'python'
));
test('Tricky syntax navigation: next scope with IND from python code line ' + mode, testCase(
`
@def foo(bar, baz):
bar()
baz()
^
pass
`,
'goPastNextScope', mode, 'python'
));
test('Tricky syntax navigation: down scope with IND from header line no change ' + mode, testCase(
`
@^def foo(bar, baz):
bar()
baz()
pass
`,
'goToDownScope', mode, 'python'
));
test('Tricky syntax navigation: down scope with IND from header line 2 no change ' + mode, testCase(
`
d@^ef foo(bar, baz):
bar()
baz()
pass
`,
'goToDownScope', mode, 'python'
));
test('Tricky syntax navigation: down scope with IND from inner line ' + mode, testCase(
`
def foo(bar, baz):
ba@r()
baz()
^
pass
`,
'goToDownScope', mode, 'python'
));
test('Tricky syntax navigation: previous scope with IND from code line ' + mode, testCase(
`
^def foo(bar, baz):
bar()
baz()
@pass
`,
'goPastPreviousScope', mode, 'python'
));
test('Tricky syntax navigation: previous scope with IND from attached code line ' + mode, testCase(
`
^def foo(bar, baz):
bar()
baz()
@pass
`,
'goPastPreviousScope', mode, 'python'
));
test('Tricky syntax navigation: previous scope with IND from empty line ' + mode, testCase(
`
^def foo(bar, baz):
bar()
baz()
pass
@
`,
'goPastPreviousScope', mode, 'python'
));
test('Tricky syntax navigation: previous scope with IND from hanging empty line ' + mode, testCase(
`
def foo(bar, baz):
bar()
baz^()
@
`,
'goPastPreviousScope', mode, 'python'
));
test('Tricky syntax navigation: previous scope with IND from separating empty line ' + mode, testCase(
`
def foo(bar, baz):
bar()
baz^()
@
pass
`,
'goPastPreviousScope', mode, 'python'
));
test('Tricky syntax navigation: previous scope with IND to separating empty line ' + mode, testCase(
`
pass
^def foo(bar, baz):
bar()
baz()
pass
@
`,
'goPastPreviousScope', mode, 'python'
));
test('Tricky syntax navigation: previous scope with IND from and to separating empty line ' + mode, testCase(
`
pass
def foo(bar, baz):
bar()
baz^()
@
pass
`,
'goPastPreviousScope', mode, 'python'
));
test('Tricky syntax navigation: down scope with IND from indented line ' + mode, testCase(
`
for (let index = 0;
index < array.length;
index++)@ {
const element = array[index];
}^
`,
'goToDownScope', mode, 'typescript'
));
test('Tricky syntax navigation: previous scope with IND from indented line ' + mode, testCase(
`
for ^(let index = 0;
index < array.length;
index++)@ {
const element = array[index];
}
`,
'goPastPreviousScope', mode, 'typescript'
));
test('Tricky syntax navigation: previous scope with IND from indented line 2 ' + mode, testCase(
`
print^("Hello, ",
name)@
`,
'goPastPreviousScope', mode, 'typescript'
));
test('Tricky syntax navigation: next scope with IND from indented line ' + mode, testCase(
`
for (let index = 0;
index < array.length;
index++)@ {
const element = array[index];
}^
`,
'goPastNextScope', mode, 'typescript'
));
}
for (const mode of ['NON/RAW', 'IND/RAW']) {
test('Basic parentheses navigation: up to unmatched left ' + mode, testCase(
`^(@()`,
'goToUpScope', mode, 'typescript'
));
test('Basic parentheses navigation: down to unmatched right ' + mode, testCase(
`()@)^`,
'goToDownScope', mode, 'typescript'
));
test('Basic parentheses navigation: up to unmatched left 2 ' + mode, testCase(
`^(()@`,
'goToUpScope', mode, 'typescript'
));
test('Basic parentheses navigation: down to unmatched right 2 ' + mode, testCase(
`@())^`,
'goToDownScope', mode, 'typescript'
));
test('Basic parentheses navigation: begin to unmatched left ' + mode, testCase(
`(^()@`,
'goToBeginScope', mode, 'typescript'
));
test('Basic parentheses navigation: end to unmatched right ' + mode, testCase(
`@()^)`,
'goToEndScope', mode, 'typescript'
));
}
{
const mode = 'NON/RAW';
test('Bracket syntax navigation: NON-block begin scope other line unmatched ' + mode, testCase(
`
for (let index = 0; index < array.length; index++) {^
element = f(array[index],
g(index))@;
`,
'goToBeginScope', mode, 'typescript'
));
test('Bracket syntax navigation: NON-block end scope other line unmatched ' + mode, testCase(
`
for (let index = 0; index < array.length; index++)
element = @f(array[index],
g(index));
^}
`,
'goToEndScope', mode, 'typescript'
));
test('Bracket syntax navigation: NON-block up scope other line unmatched ' + mode, testCase(
`
for (let index = 0; index < array.length; index++) ^{
element = f(array[index],
g(index))@;
`,
'goToUpScope', mode, 'typescript'
));
test('Bracket syntax navigation: NON-block down scope other line unmatched ' + mode, testCase(
`
for (let index = 0; index < array.length; index++)
element = @f(array[index],
g(index));
}^
`,
'goToDownScope', mode, 'typescript'
));
// Multicharacter brackets.
test('Multicharacter brackets navigation: up from between parens ' + mode, testCase(
`(^(* @() *))`,
'goToUpScope', mode, 'pascal'
));
test('Multicharacter brackets navigation: down from between parens ' + mode, testCase(
`((* @() *)^)`,
'goToDownScope', mode, 'pascal'
));
test('Multicharacter brackets navigation: left no-change ' + mode, testCase(
`((* ^@() *))`,
'goPastPreviousScope', mode, 'pascal'
));
test('Multicharacter brackets navigation: right no-change ' + mode, testCase(
`((* ()@^ *))`,
'goPastNextScope', mode, 'pascal'
));
test('Multicharacter brackets navigation: left ' + mode, testCase(
`(^(* () *)@)`,
'goPastPreviousScope', mode, 'pascal'
));
test('Multicharacter brackets navigation: right ' + mode, testCase(
`(@(* () *)^)`,
'goPastNextScope', mode, 'pascal'
));
test('Multicharacter brackets navigation: beginning from between parens ' + mode, testCase(
`((* ^ ()@() *))`,
'goToBeginScope', mode, 'pascal'
));
test('Multicharacter brackets navigation: end from between parens ' + mode, testCase(
`((* ()@() ^ *))`,
'goToEndScope', mode, 'pascal'
));
test('Multicharacter brackets navigation: beginning no-change ' + mode, testCase(
`((* ^@() *))`,
'goToBeginScope', mode, 'pascal'
));
test('Multicharacter brackets navigation: end no-change ' + mode, testCase(
`((* ()@^ *))`,
'goToEndScope', mode, 'pascal'
));
test('Multicharacter brackets navigation: up from between parens 2 ' + mode, testCase(
`(^<p>@()</p>)`,
'goToUpScope', mode, 'html'
));
test('Multicharacter brackets navigation: down from between parens 2 ' + mode, testCase(
`(<p>@()</p>^)`,
'goToDownScope', mode, 'html'
));
test('Multicharacter brackets navigation: left no-change 2 ' + mode, testCase(
`(<p>^@()</p>)`,
'goPastPreviousScope', mode, 'html'
));
test('Multicharacter brackets navigation: right no-change 2 ' + mode, testCase(
`(<p>()@^</p>)`,
'goPastNextScope', mode, 'html'
));
test('Multicharacter brackets navigation: left 2 ' + mode, testCase(
`(^<p>()</p>@)`,
'goPastPreviousScope', mode, 'html'
));
test('Multicharacter brackets navigation: right 2 ' + mode, testCase(
`(@<p>()</p>^)`,
'goPastNextScope', mode, 'html'
));
test('Multicharacter brackets navigation: beginning from between parens 2 ' + mode, testCase(
`(<p>^ ()@()</p>)`,
'goToBeginScope', mode, 'html'
));
test('Multicharacter brackets navigation: end from between parens 2 ' + mode, testCase(
`(<p>()@() ^</p>)`,
'goToEndScope', mode, 'html'
));
test('Multicharacter brackets navigation: beginning no-change 2 ' + mode, testCase(
`(<p>^@()</p>)`,
'goToBeginScope', mode, 'html'
));
test('Multicharacter brackets navigation: end no-change 2 ' + mode, testCase(
`(<p>()@^</p>)`,
'goToEndScope', mode, 'html'
));
test('Multicharacter brackets navigation: up multiline ' + mode, testCase(
`^<p>
<p> </p>@
</p>`,
'goToUpScope', mode, 'html'
));
test('Multicharacter brackets navigation: down multiline ' + mode, testCase(
`<p>
@<p> </p>
</p>^`,
'goToDownScope', mode, 'html'
));
test('Multicharacter brackets navigation: left multiline ' + mode, testCase(
`<p>^<p>
</p>
@</p>`,
'goPastPreviousScope', mode, 'html'
));
test('Multicharacter brackets navigation: right multiline ' + mode, testCase(
`<p>
@<p>
</p>^</p>`,
'goPastNextScope', mode, 'html'
));
test('Multicharacter brackets navigation: beginning multiline ' + mode, testCase(
`<p>^
<p> </p>@<p> </p>
</p>`,
'goToBeginScope', mode, 'html'
));
test('Multicharacter brackets navigation: end multiline ' + mode, testCase(
`<p>
<p> </p>@<p> </p>
^</p>`,
'goToEndScope', mode, 'html'
));
test('Multicharacter brackets navigation: left multiline 2 ' + mode, testCase(
`^<p><p>
</p>
</p>@`,
'goPastPreviousScope', mode, 'html'
));
test('Multicharacter brackets navigation: right multiline 2 ' + mode, testCase(
`@<p>
<p>
</p></p>^`,
'goPastNextScope', mode, 'html'
));
// FIXME(11): bug.
test('Multicharacter brackets navigation: left multiline 3 ' + mode, testCase(
`^[
(* comment *)
]@`,
'goPastPreviousScope', mode, 'pascal'
));
test('Multicharacter brackets navigation: right multiline 3 ' + mode, testCase(
`@[
(* comment *)
]^`,
'goPastNextScope', mode, 'pascal'
));
test('Multicharacter brackets navigation: up multiline 2 ' + mode, testCase(
`^[
(* comment *)@
]`,
'goToUpScope', mode, 'pascal'
));
test('Multicharacter brackets navigation: down multiline 2 ' + mode, testCase(
`[
@(* comment *)
]^`,
'goToDownScope', mode, 'pascal'
));
}
{
const mode = 'IND/RAW';
test('Multicharacter brackets navigation: up multiline 3 ' + mode, testCase(
`(* comment *)
program Test;
^begin
Pass;
@(* comment *)
Pass;
end.
`,
'goToUpScope', mode, 'pascal'
));
test('Non-Multicharacter brackets navigation: baseline for up multiline 3 ' + mode, testCase(
`{ comment }
program Test;
^begin
Pass;
@{ comment }
Pass;
end.
`,
'goToUpScope', mode, 'pascal'
));
test('Tricky syntax navigation: either _next_ or down should find next scope ' + mode, testCase(
`
@for x in xs:
if x:
foo(x)
pass
^pass
`,
'goPastNextScope', mode, 'pascal'
));
test('Tricky syntax navigation: find next scope from inside indentation header ' + mode, testCase(
`
f@or x in xs:
if x:
foo(x)^
pass
pass
`,
'goPastNextScope', mode, 'pascal'
));
test('Tricky syntax navigation: either next or _down_ should find next scope ' + mode, testCase(
`
^@for x in xs:
if x:
foo(x)
pass
pass
`,
'goToDownScope', mode, 'pascal'
));
test('Tricky syntax navigation: either _next_ or down should find next scope 2 ' + mode, testCase(
`@for x in xs:
if x:
foo(x)
pass
^pass`,
'goPastNextScope', mode, 'pascal'
));
test('Corner case: respect indentation for going up scope ' + mode, testCase(
`
^if true:
pass
pass@
`,
'goToUpScope', mode, 'python'
));
test('Corner case: respect indentation for going up scope 2 ' + mode, testCase(
`
^if true:
pass
pass@`,
'goToUpScope', mode, 'python'
));
test('Corner case: respect indentation for going up scope 3 ' + mode, testCase(
`^if true:
pass
pass@`,
'goToUpScope', mode, 'python'
));
test('Corner case: respect indentation for finding end of scope ' + mode, testCase(
`
if true:
pass
@ pass^
`,
'goToEndScope', mode, 'python'
));
test('Corner case: respect indentation for finding end of scope 2 ' + mode, testCase(
`if true:
pass
@ pass^`,
'goToEndScope', mode, 'python'
));
test('Corner case: go to end scope from empty line ' + mode, testCase(
`
if true:
@
pass
pass^
end
`,
'goToEndScope', mode, 'python'
));
test('Tricky syntax navigation: either go to down scope or go past next scope should ' +
'find end of scope 1 ' + mode,
testCase(
`
procedure Foo(Param: boolean);^@ begin
pass;
pass;
end
`,
'goToDownScope', mode, 'pascal'
));
test('Tricky syntax navigation: either go to up scope or go past next scope should ' +
'find end of scope 2 ' + mode,
testCase(
`
procedure Foo(Param: boolean);@ begin
pass;
pass;
^end
`,
'goPastNextScope', mode, 'pascal'
));
}
for (const mode of ['NON/RAW', 'NON/JTB']) {
test('Bracket syntax navigation: begin scope other line ' + mode, testCase(
`
for (let index = 0; index < array.length; index++) {
element = f(^array[index],
g@(index));
}
`,
'goToBeginScope', mode, 'typescript'
));
test('Bracket syntax navigation: end scope other line ' + mode, testCase(
`
for (let index = 0; index < array.length; index++) {
element = f(arr@ay[index],
g(index)^);
}
`,
'goToEndScope', mode, 'typescript'
));
test('Bracket syntax navigation: previous scope other line ' + mode, testCase(
`
for (let index = 0; index < array.length; index++) {
element = f(array^[index],
g@(index));
}
`,
'goPastPreviousScope', mode, 'typescript'
));
test('Bracket syntax navigation: next scope other line ' + mode, testCase(
`
for (let index = 0; index < array.length; index++) {
element = f(array[index]@,
g(index)^, index);
}
`,
'goPastNextScope', mode, 'typescript'
));
}
for (const mode of ['IND/JTB', 'NON/JTB']) {
test('Bracket syntax navigation: previous scope other line with comments ' + mode, testCase(
`
for (let index = 0; index < array.length; index++) {
element = f(
array^[index], // (comment), (comment)
g@(index));
}
`,
'goPastPreviousScope', mode, 'typescript'
));
test('Bracket syntax navigation: next scope other line with comments ' + mode, testCase(
`
for (let index = 0; index < array.length; index++) {
element = f(
array[index]@, // (comment), (comment)
g(index)^, index);
}
`,
'goPastNextScope', mode, 'typescript'
));
// Note that the less-indented line is still part of the "far" indent scope.
test('Bracket syntax navigation: previous scope other line with comments 2 ' + mode, testCase(
`
for (let index = 0; index < array.length; index++) {
element = f(array^[index], // (comment), (comment)
g@(index));
}
`,
'goPastPreviousScope', mode, 'typescript'
));
test('Bracket syntax navigation: next scope other line with comments 2 ' + mode, testCase(
`
for (let index = 0; index < array.length; index++) {
element = f(array[index]@, // (comment), (comment)
g(index)^, index);
}
`,
'goPastNextScope', mode, 'typescript'
));
}
{
const mode = 'IND/NON';
test('Basic syntax navigation: up scope using IND ' + mode, testCase(
// The less-indented non-whitespace-starting-part line is like a big start delimiter for the scope.
`
for item in range:
^if condition:
pa@ss
elif condition:
pass
`,
'goToUpScope', mode, 'python'
));
test('Basic syntax navigation: down scope using IND ' + mode, testCase(
`
for item in range:
if condition:
pa@ss
^elif condition:
pass
`,
'goToDownScope', mode, 'python'
));
test('Basic syntax navigation: begin scope using IND ' + mode, testCase(
`
for item in range:
if condition:
^pa@ss
elif condition:
pass
`,
'goToBeginScope', mode, 'python'
));
test('Basic syntax navigation: begin scope using IND 2 ' + mode, testCase(
`
for item in range:
^if condition:
pass
@elif condition:
pass
`,
'goToBeginScope', mode, 'python'
));
test('Basic syntax navigation: begin scope using IND 3 ' + mode, testCase(
`
for item in range:
if condition:
^pass
pa@ss
elif condition:
pass
`,
'goToBeginScope', mode, 'python'
));
test('Basic syntax navigation: end scope using IND ' + mode, testCase(
`
for item in range:
if condition:
pa@ss^
elif condition:
pass
`,
'goToEndScope', mode, 'python'
));
test('Basic syntax navigation: end scope using IND 2 ' + mode, testCase(
`
for item in range:
if condition:
pa@ss
pass^