Fixed newline handling

This commit is contained in:
Arthur Ozga
2015-08-03 15:09:49 -07:00
parent 8d07c6929a
commit 9d26b4eb41
5 changed files with 21 additions and 20 deletions

View File

@@ -1941,7 +1941,7 @@ module FourSlash {
}
}
public verifyDocCommentTemplate(expected: ts.TextInsertion) {
public verifyDocCommentTemplate(expected?: ts.TextInsertion) {
const name = "verifyDocCommentTemplate";
let actual = this.languageService.getDocCommentTemplateAtPosition(this.activeFile.fileName, this.currentCaretPosition);
@@ -1953,16 +1953,18 @@ module FourSlash {
this.raiseError(name + ' failed - expected no template but got {newText: \"' + actual.newText + '\" offsetInNewText: ' + actual.offsetInNewText + '}');
}
}
if (expected !== undefined && actual === undefined) {
this.raiseError(name + ' failed - expected the template {newText: \"' + actual.newText + '\" offsetInNewText: ' + actual.offsetInNewText + '} but got nothing instead');
}
else {
if (actual === undefined) {
this.raiseError(name + ' failed - expected the template {newText: \"' + actual.newText + '\" offsetInNewText: ' + actual.offsetInNewText + '} but got nothing instead');
}
if (actual.newText !== expected.newText) {
this.raiseError(name + ' failed - expected insertion:\n' + expected.newText + '\nactual insertion:\n' + actual.newText);
}
if (actual.newText !== expected.newText) {
this.raiseError(name + ' failed - expected insertion:\n' + expected.newText + '\nactual insertion:\n' + actual.newText);
}
if (actual.offsetInNewText !== expected.offsetInNewText) {
this.raiseError(name + ' failed - expected offsetInNewText: ' + expected.offsetInNewText + ',\nactual offsetInNewText:' + actual.offsetInNewText);
if (actual.offsetInNewText !== expected.offsetInNewText) {
this.raiseError(name + ' failed - expected offsetInNewText: ' + expected.offsetInNewText + ',\nactual offsetInNewText:' + actual.offsetInNewText);
}
}
}

View File

@@ -6838,7 +6838,7 @@ namespace ts {
let indentationStr = sourceFile.text.substr(lineStart, posLineAndChar.character).match(/\s*/).toString();
const newLine = host.getNewLine();
const newLine = host.getNewLine ? host.getNewLine() : "\r\n";
let docParams = parameters.map((p, index) =>
indentationStr + " * @param " + (p.name.kind === SyntaxKind.Identifier ? (<Identifier>p.name).text : "param" + index.toString()) + newLine);
@@ -6850,7 +6850,7 @@ namespace ts {
/* closing comment */ indentationStr + " */" +
/* newline if at decl start */ (tokenStart === position ? newLine + indentationStr : "");
let cursorOffset = /* "/**" */ 3 + /* newLine */ + newLine.length + indentationStr.length + /* " * " */ 3;
let cursorOffset = /* "/**" */ 3 + /* newLine */ newLine.length + indentationStr.length + /* " * " */ 3;
return {newText: result, offsetInNewText: cursorOffset };
}

View File

@@ -5,9 +5,9 @@
//// /*1*/
//// function foo(x: number, y: string): boolean {}
const noIndentScaffolding = "/**\n * \n * @param x\n * @param y\n */";
const oneIndentScaffolding = "/**\n * \n * @param x\n * @param y\n */";
const noIndentOffset = 7;
const noIndentScaffolding = "/**\r\n * \r\n * @param x\r\n * @param y\r\n */";
const oneIndentScaffolding = "/**\r\n * \r\n * @param x\r\n * @param y\r\n */";
const noIndentOffset = 8;
const oneIndentOffset = noIndentOffset + 4;
goTo.marker("0");

View File

@@ -5,10 +5,10 @@
//// /*1*/
//// /*2*/function foo() { }
const noIndentEmptyScaffolding = "/**\n * \n */";
const oneIndentEmptyScaffolding = "/**\n * \n */";
const twoIndentEmptyScaffolding = "/**\n * \n */\n ";
const noIndentOffset = 7;
const noIndentEmptyScaffolding = "/**\r\n * \r\n */";
const oneIndentEmptyScaffolding = "/**\r\n * \r\n */";
const twoIndentEmptyScaffolding = "/**\r\n * \r\n */\r\n ";
const noIndentOffset = 8;
const oneIndentOffset = noIndentOffset + 4;
const twoIndentOffset = oneIndentOffset + 4;

View File

@@ -378,9 +378,8 @@ module FourSlashInterface {
FourSlash.currentTestState.verifyNoMatchingBracePosition(bracePosition);
}
// Will fix in fourslash-referencing
public DocCommentTemplate(expectedText: string, expectedOffset: number, empty?: boolean) {
FourSlash.currentTestState.verifyDocCommentTemplate(empty ? undefined : { newText: expectedText, cursorOffset: expectedOffset });
FourSlash.currentTestState.verifyDocCommentTemplate(empty ? undefined : { newText: expectedText, offsetInNewText: expectedOffset });
}
public noDocCommentTemplate() {