Skip to content

Commit 323eceb

Browse files
Add todo comment tests.
1 parent 751ac31 commit 323eceb

19 files changed

+99
-0
lines changed

src/harness/fourslash.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,25 @@ module FourSlash {
14101410
}
14111411
}
14121412

1413+
public verifyTodoComments(descriptors: string[], spans: TextSpan[]) {
1414+
var actual = this.languageService.getTodoComments(this.activeFile.fileName,
1415+
descriptors.map(d => new ts.TodoCommentDescriptor(d, 0)));
1416+
1417+
if (actual.length !== spans.length) {
1418+
throw new Error('verifyTodoComments failed - expected total spans to be ' + spans.length + ', but was ' + actual.length);
1419+
}
1420+
1421+
for (var i = 0; i < spans.length; i++) {
1422+
var expectedSpan = spans[i];
1423+
var actualComment = actual[i];
1424+
var actualCommentSpan = new TypeScript.TextSpan(actualComment.position, actualComment.message.length);
1425+
1426+
if (expectedSpan.start !== actualCommentSpan.start() || expectedSpan.end !== actualCommentSpan.end()) {
1427+
throw new Error('verifyOutliningSpans failed - span ' + (i + 1) + ' expected: (' + expectedSpan.start + ',' + expectedSpan.end + '), actual: (' + actualCommentSpan.start() + ',' + actualCommentSpan.end() + ')');
1428+
}
1429+
}
1430+
}
1431+
14131432
public verifyMatchingBracePosition(bracePosition: number, expectedMatchPosition: number) {
14141433
this.taoInvalidReason = 'verifyMatchingBracePosition NYI';
14151434

tests/cases/fourslash/fourslash.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ module FourSlashInterface {
315315
FourSlash.currentTestState.verifyTodoComments(descriptors, test.ranges());
316316
}
317317

318+
public todoCommentsInCurrentFile(descriptors: string[]) {
319+
FourSlash.currentTestState.verifyTodoComments(descriptors, test.ranges());
320+
}
321+
318322
public matchingBracePositionInCurrentFile(bracePosition: number, expectedMatchPosition: number) {
319323
FourSlash.currentTestState.verifyMatchingBracePosition(bracePosition, expectedMatchPosition);
320324
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//// // [|TODO|]
2+
debugger;
3+
verify.todoCommentsInCurrentFile(["TODO"]);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// /*
2+
//// [|todo 1|]
3+
//// [|hack 2|]
4+
//// */
5+
debugger;
6+
verify.todoCommentsInCurrentFile(["TODO", "HACK"]);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// /*
2+
//// [|TODO(jason) 1|]
3+
//// [|HACK 2|]
4+
//// */
5+
debugger;
6+
verify.todoCommentsInCurrentFile(["TODO(jason)", "HACK"]);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// /*
2+
//// [|TODO(jason) 1|]
3+
//// [|HACK 2|]
4+
//// */
5+
debugger;
6+
verify.todoCommentsInCurrentFile(["HACK", "TODO(jason)"]);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//// TODO
2+
3+
debugger;
4+
verify.todoCommentsInCurrentFile(["TODO"]);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//// BAR // [|TODO|]
2+
debugger;
3+
verify.todoCommentsInCurrentFile(["TODO"]);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//// "// HACK 1";
2+
debugger;
3+
verify.todoCommentsInCurrentFile(["TODO(jason)", "HACK"]);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//// //// [|HACK 1|]
2+
debugger;
3+
verify.todoCommentsInCurrentFile(["TODO(jason)", "HACK"]);

0 commit comments

Comments
 (0)