adding unit tests fot block comments outlining

This commit is contained in:
Ahmad Farid
2015-04-03 19:21:27 -07:00
parent 854d5496b4
commit 7fcbb8c9a0
3 changed files with 114 additions and 10 deletions

View File

@@ -549,7 +549,7 @@ module ts {
result = [];
}
result.push({ pos: startPos, end: pos, hasTrailingNewLine: hasTrailingNewLine, kind: kind });
result.push({ pos: startPos, end: pos, hasTrailingNewLine, kind });
}
continue;
}

View File

@@ -37,8 +37,7 @@ module ts {
let isFirstSingleLineComment = true;
let singleLineCommentCount = 0;
for (let i = 0; i < comments.length; i++) {
let currentComment = comments[i];
for (let currentComment of comments) {
// For single line comments, combine consecutive ones (2 or more) into
// a single span from the start of the first till the end of the last
@@ -50,9 +49,9 @@ module ts {
lastSingleLineCommentEnd = currentComment.end;
singleLineCommentCount++;
}
else {
else if (currentComment.kind === SyntaxKind.MultiLineCommentTrivia) {
combineAndAddMultipleSingleLineComments(singleLineCommentCount, firstSingleLineCommentStart, lastSingleLineCommentEnd);
addOutliningSpanComments(currentComment, false);
addOutliningSpanComments(currentComment, /*autoCollapse*/ false);
singleLineCommentCount = 0;
lastSingleLineCommentEnd = -1;
@@ -64,18 +63,16 @@ module ts {
}
}
function combineAndAddMultipleSingleLineComments(count: number, start: number, end: number) {
function combineAndAddMultipleSingleLineComments(count: number, start: number, end: number) {
// Only outline spans of two or more consecutive single line comments
if (count > 1) {
let multipleSingleLineComments = {
pos: start,
end: end,
kind: SyntaxKind.SingleLineCommentTrivia
}
addOutliningSpanComments(multipleSingleLineComments, false);
addOutliningSpanComments(multipleSingleLineComments, /*autoCollapse*/ false);
}
}
@@ -90,7 +87,10 @@ module ts {
return;
}
addOutliningForLeadingCommentsForNode(n);
if (isDeclaration(n)) {
addOutliningForLeadingCommentsForNode(n);
}
switch (n.kind) {
case SyntaxKind.Block:
if (!isFunctionBlock(n)) {

View File

@@ -0,0 +1,104 @@
/// <reference path="fourslash.ts"/>
////[|/*
//// Comment before module:
//// line one of the comment
//// line two of the comment
//// line three
//// line four
//// line five
////*/|]
////module Sayings [|{
//// [|/*
//// Comment before class:
//// line one of the comment
//// line two of the comment
//// line three
//// line four
//// line five
//// */|]
//// export class Greeter [|{
//// [|/*
//// Comment before a string identifier
//// line two of the comment
//// */|]
//// greeting: string;
//// [|/*
//// constructor
//// parameter message as a string
//// */|]
//// /* This is a single line block comment style. Should not be collapsed*/
//// [|/*
//// Multiple comments should be collapsed individually
//// */|]
//// constructor(message: string /* do not collapse single lines*/) [|{
//// this.greeting = message;
//// }|]
//// [|/*
//// method of a class
//// */|]
//// greet() [|{
//// return "Hello, " + this.greeting;
//// }|]
//// }|]
////}|]
////
////[|/*
//// Block comment for interface. The ending can be on the same line as the declaration.
////*/|]interface IFoo [|{
//// [|/*
//// Multiple block comments
//// */|]
////
//// [|/*
//// should be collapsed
//// */|]
////
//// [|/*
//// individually
//// */|]
////
//// [|/*
//// this comment has trailing space before /* and after *-/ signs
//// */|]
////
//// [|/**
//// *
//// *
//// *
//// */|]
////
//// [|/*
//// */|]
////
//// [|/*
//// */|]
//// // single line comments in the middle should not have an effect
//// [|/*
//// */|]
////
//// [|/*
//// */|]
////
//// [|/*
//// this block comment ends
//// on the same line */|] [|/* where the following comment starts
//// should be collapsed separately
//// */|]
////
//// getDist(): number;
////}|]
////
////var x =[|{
//// a:1,
//// b: 2,
//// [|/*
//// Over a function in an object literal
//// */|]
//// get foo() [|{
//// return 1;
//// }|]
////}|]
verify.outliningSpansInCurrentFile(test.ranges());