forked from hyperledger-archives/composer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code coverage - partly fixes #1495 (hyperledger-archives#2320)
* updates so far Signed-off-by: Matthew B White <[email protected]> * updates Signed-off-by: Matthew B White <[email protected]> * more coverage Signed-off-by: Matthew B White <[email protected]> * fix typo Signed-off-by: Matthew B White <[email protected]>
Showing
16 changed files
with
1,393 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const chai = require('chai'); | ||
chai.should(); | ||
chai.use(require('chai-as-promised')); | ||
chai.use(require('chai-things')); | ||
const sinon = require('sinon'); | ||
|
||
|
||
describe('ClassUndertest', function () { | ||
|
||
let sandbox; | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.sandbox.create(); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe('#isPrimitiveType', function() { | ||
it('check isPrimitiveType', function() { | ||
|
||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const chai = require('chai'); | ||
const should = chai.should(); | ||
chai.use(require('chai-as-promised')); | ||
chai.use(require('chai-things')); | ||
const sinon = require('sinon'); | ||
|
||
const FileWriter = require('../../lib/codegen/filewriter'); | ||
|
||
const fs = require('fs'); | ||
const mkdirp = require('mkdirp'); | ||
const path = require('path'); | ||
const Writer = require('../../lib/codegen/writer'); | ||
|
||
describe('ClassUndertest', function () { | ||
|
||
let sandbox; | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.sandbox.create(); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe('#constructor', function () { | ||
it('main code path', function () { | ||
let syncStub = sandbox.stub(mkdirp, 'sync'); | ||
syncStub.returns(); | ||
|
||
let fileWriter = new FileWriter('dir'); | ||
should.exist(fileWriter); | ||
// sinon.assert.exists(fileWriter); | ||
sinon.assert.calledOnce(syncStub); | ||
sinon.assert.calledWith(syncStub, 'dir'); | ||
|
||
}); | ||
}); | ||
|
||
describe('#openFile', function () { | ||
it('main code path', function () { | ||
|
||
let fileWriter = new FileWriter('dir'); | ||
should.exist(fileWriter); | ||
fileWriter.openFile('filename'); | ||
fileWriter.fileName.should.equal('filename'); | ||
should.not.exist(fileWriter.relativeDir); | ||
}); | ||
}); | ||
|
||
describe('#openRelativeFile', function () { | ||
it('main code path', function () { | ||
let fileWriter = new FileWriter('dir'); | ||
should.exist(fileWriter); | ||
fileWriter.openRelativeFile('relativeDir', 'filename'); | ||
fileWriter.fileName.should.equal('filename'); | ||
fileWriter.relativeDir.should.equal('relativeDir'); | ||
}); | ||
}); | ||
|
||
describe('#writeLine', function () { | ||
it('file not opened error code path', function () { | ||
let stub = sandbox.stub(Writer, 'writeLine'); | ||
stub.returns(); | ||
let fileWriter = new FileWriter('dir'); | ||
should.exist(fileWriter); | ||
(() => { | ||
fileWriter.writeLine('tabs', 'text'); | ||
}).should.throws(/not been opened/); | ||
|
||
}); | ||
|
||
it('main code path', function () { | ||
let stub = sandbox.stub(Writer.prototype, 'writeLine'); | ||
stub.returns(); | ||
let fileWriter = new FileWriter('dir'); | ||
fileWriter.fileName='filename'; | ||
should.exist(fileWriter); | ||
|
||
fileWriter.writeLine('tabs', 'text'); | ||
|
||
sinon.assert.calledWith(stub,'tabs','text'); | ||
}); | ||
}); | ||
|
||
describe('#writeBeforeLine', function () { | ||
it('file not opened error code path', function () { | ||
let stub = sandbox.stub(Writer, 'writeBeforeLine'); | ||
stub.returns(); | ||
let fileWriter = new FileWriter('dir'); | ||
should.exist(fileWriter); | ||
(() => { | ||
fileWriter.writeBeforeLine('tabs', 'text'); | ||
}).should.throws(/not been opened/); | ||
}); | ||
|
||
it('main code path', function () { | ||
let stub = sandbox.stub(Writer.prototype, 'writeBeforeLine'); | ||
stub.returns(); | ||
let fileWriter = new FileWriter('dir'); | ||
fileWriter.fileName='filename'; | ||
should.exist(fileWriter); | ||
|
||
fileWriter.writeBeforeLine('tabs', 'text'); | ||
|
||
sinon.assert.calledWith(stub,'tabs','text'); | ||
}); | ||
}); | ||
|
||
describe('#closeFile', function () { | ||
it('file not opened error code path', function () { | ||
let fileWriter = new FileWriter('dir'); | ||
should.exist(fileWriter); | ||
(() => { | ||
fileWriter.closeFile(); | ||
}).should.throws(/No file open/); | ||
}); | ||
|
||
it('main code path', function () { | ||
let pathResolveStub = sandbox.stub(path, 'resolve'); | ||
pathResolveStub.returns('resolvedpath'); | ||
|
||
let pathdirnameStub = sandbox.stub(path, 'dirname'); | ||
pathdirnameStub.returns(); | ||
|
||
let fsWriteFileSyncStub = sandbox.stub(fs, 'writeFileSync'); | ||
fsWriteFileSyncStub.returns(); | ||
|
||
let syncStub = sandbox.stub(mkdirp, 'sync'); | ||
syncStub.returns(); | ||
|
||
let superClearBuffer = sandbox.stub(Writer.prototype, 'clearBuffer'); | ||
superClearBuffer.returns(); | ||
|
||
let superGetBuffer = sandbox.stub(Writer.prototype, 'getBuffer'); | ||
superGetBuffer.returns([0,1,2,3]); | ||
|
||
// --- | ||
let fileWriter = new FileWriter('dir'); | ||
should.exist(fileWriter); | ||
fileWriter.fileName='filename'; | ||
fileWriter.outputDirectory='outputDir'; | ||
|
||
fileWriter.closeFile(); | ||
|
||
sinon.assert.calledOnce(pathResolveStub); | ||
sinon.assert.calledWith(pathResolveStub,'outputDir','filename'); | ||
sinon.assert.calledOnce(pathdirnameStub); | ||
sinon.assert.calledWith(pathdirnameStub,'resolvedpath'); | ||
sinon.assert.calledOnce(fsWriteFileSyncStub); | ||
sinon.assert.calledWith(fsWriteFileSyncStub,'resolvedpath',[0,1,2,3]); | ||
sinon.assert.calledTwice(syncStub); | ||
sinon.assert.calledOnce(superClearBuffer); | ||
|
||
|
||
}); | ||
it('main code path - relativedir', function () { | ||
let pathResolveStub = sandbox.stub(path, 'resolve'); | ||
pathResolveStub.returns('resolvedpath'); | ||
|
||
let pathdirnameStub = sandbox.stub(path, 'dirname'); | ||
pathdirnameStub.returns(); | ||
|
||
let fsWriteFileSyncStub = sandbox.stub(fs, 'writeFileSync'); | ||
fsWriteFileSyncStub.returns(); | ||
|
||
let syncStub = sandbox.stub(mkdirp, 'sync'); | ||
syncStub.returns(); | ||
|
||
let superClearBuffer = sandbox.stub(Writer.prototype, 'clearBuffer'); | ||
superClearBuffer.returns(); | ||
|
||
let superGetBuffer = sandbox.stub(Writer.prototype, 'getBuffer'); | ||
superGetBuffer.returns([0,1,2,3]); | ||
|
||
// --- | ||
let fileWriter = new FileWriter('dir'); | ||
should.exist(fileWriter); | ||
fileWriter.fileName='filename'; | ||
fileWriter.outputDirectory='outputDir'; | ||
fileWriter.relativeDir = 'relativeDir'; | ||
|
||
fileWriter.closeFile(); | ||
|
||
sinon.assert.calledTwice(pathResolveStub); | ||
sinon.assert.calledWith(pathResolveStub,'outputDir','relativeDir'); | ||
sinon.assert.calledWith(pathResolveStub,'resolvedpath','filename'); | ||
sinon.assert.calledOnce(pathdirnameStub); | ||
sinon.assert.calledWith(pathdirnameStub,'resolvedpath'); | ||
sinon.assert.calledOnce(fsWriteFileSyncStub); | ||
sinon.assert.calledWith(fsWriteFileSyncStub,'resolvedpath',[0,1,2,3]); | ||
sinon.assert.calledTwice(syncStub); | ||
sinon.assert.calledOnce(superClearBuffer); | ||
|
||
|
||
}); | ||
}); | ||
}); |
109 changes: 109 additions & 0 deletions
109
packages/composer-common/test/codegen/fromjs/apisignaturegenerator.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const chai = require('chai'); | ||
chai.should(); | ||
chai.use(require('chai-as-promised')); | ||
chai.use(require('chai-things')); | ||
const sinon = require('sinon'); | ||
|
||
const fs = require('fs'); | ||
const APISignatureGenerator = require('../../../lib/codegen/fromjs/apisignaturegenerator'); | ||
const Writer = require('../../../lib/codegen/writer'); | ||
|
||
describe('APISignatureGenerator', function () { | ||
|
||
let sandbox; | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.sandbox.create(); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe('#generate', function() { | ||
it('Good path', function() { | ||
let apigen = new APISignatureGenerator(); | ||
|
||
let appendFileSync = sandbox.stub(fs, 'appendFileSync'); | ||
appendFileSync.returns; | ||
|
||
let writeLine = sandbox.stub(Writer.prototype,'writeLine'); | ||
writeLine.returns; | ||
|
||
let program = {outdir:'outdir'}; | ||
let file = 'not used'; | ||
let includes = []; | ||
let classes = [ | ||
{ | ||
methods:[ | ||
{name:'methodname1',visibility:'public',methodArgs:['string','int'],throws:'error'}, | ||
{name:'methodname2',visibility:'public',methodArgs:['string','int']} | ||
], | ||
name:'aclass' | ||
}, | ||
{ | ||
methods:[ | ||
{name:'methodname1',visibility:'public',methodArgs:['string','int'],throws:'error'}, | ||
{name:'methodname2',visibility:'public',methodArgs:['string','int']} | ||
], | ||
name:'asubclass', | ||
superClass :'aclass' | ||
} | ||
]; | ||
let functions = [ | ||
{ | ||
throws:'error', | ||
visibility:'private', | ||
methodArgs:['string','int'], | ||
name:'func1', | ||
returnType:'int' | ||
}, | ||
{ | ||
visibility:'private', | ||
methodArgs:['string','int'], | ||
name:'func2', | ||
returnType:'int' | ||
}]; | ||
apigen.generate(program,file,includes,classes,functions); | ||
sinon.assert.callCount(writeLine,10); | ||
|
||
|
||
}); | ||
|
||
it('nothing to do', function() { | ||
let apigen = new APISignatureGenerator(); | ||
|
||
let appendFileSync = sandbox.stub(fs, 'appendFileSync'); | ||
appendFileSync.returns; | ||
|
||
let writeLine = sandbox.stub(Writer,'writeLine'); | ||
writeLine.returns; | ||
|
||
let program = {outdir:'outdir'}; | ||
let file = 'not used'; | ||
let includes = []; | ||
let classes = []; | ||
let functions = []; | ||
apigen.generate(program,file,includes,classes,functions); | ||
sinon.assert.notCalled.appendFileSync; | ||
sinon.assert.notCalled.writeLine; | ||
}); | ||
}); | ||
|
||
}); |
144 changes: 144 additions & 0 deletions
144
packages/composer-common/test/codegen/fromjs/jsonsignaturegenerator.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const chai = require('chai'); | ||
chai.should(); | ||
chai.use(require('chai-as-promised')); | ||
chai.use(require('chai-things')); | ||
const sinon = require('sinon'); | ||
|
||
const fs = require('fs'); | ||
const JSONGenerator = require('../../../lib/codegen/fromjs/jsongenerator'); | ||
const path = require('path'); | ||
|
||
describe('JSONGenerator', function () { | ||
|
||
let sandbox; | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.sandbox.create(); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe('#generate', function() { | ||
it('Good path', function() { | ||
let apigen = new JSONGenerator(); | ||
|
||
let writeFileSync = sandbox.stub(fs, 'writeFileSync'); | ||
writeFileSync.returns; | ||
|
||
let pathResolve = sandbox.stub(path,'resolve'); | ||
pathResolve.returns(); | ||
|
||
let pathParse = sandbox.stub(path,'parse'); | ||
pathParse.returns({name:'filename'}); | ||
|
||
|
||
let program = {outdir:'outdir'}; | ||
let file = 'not used'; | ||
let includes = []; | ||
let classes = [ | ||
{ | ||
methods:[ | ||
{name:'methodname1',visibility:'public',methodArgs:['string','int'],throws:'error', | ||
commentData: {description:'a description', tags:[ | ||
|
||
]} | ||
}, | ||
{ | ||
name:'methodname2', | ||
visibility:'public', | ||
methodArgs:['string','int'], | ||
commentData: | ||
{ | ||
description:'a description', | ||
tags:[ | ||
{ | ||
|
||
title:'param', | ||
description:'superClass', | ||
type: | ||
{ name:'name', | ||
type:'OptionalType', | ||
expression: {name:'expressionnanme'} | ||
} | ||
}, | ||
{ | ||
|
||
title:'param', | ||
description:'superClass', | ||
type: | ||
{ name:'name', | ||
|
||
expression: {name:'expressionnanme'} | ||
} | ||
}, | ||
{ | ||
|
||
title:'return', | ||
description:'returns', | ||
type: | ||
{ name:'name', | ||
|
||
expression: {name:'expressionnanme'} | ||
} | ||
}, | ||
{ | ||
|
||
title:'whatever' | ||
}] | ||
} | ||
}], | ||
name:'aclass', | ||
commentData: {description:'a class description', tags:[ | ||
{title:'extends',name:'superClass'}, | ||
{title:'see',description:'[Registry]{@link module:composer-client.Registry}'}, | ||
{title:'memberof',description:'module'}, | ||
{title:'private'}, | ||
{title:'protected'}, | ||
{title:'whatever'} | ||
|
||
]} | ||
} | ||
]; | ||
let functions = []; | ||
apigen.generate(program,file,includes,classes,functions); | ||
sinon.assert.callCount(writeFileSync,1); | ||
|
||
|
||
}); | ||
|
||
it('nothing to do', function() { | ||
let apigen = new JSONGenerator(); | ||
|
||
let writeFileSync = sandbox.stub(fs, 'writeFileSync'); | ||
writeFileSync.returns; | ||
|
||
let program = {outdir:'outdir'}; | ||
let file = 'not used'; | ||
let includes = []; | ||
let classes = []; | ||
let functions = []; | ||
apigen.generate(program,file,includes,classes,functions); | ||
sinon.assert.notCalled.appendFileSync; | ||
sinon.assert.notCalled.writeLine; | ||
}); | ||
}); | ||
|
||
}); |
274 changes: 274 additions & 0 deletions
274
packages/composer-common/test/codegen/fromjs/platumlgenerator.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,274 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const chai = require('chai'); | ||
chai.should(); | ||
chai.use(require('chai-as-promised')); | ||
chai.use(require('chai-things')); | ||
const sinon = require('sinon'); | ||
|
||
const fs = require('fs'); | ||
const PlantUMLGenerator = require('../../../lib/codegen/fromjs/plantumlgenerator'); | ||
const path = require('path'); | ||
const FileWriter = require('../../../lib/codegen/filewriter'); | ||
const mkdirp = require('mkdirp'); | ||
|
||
describe('PlantUMLGenerator', function () { | ||
|
||
let sandbox; | ||
|
||
|
||
|
||
describe('#toUMLFilename', function() { | ||
it('good path',function() { | ||
let apigen = new PlantUMLGenerator(); | ||
let filename = apigen.toUMLFilename('inputDir','outputDir','inputDir/filename.js'); | ||
filename.should.equal('filename.uml'); | ||
}); | ||
|
||
it('missing extension',function() { | ||
let apigen = new PlantUMLGenerator(); | ||
let filename = apigen.toUMLFilename('inputDir','outputDir','inputDir/filename'); | ||
filename.should.equal(''); | ||
}); | ||
}); | ||
|
||
describe('#generate', function() { | ||
beforeEach(() => { | ||
sandbox = sinon.sandbox.create(); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
it('Good path', function() { | ||
sandbox.stub(mkdirp,'sync').returns; | ||
|
||
let fwOpenStub = sandbox.stub(FileWriter.prototype,'openFile'); | ||
fwOpenStub.returns; | ||
|
||
let fwWriteLine = sandbox.stub(FileWriter.prototype,'writeLine'); | ||
fwWriteLine.returns; | ||
|
||
let fwCloseFile = sandbox.stub(FileWriter.prototype,'closeFile'); | ||
fwCloseFile.returns; | ||
|
||
let fwWriteBeforeLine = sandbox.stub(FileWriter.prototype,'writeBeforeLine'); | ||
fwWriteBeforeLine.returns; | ||
|
||
let existsSync = sandbox.stub(fs, 'existsSync'); | ||
existsSync.returns(true); | ||
|
||
let pathResolve = sandbox.stub(path,'resolve'); | ||
pathResolve.returns(); | ||
|
||
let pathParse = sandbox.stub(path,'parse'); | ||
pathParse.returns({name:'filename'}); | ||
|
||
let stub = sandbox.stub(PlantUMLGenerator.prototype,'toUMLFilename'); | ||
stub.returns('nameoffile'); | ||
|
||
let apigen = new PlantUMLGenerator(); | ||
|
||
let program = {outdir:'outdir',indir:'indir',file:'file'}; | ||
let file = 'not used'; | ||
let includes = ['includeFile']; | ||
let classes = [ | ||
{ | ||
superClass : 'ASuperClass', | ||
methods:[ | ||
{name:'methodname1',visibility:'public',methodArgs:['string','int'],throws:'error', | ||
commentData: {description:'a description', tags:[ | ||
|
||
]} | ||
}, | ||
{ | ||
name:'methodname2', | ||
visibility:'public', | ||
methodArgs:['string','int'], | ||
commentData: | ||
{ | ||
description:'a description', | ||
tags:[ | ||
{ | ||
|
||
title:'param', | ||
description:'superClass', | ||
type: | ||
{ name:'name', | ||
type:'OptionalType', | ||
expression: {name:'expressionnanme'} | ||
} | ||
}, | ||
{ | ||
|
||
title:'param', | ||
description:'superClass', | ||
type: | ||
{ name:'name', | ||
|
||
expression: {name:'expressionnanme'} | ||
} | ||
}, | ||
{ | ||
|
||
title:'return', | ||
description:'returns', | ||
type: | ||
{ name:'name', | ||
|
||
expression: {name:'expressionnanme'} | ||
} | ||
}, | ||
{ | ||
|
||
title:'whatever' | ||
}] | ||
} | ||
}], | ||
name:'aclass', | ||
commentData: {description:'a class description', tags:[ | ||
{title:'extends',name:'superClass'}, | ||
{title:'see',description:'[Registry]{@link module:composer-client.Registry}'}, | ||
{title:'memberof',description:'module'}, | ||
{title:'private'}, | ||
{title:'protected'}, | ||
{title:'whatever'} | ||
|
||
]} | ||
} | ||
]; | ||
let functions = []; | ||
apigen.generate(program,file,includes,classes,functions); | ||
|
||
|
||
}); | ||
it('Else conditions for the list of functions', function() { | ||
sandbox.stub(mkdirp,'sync').returns; | ||
|
||
let fwOpenStub = sandbox.stub(FileWriter.prototype,'openFile'); | ||
fwOpenStub.returns; | ||
|
||
let fwWriteLine = sandbox.stub(FileWriter.prototype,'writeLine'); | ||
fwWriteLine.returns; | ||
|
||
let fwCloseFile = sandbox.stub(FileWriter.prototype,'closeFile'); | ||
fwCloseFile.returns; | ||
|
||
let fwWriteBeforeLine = sandbox.stub(FileWriter.prototype,'writeBeforeLine'); | ||
fwWriteBeforeLine.returns; | ||
|
||
let existsSync = sandbox.stub(fs, 'existsSync'); | ||
existsSync.returns(false); | ||
|
||
let pathResolve = sandbox.stub(path,'resolve'); | ||
pathResolve.returns(); | ||
|
||
let pathParse = sandbox.stub(path,'parse'); | ||
pathParse.returns({name:'filename'}); | ||
|
||
let stub = sandbox.stub(PlantUMLGenerator.prototype,'toUMLFilename'); | ||
stub.returns('nameoffile'); | ||
|
||
let apigen = new PlantUMLGenerator(); | ||
|
||
let program = {outdir:'outdir',indir:'indir',file:'file'}; | ||
let file = 'not used'; | ||
let includes = ['includeFile']; | ||
let classes = [ | ||
{ | ||
methods:[ | ||
{name:'methodname1',visibility:'public',methodArgs:['string','int'],throws:'error', | ||
commentData: {description:'a description', tags:[ | ||
|
||
]} | ||
}, | ||
{ | ||
name:'methodname2', | ||
visibility:'public', | ||
methodArgs:['string','int'], | ||
commentData: | ||
{ | ||
description:'a description', | ||
tags:[ | ||
{ | ||
|
||
title:'param', | ||
description:'superClass', | ||
type: | ||
{ name:'name', | ||
type:'OptionalType', | ||
expression: {name:'expressionnanme'} | ||
} | ||
}, | ||
{ | ||
|
||
title:'param', | ||
description:'superClass', | ||
type: | ||
{ name:'name', | ||
|
||
expression: {name:'expressionnanme'} | ||
} | ||
}, | ||
{ | ||
|
||
title:'return', | ||
description:'returns', | ||
type: | ||
{ name:'name', | ||
|
||
expression: {name:'expressionnanme'} | ||
} | ||
}, | ||
{ | ||
|
||
title:'whatever' | ||
}] | ||
} | ||
}], | ||
name:'aclass', | ||
commentData: {description:'a class description', tags:[ | ||
{title:'extends',name:'superClass'}, | ||
{title:'see',description:'[Registry]{@link module:composer-client.Registry}'}, | ||
{title:'memberof',description:'module'}, | ||
{title:'private'}, | ||
{title:'protected'}, | ||
{title:'whatever'} | ||
|
||
]} | ||
} | ||
]; | ||
let functions = []; | ||
apigen.generate(program,file,includes,classes,functions); | ||
|
||
|
||
}); | ||
|
||
it('No input',function() { | ||
let apigen = new PlantUMLGenerator(); | ||
|
||
let program = {outdir:'outdir',indir:'indir',file:'file'}; | ||
let file = 'not used'; | ||
let includes = ['includeFile']; | ||
let classes = []; | ||
let functions= []; | ||
apigen.generate(program,file,includes,classes,functions); | ||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
346 changes: 344 additions & 2 deletions
346
packages/composer-common/test/codegen/javascriptparser.js
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const chai = require('chai'); | ||
chai.should(); | ||
chai.use(require('chai-as-promised')); | ||
chai.use(require('chai-things')); | ||
const sinon = require('sinon'); | ||
|
||
|
||
describe('parsejs', function () { | ||
|
||
let sandbox; | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.sandbox.create(); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe('#maintest', function() { | ||
it('main path', function() { | ||
// require('../../lib/codegen/parsejs.js'); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const chai = require('chai'); | ||
const should = chai.should(); | ||
chai.use(require('chai-as-promised')); | ||
chai.use(require('chai-things')); | ||
const sinon = require('sinon'); | ||
const Writer = require('../../lib/codegen/writer'); | ||
|
||
describe('Writer', function () { | ||
|
||
let sandbox; | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.sandbox.create(); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe('#constructor', function() { | ||
it('main path', function() { | ||
let writer = new Writer(); | ||
should.exist(writer); | ||
writer.clearBuffer(); | ||
|
||
}); | ||
}); | ||
|
||
describe('#writeBeforeLine', function() { | ||
it('main path', function() { | ||
let writer = new Writer(); | ||
should.exist(writer); | ||
writer.writeBeforeLine(1,'Hello World'); | ||
writer.beforeBuffer.should.equal(' Hello World\n'); | ||
writer.linesWritten.should.equal(1); | ||
writer.getLineCount().should.equal(1); | ||
}); | ||
}); | ||
|
||
|
||
describe('#writeLine', function() { | ||
it('main path', function() { | ||
let writer = new Writer(); | ||
should.exist(writer); | ||
writer.writeLine(1,'Hello World'); | ||
writer.buffer.should.equal(' Hello World\n'); | ||
writer.linesWritten.should.equal(5); | ||
writer.getBuffer().should.equal(' Hello World\n'); | ||
}); | ||
}); | ||
describe('#writeIndented', function() { | ||
it('main path', function() { | ||
let writer = new Writer(); | ||
should.exist(writer); | ||
writer.writeIndented(1,'Hello World'); | ||
|
||
writer.linesWritten.should.equal(2); | ||
writer.getBuffer().should.equal(' Hello World'); | ||
}); | ||
}); | ||
|
||
describe('#write', ()=>{ | ||
it('writes a line that is not a string', ()=>{ | ||
(()=>{ | ||
let writer = new Writer(); | ||
should.exist(writer); | ||
writer.write(false); | ||
}).should.throws(/Can only append strings/); | ||
|
||
}); | ||
|
||
}); | ||
}); |