Skip to content

Commit ea8d1b7

Browse files
committed
Change tests to assert active indent guides explicitly
1 parent 5835d42 commit ea8d1b7

File tree

1 file changed

+96
-126
lines changed

1 file changed

+96
-126
lines changed

src/vs/editor/test/common/model/textModelWithTokens.test.ts

Lines changed: 96 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -572,206 +572,176 @@ suite('TextModelWithTokens regression tests', () => {
572572
});
573573

574574
suite('TextModel.getLineIndentGuide', () => {
575-
function assertIndentGuides(lines: [number, string][]): void {
576-
let text = lines.map(l => l[1]).join('\n');
575+
function assertIndentGuides(lines: [number, number, number, number, string][]): void {
576+
let text = lines.map(l => l[4]).join('\n');
577577
let model = TextModel.createFromString(text);
578578

579579
let actualIndents = model.getLinesIndentGuides(1, model.getLineCount());
580580

581-
let actual: [number, string][] = [];
581+
let actual: [number, number, number, number, string][] = [];
582582
for (let line = 1; line <= model.getLineCount(); line++) {
583-
actual[line - 1] = [actualIndents[line - 1], model.getLineContent(line)];
583+
const activeIndentGuide = model.getActiveIndentGuide(line, 1, model.getLineCount());
584+
actual[line - 1] = [actualIndents[line - 1], activeIndentGuide.startLineNumber, activeIndentGuide.endLineNumber, activeIndentGuide.indent, model.getLineContent(line)];
584585
}
585586

586587
assert.deepEqual(actual, lines);
587588

588-
// Also test getActiveIndentGuide
589-
for (let lineNumber = 1; lineNumber <= model.getLineCount(); lineNumber++) {
590-
let startLineNumber = lineNumber;
591-
let endLineNumber = lineNumber;
592-
let indent = actualIndents[lineNumber - 1];
593-
594-
if (indent !== 0) {
595-
for (let i = lineNumber - 1; i >= 1; i--) {
596-
const currIndent = actualIndents[i - 1];
597-
if (currIndent >= indent) {
598-
startLineNumber = i;
599-
} else {
600-
break;
601-
}
602-
}
603-
for (let i = lineNumber + 1; i <= model.getLineCount(); i++) {
604-
const currIndent = actualIndents[i - 1];
605-
if (currIndent >= indent) {
606-
endLineNumber = i;
607-
} else {
608-
break;
609-
}
610-
}
611-
}
612-
613-
const expected = { startLineNumber, endLineNumber, indent };
614-
const actual = model.getActiveIndentGuide(lineNumber, 1, model.getLineCount());
615-
616-
assert.deepEqual(actual, expected, `line number ${lineNumber}`);
617-
}
618-
619589
model.dispose();
620590
}
621591

622592
test('getLineIndentGuide one level', () => {
623593
assertIndentGuides([
624-
[0, 'A'],
625-
[1, ' A'],
626-
[1, ' A'],
627-
[1, ' A'],
594+
[0, 1, 1, 0, 'A'],
595+
[1, 2, 4, 1, ' A'],
596+
[1, 2, 4, 1, ' A'],
597+
[1, 2, 4, 1, ' A'],
628598
]);
629599
});
630600

631601
test('getLineIndentGuide two levels', () => {
632602
assertIndentGuides([
633-
[0, 'A'],
634-
[1, ' A'],
635-
[1, ' A'],
636-
[1, ' A'],
637-
[1, ' A'],
603+
[0, 1, 1, 0, 'A'],
604+
[1, 2, 5, 1, ' A'],
605+
[1, 2, 5, 1, ' A'],
606+
[1, 2, 5, 1, ' A'],
607+
[1, 2, 5, 1, ' A'],
638608
]);
639609
});
640610

641611
test('getLineIndentGuide three levels', () => {
642612
assertIndentGuides([
643-
[0, 'A'],
644-
[1, ' A'],
645-
[1, ' A'],
646-
[2, ' A'],
647-
[0, 'A'],
613+
[0, 1, 1, 0, 'A'],
614+
[1, 2, 4, 1, ' A'],
615+
[1, 2, 4, 1, ' A'],
616+
[2, 4, 4, 2, ' A'],
617+
[0, 5, 5, 0, 'A'],
648618
]);
649619
});
650620

651621
test('getLineIndentGuide decreasing indent', () => {
652622
assertIndentGuides([
653-
[1, ' A'],
654-
[1, ' A'],
655-
[0, 'A'],
623+
[1, 1, 2, 1, ' A'],
624+
[1, 1, 2, 1, ' A'],
625+
[0, 3, 3, 0, 'A'],
656626
]);
657627
});
658628

659629
test('getLineIndentGuide Java', () => {
660630
assertIndentGuides([
661-
/* 1*/[0, 'class A {'],
662-
/* 2*/[1, ' void foo() {'],
663-
/* 3*/[1, ' console.log(1);'],
664-
/* 4*/[1, ' console.log(2);'],
665-
/* 5*/[1, ' }'],
666-
/* 6*/[1, ''],
667-
/* 7*/[1, ' void bar() {'],
668-
/* 8*/[1, ' console.log(3);'],
669-
/* 9*/[1, ' }'],
670-
/*10*/[0, '}'],
671-
/*11*/[0, 'interface B {'],
672-
/*12*/[1, ' void bar();'],
673-
/*13*/[0, '}'],
631+
/* 1*/[0, 1, 1, 0, 'class A {'],
632+
/* 2*/[1, 2, 9, 1, ' void foo() {'],
633+
/* 3*/[1, 2, 9, 1, ' console.log(1);'],
634+
/* 4*/[1, 2, 9, 1, ' console.log(2);'],
635+
/* 5*/[1, 2, 9, 1, ' }'],
636+
/* 6*/[1, 2, 9, 1, ''],
637+
/* 7*/[1, 2, 9, 1, ' void bar() {'],
638+
/* 8*/[1, 2, 9, 1, ' console.log(3);'],
639+
/* 9*/[1, 2, 9, 1, ' }'],
640+
/*10*/[0, 10, 10, 0, '}'],
641+
/*11*/[0, 11, 11, 0, 'interface B {'],
642+
/*12*/[1, 12, 12, 1, ' void bar();'],
643+
/*13*/[0, 13, 13, 0, '}'],
674644
]);
675645
});
676646

677647
test('getLineIndentGuide Javadoc', () => {
678648
assertIndentGuides([
679-
[0, '/**'],
680-
[1, ' * Comment'],
681-
[1, ' */'],
682-
[0, 'class A {'],
683-
[1, ' void foo() {'],
684-
[1, ' }'],
685-
[0, '}'],
649+
[0, 1, 1, 0, '/**'],
650+
[1, 2, 3, 1, ' * Comment'],
651+
[1, 2, 3, 1, ' */'],
652+
[0, 4, 4, 0, 'class A {'],
653+
[1, 5, 6, 1, ' void foo() {'],
654+
[1, 5, 6, 1, ' }'],
655+
[0, 7, 7, 0, '}'],
686656
]);
687657
});
688658

689659
test('getLineIndentGuide Whitespace', () => {
690660
assertIndentGuides([
691-
[0, 'class A {'],
692-
[1, ''],
693-
[1, ' void foo() {'],
694-
[1, ' '],
695-
[2, ' return 1;'],
696-
[1, ' }'],
697-
[1, ' '],
698-
[0, '}'],
661+
[0, 1, 1, 0, 'class A {'],
662+
[1, 2, 7, 1, ''],
663+
[1, 2, 7, 1, ' void foo() {'],
664+
[1, 2, 7, 1, ' '],
665+
[2, 5, 5, 2, ' return 1;'],
666+
[1, 2, 7, 1, ' }'],
667+
[1, 2, 7, 1, ' '],
668+
[0, 8, 8, 0, '}']
699669
]);
700670
});
701671

702672
test('getLineIndentGuide Tabs', () => {
703673
assertIndentGuides([
704-
[0, 'class A {'],
705-
[1, '\t\t'],
706-
[1, '\tvoid foo() {'],
707-
[2, '\t \t//hello'],
708-
[2, '\t return 2;'],
709-
[1, ' \t}'],
710-
[1, ' '],
711-
[0, '}'],
674+
[0, 1, 1, 0, 'class A {'],
675+
[1, 2, 7, 1, '\t\t'],
676+
[1, 2, 7, 1, '\tvoid foo() {'],
677+
[2, 4, 5, 2, '\t \t//hello'],
678+
[2, 4, 5, 2, '\t return 2;'],
679+
[1, 2, 7, 1, ' \t}'],
680+
[1, 2, 7, 1, ' '],
681+
[0, 8, 8, 0, '}']
712682
]);
713683
});
714684

715685
test('getLineIndentGuide checker.ts', () => {
716686
assertIndentGuides([
717-
/* 1*/[0, '/// <reference path="binder.ts"/>'],
718-
/* 2*/[0, ''],
719-
/* 3*/[0, '/* @internal */'],
720-
/* 4*/[0, 'namespace ts {'],
721-
/* 5*/[1, ' let nextSymbolId = 1;'],
722-
/* 6*/[1, ' let nextNodeId = 1;'],
723-
/* 7*/[1, ' let nextMergeId = 1;'],
724-
/* 8*/[1, ' let nextFlowId = 1;'],
725-
/* 9*/[1, ''],
726-
/*10*/[1, ' export function getNodeId(node: Node): number {'],
727-
/*11*/[2, ' if (!node.id) {'],
728-
/*12*/[3, ' node.id = nextNodeId;'],
729-
/*13*/[3, ' nextNodeId++;'],
730-
/*14*/[2, ' }'],
731-
/*15*/[2, ' return node.id;'],
732-
/*16*/[1, ' }'],
733-
/*17*/[0, '}'],
687+
/* 1*/[0, 1, 1, 0, '/// <reference path="binder.ts"/>'],
688+
/* 2*/[0, 2, 2, 0, ''],
689+
/* 3*/[0, 3, 3, 0, '/* @internal */'],
690+
/* 4*/[0, 4, 4, 0, 'namespace ts {'],
691+
/* 5*/[1, 5, 16, 1, ' let nextSymbolId = 1;'],
692+
/* 6*/[1, 5, 16, 1, ' let nextNodeId = 1;'],
693+
/* 7*/[1, 5, 16, 1, ' let nextMergeId = 1;'],
694+
/* 8*/[1, 5, 16, 1, ' let nextFlowId = 1;'],
695+
/* 9*/[1, 5, 16, 1, ''],
696+
/*10*/[1, 5, 16, 1, ' export function getNodeId(node: Node): number {'],
697+
/*11*/[2, 11, 15, 2, ' if (!node.id) {'],
698+
/*12*/[3, 12, 13, 3, ' node.id = nextNodeId;'],
699+
/*13*/[3, 12, 13, 3, ' nextNodeId++;'],
700+
/*14*/[2, 11, 15, 2, ' }'],
701+
/*15*/[2, 11, 15, 2, ' return node.id;'],
702+
/*16*/[1, 5, 16, 1, ' }'],
703+
/*17*/[0, 17, 17, 0, '}']
734704
]);
735705
});
736706

737707
test('issue #8425 - Missing indentation lines for first level indentation', () => {
738708
assertIndentGuides([
739-
[1, '\tindent1'],
740-
[2, '\t\tindent2'],
741-
[2, '\t\tindent2'],
742-
[1, '\tindent1'],
709+
[1, 1, 4, 1, '\tindent1'],
710+
[2, 2, 3, 2, '\t\tindent2'],
711+
[2, 2, 3, 2, '\t\tindent2'],
712+
[1, 1, 4, 1, '\tindent1']
743713
]);
744714
});
745715

746716
test('issue #8952 - Indentation guide lines going through text on .yml file', () => {
747717
assertIndentGuides([
748-
[0, 'properties:'],
749-
[1, ' emailAddress:'],
750-
[2, ' - bla'],
751-
[2, ' - length:'],
752-
[3, ' max: 255'],
753-
[0, 'getters:'],
718+
[0, 1, 1, 0, 'properties:'],
719+
[1, 2, 5, 1, ' emailAddress:'],
720+
[2, 3, 5, 2, ' - bla'],
721+
[2, 3, 5, 2, ' - length:'],
722+
[3, 5, 5, 3, ' max: 255'],
723+
[0, 6, 6, 0, 'getters:']
754724
]);
755725
});
756726

757727
test('issue #11892 - Indent guides look funny', () => {
758728
assertIndentGuides([
759-
[0, 'function test(base) {'],
760-
[1, '\tswitch (base) {'],
761-
[2, '\t\tcase 1:'],
762-
[3, '\t\t\treturn 1;'],
763-
[2, '\t\tcase 2:'],
764-
[3, '\t\t\treturn 2;'],
765-
[1, '\t}'],
766-
[0, '}'],
729+
[0, 1, 1, 0, 'function test(base) {'],
730+
[1, 2, 7, 1, '\tswitch (base) {'],
731+
[2, 3, 6, 2, '\t\tcase 1:'],
732+
[3, 4, 4, 3, '\t\t\treturn 1;'],
733+
[2, 3, 6, 2, '\t\tcase 2:'],
734+
[3, 6, 6, 3, '\t\t\treturn 2;'],
735+
[1, 2, 7, 1, '\t}'],
736+
[0, 8, 8, 0, '}']
767737
]);
768738
});
769739

770740
test('issue #12398 - Problem in indent guidelines', () => {
771741
assertIndentGuides([
772-
[2, '\t\t.bla'],
773-
[3, '\t\t\tlabel(for)'],
774-
[0, 'include script'],
742+
[2, 1, 2, 2, '\t\t.bla'],
743+
[3, 2, 2, 3, '\t\t\tlabel(for)'],
744+
[0, 3, 3, 0, 'include script']
775745
]);
776746
});
777747

0 commit comments

Comments
 (0)