-
-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: jonathan.casey <jonathan.casey@docusign.com>
- Loading branch information
1 parent
a9b483e
commit 853837a
Showing
5 changed files
with
225 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* 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 Writer = require('./writer'); | ||
|
||
/** | ||
* InMemoryWriter stores string representation of files in a map structure. | ||
* The Map key is the filename, and the value are its string contents. | ||
* | ||
* @private | ||
* @extends Writer | ||
* @see See {@link Writer} | ||
* @class | ||
* @memberof module:concerto-core | ||
*/ | ||
class InMemoryWriter extends Writer { | ||
|
||
/** | ||
* Create a FileWriter. | ||
* | ||
*/ | ||
constructor() { | ||
super(); | ||
this.fileName = ''; | ||
this.data = new Map(); | ||
} | ||
|
||
/** | ||
* Creates the filename which will be used for association with its string content. | ||
* | ||
* @param {string} fileName - the name of the file. | ||
*/ | ||
openFile(fileName) { | ||
this.fileName = fileName; | ||
} | ||
|
||
/** | ||
* Writes the contents of the buffer to the Map store. | ||
*/ | ||
closeFile() { | ||
this.data.set(this.fileName, this.getBuffer()); | ||
this.clearBuffer(); | ||
} | ||
|
||
/** | ||
* Returns the content of the Map store. | ||
* | ||
* @return {Map} - a Map containing the string representation of files. (k,v) => (filename, file content). | ||
*/ | ||
getFilesInMemory() { | ||
return this.data; | ||
} | ||
} | ||
module.exports = InMemoryWriter; |
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,121 @@ | ||
/* | ||
* 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/writer'); | ||
const InMemoryWriter = require('../lib/inmemorywriter'); | ||
|
||
describe('InMemoryWriter', function() { | ||
|
||
let sandbox; | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.createSandbox(); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe('#constructor', function() { | ||
it('main code path', function() { | ||
let imw = new InMemoryWriter(); | ||
should.exist(imw); | ||
}); | ||
}); | ||
|
||
describe('#openFile', function() { | ||
it('main code path', function() { | ||
let imw = new InMemoryWriter(); | ||
should.exist(imw); | ||
imw.openFile('filename'); | ||
imw.fileName.should.equal('filename'); | ||
}); | ||
}); | ||
|
||
describe('#writeLine', function() { | ||
it('main code path', function() { | ||
let stub = sandbox.stub(Writer.prototype, 'writeLine'); | ||
stub.returns(); | ||
let imw = new InMemoryWriter(); | ||
imw.fileName = 'filename'; | ||
should.exist(imw); | ||
|
||
imw.writeLine('tabs', 'text'); | ||
|
||
sinon.assert.calledWith(stub, 'tabs', 'text'); | ||
}); | ||
}); | ||
|
||
describe('#writeBeforeLine', function() { | ||
it('main code path', function() { | ||
let stub = sandbox.stub(Writer.prototype, 'writeBeforeLine'); | ||
stub.returns(); | ||
let imw = new InMemoryWriter(); | ||
imw.fileName = 'filename'; | ||
should.exist(imw); | ||
|
||
imw.writeBeforeLine('tabs', 'text'); | ||
|
||
sinon.assert.calledWith(stub, 'tabs', 'text'); | ||
}); | ||
}); | ||
|
||
describe('#closeFile', function() { | ||
it('main code path', function() { | ||
let superClearBuffer = sandbox.stub(Writer.prototype, 'clearBuffer'); | ||
superClearBuffer.returns(); | ||
|
||
let superGetBuffer = sandbox.stub(Writer.prototype, 'getBuffer'); | ||
superGetBuffer.returns([0, 1, 2, 3]); | ||
|
||
let imw = new InMemoryWriter(); | ||
should.exist(imw); | ||
imw.fileName = 'filename'; | ||
|
||
imw.closeFile(); | ||
|
||
sinon.assert.calledOnce(superClearBuffer); | ||
}); | ||
}); | ||
|
||
describe('#getFilesInMemory', function() { | ||
it('main code path', function() { | ||
let superClearBuffer = sandbox.stub(Writer.prototype, 'clearBuffer'); | ||
superClearBuffer.returns(); | ||
|
||
let superGetBuffer = sandbox.stub(Writer.prototype, 'getBuffer'); | ||
superGetBuffer.returns('lorem ipsum'); | ||
|
||
let imw = new InMemoryWriter(); | ||
should.exist(imw); | ||
|
||
imw.fileName = 'filename.txt'; | ||
imw.writeLine('', 'lorem ipsum'); | ||
imw.closeFile(); | ||
|
||
imw.data.size.should.equal(1); | ||
imw.getFilesInMemory().get('filename.txt').should.equal('lorem ipsum'); | ||
|
||
sinon.assert.calledOnce(superClearBuffer); | ||
}); | ||
}); | ||
}); |
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,32 @@ | ||
export = InMemoryWriter; | ||
/** | ||
* InMemoryWriter stores string representation of files in a map structure. | ||
* The Map key is the filename, and the value are its string contents. | ||
* | ||
* @private | ||
* @extends Writer | ||
* @see See {@link Writer} | ||
* @class | ||
* @memberof module:concerto-core | ||
*/ | ||
declare class InMemoryWriter extends Writer { | ||
fileName: string; | ||
data: Map<any, any>; | ||
/** | ||
* Creates the filename which will be used for association with its string content. | ||
* | ||
* @param {string} fileName - the name of the file. | ||
*/ | ||
openFile(fileName: string): void; | ||
/** | ||
* Writes the contents of the buffer to the Map store. | ||
*/ | ||
closeFile(): void; | ||
/** | ||
* Returns the content of the Map store. | ||
* | ||
* @return {Map} - a Map containing the string representation of files. (k,v) => (filename, file content). | ||
*/ | ||
getFilesInMemory(): Map<any, any>; | ||
} | ||
import Writer = require("./writer"); |