Added tests, and perhaps fixed a test runner bug?

This commit is contained in:
Josh Goldberg
2020-04-28 20:56:15 -04:00
parent 956ac2132a
commit 12749c9291
2 changed files with 37 additions and 8 deletions
+12 -2
View File
@@ -1740,7 +1740,12 @@ namespace ts {
pos++;
}
commentDirectives = appendIfCommentDirective(commentDirectives, text.slice(tokenPos, pos), commentDirectiveRegExSingleLine);
commentDirectives = appendIfCommentDirective(
commentDirectives,
text.slice(tokenPos, pos),
commentDirectiveRegExSingleLine,
tokenPos,
);
if (skipTrivia) {
continue;
@@ -2119,7 +2124,12 @@ namespace ts {
return token;
}
function appendIfCommentDirective(commentDirectives: CommentDirective[] | undefined, text: string, commentDirectiveRegEx: RegExp, lineStart = tokenPos) {
function appendIfCommentDirective(
commentDirectives: CommentDirective[] | undefined,
text: string,
commentDirectiveRegEx: RegExp,
lineStart: number,
) {
const type = getDirectiveFromComment(text, commentDirectiveRegEx);
if (type === undefined) {
return commentDirectives;
+25 -6
View File
@@ -833,7 +833,7 @@ module m3 { }\
});
describe("comment directives", () => {
const tsIgnoreComment = "// @ts-ignore";
const tsIgnoreComment = "@ts-ignore";
const textWithIgnoreComment = `const x = 10;
function foo() {
// @ts-ignore
@@ -845,14 +845,27 @@ function bar() {
let z : string = x;
return z;
}
function bar3() {
function bar2() {
// @ts-ignore
let z : string = x;
return z;
}
function bar3() {
/* @ts-ignore */
let z : string = x;
return z;
}
function bar4() {
/*
@ts-ignore */
let z : string = x;
return z;
}
foo();
bar();
bar3();`;
bar3();
bar4();
bar5()`;
verifyScenario("when deleting ts-ignore comment", verifyDelete);
verifyScenario("when inserting ts-ignore comment", verifyInsert);
verifyScenario("when changing ts-ignore comment to blah", verifyChangeToBlah);
@@ -876,17 +889,23 @@ bar3();`;
it(`${scenario} - 2`, () => {
verifyChange(2);
});
it(`${scenario} - 3`, () => {
verifyChange(3);
});
it(`${scenario} - 4`, () => {
verifyChange(4);
});
it(`${scenario} - with single ts-ignore`, () => {
verifyChange(0, /*singleIgnore*/ true);
});
}
function getIndexOfTsIgnoreComment(atIndex: number) {
let index: number;
let index = 0;
for (let i = 0; i <= atIndex; i++) {
index = textWithIgnoreComment.indexOf(tsIgnoreComment);
index = textWithIgnoreComment.indexOf(tsIgnoreComment, index);
}
return index!;
return index;
}
function textWithIgnoreCommentFrom(text: string, singleIgnore: true | undefined) {