-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(intersection_syntactic_variations): add remaining test for post-…
…processing feature. pass document pointer to script as first arg instead of being bound to $this
- Loading branch information
1 parent
e63c833
commit b92c404
Showing
6 changed files
with
129 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
|
||
const Document = require('../../Document'); | ||
const intersections = require('../../post/intersections'); | ||
const DEFAULT_SCRIPTS = [ intersections ]; | ||
|
||
module.exports.tests = {}; | ||
|
||
module.exports.tests.addPostProcessingScript = function(test) { | ||
test('default scripts', function(t) { | ||
let doc = new Document('mysource','mylayer','myid'); | ||
t.deepEqual(doc._post, DEFAULT_SCRIPTS, 'default processing scripts'); | ||
t.end(); | ||
}); | ||
test('invalid type', function(t) { | ||
let doc = new Document('mysource','mylayer','myid'); | ||
t.throws( doc.addPostProcessingScript.bind(doc, 'invalid'), /invalid document type, expecting: function got/ ); | ||
t.throws( doc.addPostProcessingScript.bind(doc, 100), /invalid document type, expecting: function got/ ); | ||
t.throws( doc.addPostProcessingScript.bind(doc, []), /invalid document type, expecting: function got/ ); | ||
t.throws( doc.addPostProcessingScript.bind(doc, {}), /invalid document type, expecting: function got/ ); | ||
t.end(); | ||
}); | ||
test('set function', function(t) { | ||
let script = function(){}; | ||
let doc = new Document('mysource','mylayer','myid'); | ||
doc.addPostProcessingScript( script ); | ||
t.deepEqual(doc._post, DEFAULT_SCRIPTS.concat( script ), 'default processing scripts'); | ||
t.end(); | ||
}); | ||
test('set same function twice (allowed)', function(t) { | ||
let script = function(){}; | ||
let doc = new Document('mysource','mylayer','myid'); | ||
doc.addPostProcessingScript( script ); | ||
doc.addPostProcessingScript( script ); | ||
t.deepEqual(doc._post, DEFAULT_SCRIPTS.concat( script, script ), 'default processing scripts'); | ||
t.end(); | ||
}); | ||
}; | ||
|
||
module.exports.tests.removePostProcessingScript = function(test) { | ||
test('invalid type', function(t) { | ||
let doc = new Document('mysource','mylayer','myid'); | ||
t.throws( doc.removePostProcessingScript.bind(doc, 'invalid'), /invalid document type, expecting: function got/ ); | ||
t.throws( doc.removePostProcessingScript.bind(doc, 100), /invalid document type, expecting: function got/ ); | ||
t.throws( doc.removePostProcessingScript.bind(doc, []), /invalid document type, expecting: function got/ ); | ||
t.throws( doc.removePostProcessingScript.bind(doc, {}), /invalid document type, expecting: function got/ ); | ||
t.end(); | ||
}); | ||
test('remove function', function(t) { | ||
let script = function(){}; | ||
let doc = new Document('mysource','mylayer','myid'); | ||
doc._post = [ script ]; | ||
doc.removePostProcessingScript( script ); | ||
t.deepEqual(doc._post, [], 'script removed'); | ||
doc.removePostProcessingScript( script ); | ||
t.deepEqual(doc._post, [], 'no-op'); | ||
t.end(); | ||
}); | ||
test('remove duplicate functions (allowed)', function(t) { | ||
let script = function(){}; | ||
let doc = new Document('mysource','mylayer','myid'); | ||
doc._post = [ script, script ]; | ||
doc.removePostProcessingScript( script ); | ||
t.deepEqual(doc._post, [], 'scripts removed'); | ||
doc.removePostProcessingScript( script ); | ||
t.deepEqual(doc._post, [], 'no-op'); | ||
t.end(); | ||
}); | ||
}; | ||
|
||
module.exports.tests.callPostProcessingScript = function(test) { | ||
test('call all scripts', function(t) { | ||
let doc = new Document('mysource','mylayer','myid'); | ||
doc._post = []; // remove any default scripts | ||
t.plan(3); | ||
|
||
// document pointer passed as first arg to scripts | ||
doc.addPostProcessingScript((ref) => t.equal(doc, ref)); | ||
doc.addPostProcessingScript((ref) => t.equal(doc, ref)); | ||
doc.addPostProcessingScript((ref) => t.equal(doc, ref)); | ||
|
||
// call all scripts | ||
doc.callPostProcessingScripts(); | ||
}); | ||
}; | ||
|
||
module.exports.all = function (tape, common) { | ||
|
||
function test(name, testFunction) { | ||
return tape('post processing: ' + name, testFunction); | ||
} | ||
|
||
for( let testCase in module.exports.tests ){ | ||
module.exports.tests[testCase](test, common); | ||
} | ||
}; |
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