Decrement line ends if they end with a carriage return. (#31220)

* Decrement line ends if they end with a carriage return.

* Changed handling of newlines and inlined regex operation.

* fixed misname of hintSpan

* added tests

* revert inline of regex match and use getLineEndOfPosition

* fixed lint error and changed a silly thing in tests
This commit is contained in:
Jesse Trinity
2019-07-25 21:29:12 -07:00
committed by GitHub
parent 772bee5e84
commit 599e36a068
2 changed files with 24 additions and 3 deletions
@@ -38,6 +38,18 @@ namespace ts {
verifyNewLines(content, { newLine: NewLineKind.LineFeed });
}
function verifyOutliningSpanNewLines(content: string, options: CompilerOptions) {
const ls = testLSWithFiles(options, [{
content,
fileOptions: {},
unitName: "input.ts"
}]);
const span = ls.getOutliningSpans("input.ts")[0];
const textAfterSpanCollapse = content.substring(span.textSpan.start + span.textSpan.length);
assert(textAfterSpanCollapse.match(options.newLine === NewLineKind.CarriageReturnLineFeed ? /\r\n/ : /[^\r]\n/), "expected to find appropriate newlines");
assert(!textAfterSpanCollapse.match(options.newLine === NewLineKind.CarriageReturnLineFeed ? /[^\r]\n/ : /\r\n/), "expected not to find inappropriate newlines");
}
it("should exist and respect provided compiler options", () => {
verifyBothNewLines(`
function foo() {
@@ -45,5 +57,15 @@ namespace ts {
}
`);
});
it("should respect CRLF line endings around outlining spans", () => {
verifyOutliningSpanNewLines("// comment not included\r\n// #region name\r\nlet x: string = \"x\";\r\n// #endregion name\r\n",
{ newLine: NewLineKind.CarriageReturnLineFeed });
});
it("should respect LF line endings around outlining spans", () => {
verifyOutliningSpanNewLines("// comment not included\n// #region name\nlet x: string = \"x\";\n// #endregion name\n\n",
{ newLine: NewLineKind.LineFeed });
});
});
}