diff --git a/.gitignore b/.gitignore index dcd8530..fb237b5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ out node_modules -*.vsix \ No newline at end of file +*.vsix +coverage +.vscode-test diff --git a/.travis.yml b/.travis.yml index 237649d..c5168f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,11 +12,10 @@ before_install: fi install: - - npm install mocha - npm install - npm run vscode:prepublish script: - npm test --silent - - npm run-script coverage + - npm run-script coverage_travis after_script: "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js" diff --git a/.vscode/tasks.json b/.vscode/tasks.json index d31b159..e703b23 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -8,23 +8,55 @@ // A task runner that calls a custom npm script that compiles the extension. { - "version": "0.1.0", + "version": "0.1.0", - // we want to run npm - "command": "npm", + // we want to run npm + "command": "npm", - // the command is a shell script - "isShellCommand": true, + // the command is a shell script + "isShellCommand": true, - // show the output window only if unrecognized errors occur. - "showOutput": "silent", + // show the output window only if unrecognized errors occur. + "showOutput": "always", - // we run the custom script "compile" as defined in package.json - "args": ["run", "compile", "--loglevel", "silent"], + "args": ["run"], + + "tasks": [ + { + "taskName": "npm" + }, + { + "taskName": "build", + "suppressTaskName": true, - // The tsc compiler is started in watching mode - "isWatching": true, + // we run the custom script "compile" as defined in package.json + "args": ["compile"], - // use the standard tsc in watch mode problem matcher to find compile problems in the output. - "problemMatcher": "$tsc-watch" + // The tsc compiler is started in watching mode + "isWatching": true, + + // use the standard tsc in watch mode problem matcher to find compile problems in the output. + "problemMatcher": "$tsc" + }, + { + "taskName": "watch", + "suppressTaskName": true, + + // we run the custom script "watch" as defined in package.json + "args": ["watch", "--loglevel", "silent"], + + // The tsc compiler is started in watching mode + "isWatching": true, + + // use the standard tsc in watch mode problem matcher to find compile problems in the output. + "problemMatcher": "$tsc-watch" + }, + { + "taskName": "test", + "suppressTaskName": true, + + // we run the custom script "coverage" as defined in package.json + "args": ["coverage"] + } + ] } \ No newline at end of file diff --git a/.vscodeignore b/.vscodeignore index 58979d6..1271126 100644 --- a/.vscodeignore +++ b/.vscodeignore @@ -10,3 +10,5 @@ vsc-extension-quickstart.md tslint.json misc/** .travis.yml +coverage/** +.vscode-test/** diff --git a/package.json b/package.json index 2d61c23..34e17ed 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "docomment", - "version": "0.0.1", + "version": "0.0.2", "publisher": "k--kato", "engines": { "vscode": "^0.10.6" @@ -32,6 +32,7 @@ "tslint": "^3.2.1", "istanbul": "^0.4.2", "coveralls": "^2.11.6", + "mocha": "^2.3.4", "mocha-lcov-reporter": "^1.0.0" }, "extensionDependencies": [ @@ -39,9 +40,11 @@ "isAMD": false, "scripts": { "vscode:prepublish": "node ./node_modules/vscode/bin/compile", - "compile": "node ./node_modules/vscode/bin/compile -watch -p ./", + "compile": "node ./node_modules/vscode/bin/compile -p ./", + "watch": "node ./node_modules/vscode/bin/compile -watch -p ./", "test": "node ./node_modules/vscode/bin/test", - "coverage": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- -R spec --ui tdd ./out/test/**/*.js" + "coverage_travis": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- -R spec --ui tdd ./out/test/**/*.js", + "coverage": "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec --ui tdd ./out/test/**/*.js" }, "icon": "images/docomment.png", "license": "MIT", diff --git a/src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts b/src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts index 7b225fe..c4f15b9 100644 --- a/src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts +++ b/src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts @@ -11,47 +11,58 @@ export class SyntacticAnalysisCSharp { * Public Method *-----------------------------------------------------------------------*/ public static IsNamespace(code: string): boolean { + if (code === null) return false; return code.match(/\bnamespace\b/) !== null; } public static IsClass(code: string): boolean { + if (code === null) return false; return code.match(/\bclass\b/) !== null; } public static IsInterface(code: string): boolean { + if (code === null) return false; return code.match(/\binterface\b/) !== null; } public static IsStruct(code: string): boolean { + if (code === null) return false; return code.match(/\bstruct\b/) !== null; } public static IsEnum(code: string): boolean { + if (code === null) return false; return code.match(/\benum\b/) !== null; } public static IsDelegate(code: string): boolean { + if (code === null) return false; return code.match(/\bdelegate\b/) !== null; } public static IsEvent(code: string): boolean { + if (code === null) return false; return code.match(/\bevent\b/) !== null; } public static IsProperty(code: string): boolean { + if (code === null) return false; return code.match(/[\w\S]+[^)]?\b\s*{/) !== null; } public static IsField(code: string): boolean { + if (code === null) return false; return code.match(/;[ \t]*$/) !== null; } public static IsMethod(code: string): boolean { + if (code === null) return false; return code.match(/[\w\S]\s+[\w\S]+\s*\(.*\)/) !== null; } public static GetMethodParamNameList(code: string): Array { + if (code === null) return null; const params: RegExpMatchArray = code.match(/[\w\S]\s+[\w\S]+\s*\((.*)\)/); const isMatched = (params === null || params.length !== 2); @@ -69,6 +80,7 @@ export class SyntacticAnalysisCSharp { } public static HasMethodReturn(code: string): boolean { + if (code === null) return false; const returns: RegExpMatchArray = code.match(/([\w\S]+)\s+[\w\S]+\s*\(.*\)/); const isMatched = (returns === null || returns.length !== 2); @@ -78,6 +90,7 @@ export class SyntacticAnalysisCSharp { } public static HasPropertyReturn(code: string): boolean { + if (code === null) return false; const returns: RegExpMatchArray = code.match(/([\w\S]+)\s+[\w\S]+\s*\{/); const isMatched = (returns === null || returns.length !== 2); diff --git a/test/Api/VSCodeApi.test.ts b/test/Api/VSCodeApi.test.ts new file mode 100644 index 0000000..083e653 --- /dev/null +++ b/test/Api/VSCodeApi.test.ts @@ -0,0 +1,3 @@ +suite('Api.VSCodeApi Tests', () => { + // NOP +}); diff --git a/test/Controller/DocommentController.test.ts b/test/Controller/DocommentController.test.ts new file mode 100644 index 0000000..c464a7a --- /dev/null +++ b/test/Controller/DocommentController.test.ts @@ -0,0 +1,3 @@ +suite('Controller.DocommentController Tests', () => { + // NOP +}); diff --git a/test/Controller/Lang/DocommentControllerCSharp.test.ts b/test/Controller/Lang/DocommentControllerCSharp.test.ts new file mode 100644 index 0000000..2c2f456 --- /dev/null +++ b/test/Controller/Lang/DocommentControllerCSharp.test.ts @@ -0,0 +1,3 @@ +suite('Controller.Lang.DocommentControllerCSharp Tests', () => { + // NOP +}); diff --git a/test/Domain/DocommentDomain.test.ts b/test/Domain/DocommentDomain.test.ts new file mode 100644 index 0000000..a7be02f --- /dev/null +++ b/test/Domain/DocommentDomain.test.ts @@ -0,0 +1,3 @@ +suite('Domain.DocommentDomain Tests', () => { + // NOP +}); diff --git a/test/Domain/Lang/DocommentDomainCSharp.test.ts b/test/Domain/Lang/DocommentDomainCSharp.test.ts new file mode 100644 index 0000000..6819ffd --- /dev/null +++ b/test/Domain/Lang/DocommentDomainCSharp.test.ts @@ -0,0 +1,3 @@ +suite('Domain.DocommentDomainCSharp Tests', () => { + // NOP +}); diff --git a/test/SyntacticAnalysis/SyntacticAnalysisCSharp.test.ts b/test/SyntacticAnalysis/SyntacticAnalysisCSharp.test.ts new file mode 100644 index 0000000..60d4947 --- /dev/null +++ b/test/SyntacticAnalysis/SyntacticAnalysisCSharp.test.ts @@ -0,0 +1,192 @@ +import * as assert from 'assert'; +import {SyntacticAnalysisCSharp} from '../../src/SyntacticAnalysis/SyntacticAnalysisCSharp'; + +suite('SyntacticAnalysis.SyntacticAnalysisCSharp.IsNamespace Tests', () => { + + test(` + Category: Black-box testing + Class : SyntacticAnalysis.SyntacticAnalysisCSharp + Method : IsNamespace + STATE : - + IN : null + OUT : false + `, () => { + // arrange + const code: string = null; + + // act + const actual: boolean = SyntacticAnalysisCSharp.IsNamespace(code); + + // assert + assert.equal(actual, false); + }); + + test(` + Category: Black-box testing + Class : SyntacticAnalysis.SyntacticAnalysisCSharp + Method : IsNamespace + STATE : - + IN : '' + OUT : false + `, () => { + // arrange + const code = ''; + + // act + const actual: boolean = SyntacticAnalysisCSharp.IsNamespace(code); + + // assert + assert.equal(actual, false); + }); + + test(` + Category: Black-box testing + Class : SyntacticAnalysis.SyntacticAnalysisCSharp + Method : IsNamespace + STATE : - + IN : 'namespacefoo' + OUT : false + `, () => { + // arrange + const code = 'namespacefoo'; + + // act + const actual: boolean = SyntacticAnalysisCSharp.IsNamespace(code); + + // assert + assert.equal(actual, false); + }); + + test(` + Category: Black-box testing + Class : SyntacticAnalysis.SyntacticAnalysisCSharp + Method : IsNamespace + STATE : - + IN : 'namespace' + OUT : true + `, () => { + // arrange + const code = 'namespace'; + + // act + const actual: boolean = SyntacticAnalysisCSharp.IsNamespace(code); + + // assert + assert.equal(actual, true); + }); + + test(` + Category: Black-box testing + Class : SyntacticAnalysis.SyntacticAnalysisCSharp + Method : IsNamespace + STATE : - + IN : ' namespace ' + OUT : true + `, () => { + // arrange + const code = ' namespace '; + + // act + const actual: boolean = SyntacticAnalysisCSharp.IsNamespace(code); + + // assert + assert.equal(actual, true); + }); + +}); + + + +suite('SyntacticAnalysis.SyntacticAnalysisCSharp.IsClass Tests', () => { + + test(` + Category: Black-box testing + Class : SyntacticAnalysis.SyntacticAnalysisCSharp + Method : IsClass + STATE : - + IN : null + OUT : false + `, () => { + // arrange + const code: string = null; + + // act + const actual: boolean = SyntacticAnalysisCSharp.IsClass(code); + + // assert + assert.equal(actual, false); + }); + + test(` + Category: Black-box testing + Class : SyntacticAnalysis.SyntacticAnalysisCSharp + Method : IsClass + STATE : - + IN : '' + OUT : false + `, () => { + // arrange + const code = ''; + + // act + const actual: boolean = SyntacticAnalysisCSharp.IsClass(code); + + // assert + assert.equal(actual, false); + }); + + test(` + Category: Black-box testing + Class : SyntacticAnalysis.SyntacticAnalysisCSharp + Method : IsClass + STATE : - + IN : 'namespacefoo' + OUT : false + `, () => { + // arrange + const code = 'namespacefoo'; + + // act + const actual: boolean = SyntacticAnalysisCSharp.IsClass(code); + + // assert + assert.equal(actual, false); + }); + + test(` + Category: Black-box testing + Class : SyntacticAnalysis.SyntacticAnalysisCSharp + Method : IsClass + STATE : - + IN : 'class' + OUT : true + `, () => { + // arrange + const code = 'class'; + + // act + const actual: boolean = SyntacticAnalysisCSharp.IsClass(code); + + // assert + assert.equal(actual, true); + }); + + test(` + Category: Black-box testing + Class : SyntacticAnalysis.SyntacticAnalysisCSharp + Method : IsNamespace + STATE : - + IN : ' class ' + OUT : true + `, () => { + // arrange + const code = ' class '; + + // act + const actual: boolean = SyntacticAnalysisCSharp.IsClass(code); + + // assert + assert.equal(actual, true); + }); + +});