diff --git a/src/Api/VSCodeApi.ts b/src/Api/VSCodeApi.ts index 42636bf..233e949 100644 --- a/src/Api/VSCodeApi.ts +++ b/src/Api/VSCodeApi.ts @@ -153,4 +153,19 @@ export class VSCodeApi { return null; } + public ReadNextLineFromCurrent(): string { + const lineCount: number = this.GetLineCount(); + const curLine: number = this.GetActiveLine(); + + for (let i: number = curLine; i < lineCount - 1; i++) { + + // Skip empty line + const line: string = this.ReadLine(i + 1); + if (StringUtil.IsNullOrWhiteSpace(line)) continue; + + return line; + } + + return null; + } } diff --git a/src/Domain/Lang/DocommentDomainCSharp.ts b/src/Domain/Lang/DocommentDomainCSharp.ts index d9a1ec2..6142c1a 100644 --- a/src/Domain/Lang/DocommentDomainCSharp.ts +++ b/src/Domain/Lang/DocommentDomainCSharp.ts @@ -36,27 +36,16 @@ export class DocommentDomainCSharp extends DocommentDomain { // NG: Line is NOT /// (NG: ////) const activeLine: string = this._vsCodeApi.ReadLineAtCurrent(); if (activeLine == null) return false; - if (isSlashKey) { - const isDocComment: boolean = SyntacticAnalysisCSharp.IsDocCommentStrict(activeLine); - if (!isDocComment) return false; - - // NG: '/' => Insert => Event => ' /// ' - if (SyntacticAnalysisCSharp.IsDoubleDocComment(activeLine)) return false; - } - if (this._isEnterKey) { + if (isSlashKey || this._isEnterKey) { const isDocComment: boolean = SyntacticAnalysisCSharp.IsDocComment(activeLine); if (!isDocComment) return false; - } - // NG: Position is NOT /// - // const position: number = this._vsCodeApi.GetActiveCharPosition(); - // const positionDocComment: number = activeLine.lastIndexOf('///') + ((isEnterKey) ? 3 : 2); - // const isLastPosition: boolean = (position === positionDocComment); - // if (!isLastPosition) return false; + const previousLine: string = this._vsCodeApi.ReadPreviousLineFromCurrent(); + if (SyntacticAnalysisCSharp.IsDocComment(previousLine)) return false; - // NG: Previous line is XML document comment - // const previousLine: string = this._vsCodeApi.ReadPreviousLineFromCurrent(); - // if (SyntacticAnalysisCSharp.IsDocComment(previousLine)) return false; + const nextLine: string = this._vsCodeApi.ReadNextLineFromCurrent(); + if (SyntacticAnalysisCSharp.IsDocComment(nextLine)) return false; + } // OK return true; @@ -86,7 +75,7 @@ export class DocommentDomainCSharp extends DocommentDomain { /*------------------------------------------------------------------------- - * + * *-----------------------------------------------------------------------*/ const isInMethod = false; // fixme: if (isInMethod) return CodeType.None; diff --git a/src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts b/src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts index 27cccf4..8ca9b6c 100644 --- a/src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts +++ b/src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts @@ -17,16 +17,8 @@ export class SyntacticAnalysisCSharp { return (activeChar === '/'); } - public static IsDocCommentStrict(activeLine: string): boolean { - return activeLine.match(/(?:[^/]\/{3}[ \t]*$)|(?:^\/{3}[^/])|(?:^\/{3}[ \t]*$)/) !== null; // fixme: to simple - } - public static IsDocComment(activeLine: string): boolean { - return activeLine.match(/\/{3}/) !== null; - } - - public static IsDoubleDocComment(activeLine: string): boolean { - return activeLine.match(/^[ \t]+\/{3} $/) !== null; + return activeLine.match(/^\s*?\/{3}\s*$/) !== null; } /*------------------------------------------------------------------------- @@ -97,7 +89,7 @@ export class SyntacticAnalysisCSharp { let paramName: Array = new Array(); params[1].split(',').forEach(param => { const hasOptionaParam: boolean = param.match(/\S+\s+\S+\s*=/) !== null; - const name: RegExpMatchArray = (hasOptionaParam) + const name: RegExpMatchArray = (hasOptionaParam) ? param.match(/\S+\s+(\S+)\s*=.*/) : param.match(/(\S+)\s*$/); if (name !== null && name.length === 2) { diff --git a/test/SyntacticAnalysis/SyntacticAnalysisCSharp.test.ts b/test/SyntacticAnalysis/SyntacticAnalysisCSharp.test.ts index c7ff022..c9990ae 100644 --- a/test/SyntacticAnalysis/SyntacticAnalysisCSharp.test.ts +++ b/test/SyntacticAnalysis/SyntacticAnalysisCSharp.test.ts @@ -208,4 +208,24 @@ suite('SyntacticAnalysis.SyntacticAnalysisCSharp.IsClass Tests', () => { assert.equal(actual[1], 'onComplete'); }); + test(` + Category: Black-box testing + Class : SyntacticAnalysis.SyntacticAnalysisCSharp + Method : IsDocComment + `, () => { + assert.equal(SyntacticAnalysisCSharp.IsDocComment('///'), true, '///'); + assert.equal(SyntacticAnalysisCSharp.IsDocComment(' ///'), true, ' ///'); + assert.equal(SyntacticAnalysisCSharp.IsDocComment(' /// '), true, ' /// '); + + assert.equal(SyntacticAnalysisCSharp.IsDocComment('/// ///'), false, '/// ///'); + assert.equal(SyntacticAnalysisCSharp.IsDocComment(' /// ///'), false, ' /// ///'); + assert.equal(SyntacticAnalysisCSharp.IsDocComment('//////'), false, '//////'); + assert.equal(SyntacticAnalysisCSharp.IsDocComment(' //////'), false, ' //////'); + assert.equal(SyntacticAnalysisCSharp.IsDocComment(' /////'), false, ' /////'); + assert.equal(SyntacticAnalysisCSharp.IsDocComment(' /// //'), false, ' /// //'); + assert.equal(SyntacticAnalysisCSharp.IsDocComment(' //// ///'), false, ' //// ///'); + assert.equal(SyntacticAnalysisCSharp.IsDocComment(' /// '), false, "' /// '"); + }); + + });