-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace mocha with tape, istanbul with nyc
- Loading branch information
Showing
3 changed files
with
124 additions
and
104 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
.DS_Store | ||
*.log | ||
bower_components/ | ||
build/ | ||
components/ | ||
.nyc_output/ | ||
coverage/ | ||
node_modules/ | ||
build.js | ||
unist-util-find-before.js | ||
unist-util-find-before.min.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,111 +1,128 @@ | ||
'use strict'; | ||
|
||
/* eslint-env mocha */ | ||
|
||
var assert = require('assert'); | ||
var test = require('tape'); | ||
var mdast = require('mdast'); | ||
var findBefore = require('./'); | ||
|
||
var tree = mdast.parse('Some *emphasis*, **importance**, and `code`.'); | ||
var paragraph = tree.children[0]; | ||
var children = paragraph.children; | ||
|
||
describe('unist-util-find-before', function () { | ||
it('should fail without parent', function () { | ||
assert.throws( | ||
function () { | ||
findBefore(); | ||
}, | ||
/Expected parent node/ | ||
); | ||
}); | ||
test('unist-util-find-before', function (t) { | ||
t.throws( | ||
function () { | ||
findBefore(); | ||
}, | ||
/Expected parent node/, | ||
'should fail without parent' | ||
); | ||
|
||
t.throws( | ||
function () { | ||
findBefore({ | ||
type: 'foo' | ||
}); | ||
}, | ||
/Expected parent node/, | ||
'should fail without parent node' | ||
); | ||
|
||
it('should fail without parent node', function () { | ||
assert.throws( | ||
function () { | ||
findBefore({ | ||
type: 'foo' | ||
}); | ||
}, | ||
/Expected parent node/ | ||
); | ||
}); | ||
t.doesNotThrow( | ||
function () { | ||
assert.throws( | ||
function () { | ||
findBefore({type: 'foo', children: []}); | ||
}, | ||
/Expected positive finite index or child node/ | ||
); | ||
|
||
it('should fail without index', function () { | ||
assert.throws( | ||
function () { | ||
findBefore({type: 'foo', children: []}); | ||
}, | ||
/Expected positive finite index or child node/ | ||
); | ||
assert.throws( | ||
function () { | ||
findBefore({type: 'foo', children: []}, -1); | ||
}, | ||
/Expected positive finite index or child node/ | ||
); | ||
|
||
assert.throws( | ||
function () { | ||
findBefore({type: 'foo', children: []}, -1); | ||
}, | ||
/Expected positive finite index or child node/ | ||
); | ||
assert.throws( | ||
function () { | ||
findBefore({type: 'foo', children: []}, {type: 'bar'}); | ||
}, | ||
/Expected positive finite index or child node/ | ||
); | ||
}, | ||
'should fail without index' | ||
); | ||
|
||
assert.throws( | ||
function () { | ||
findBefore({type: 'foo', children: []}, {type: 'bar'}); | ||
}, | ||
/Expected positive finite index or child node/ | ||
); | ||
}); | ||
t.doesNotThrow( | ||
function () { | ||
assert.throws( | ||
function () { | ||
findBefore({ | ||
type: 'foo', | ||
children: [{type: 'bar'}] | ||
}, 1, false); | ||
}, | ||
/Expected function, string, or node as test/ | ||
); | ||
|
||
it('should fail for invalid `test`', function () { | ||
assert.throws( | ||
function () { | ||
findBefore({ | ||
type: 'foo', | ||
children: [{type: 'bar'}] | ||
}, 1, false); | ||
}, | ||
/Expected function, string, or node as test/ | ||
); | ||
assert.throws( | ||
function () { | ||
findBefore({ | ||
type: 'foo', | ||
children: [{type: 'bar'}] | ||
}, 1, true); | ||
}, | ||
/Expected function, string, or node as test/ | ||
); | ||
}, | ||
'should fail for invalid `test`' | ||
); | ||
|
||
assert.throws( | ||
function () { | ||
findBefore({ | ||
type: 'foo', | ||
children: [{type: 'bar'}] | ||
}, 1, true); | ||
}, | ||
/Expected function, string, or node as test/ | ||
); | ||
}); | ||
t.doesNotThrow( | ||
function () { | ||
assert.strictEqual(findBefore(paragraph, children[1]), children[0]); | ||
assert.strictEqual(findBefore(paragraph, 1), children[0]); | ||
assert.strictEqual(findBefore(paragraph, 0), null); | ||
}, | ||
'should return the preceding node when without `test`' | ||
); | ||
|
||
it('should return the preceding node when without `test`', function () { | ||
assert.strictEqual(findBefore(paragraph, children[1]), children[0]); | ||
assert.strictEqual(findBefore(paragraph, 1), children[0]); | ||
assert.strictEqual(findBefore(paragraph, 0), null); | ||
}); | ||
t.doesNotThrow( | ||
function () { | ||
assert.strictEqual(findBefore(paragraph, 100, children[0]), children[0]); | ||
assert.strictEqual(findBefore(paragraph, children[1], children[0]), children[0]); | ||
assert.strictEqual(findBefore(paragraph, 1, children[0]), children[0]); | ||
assert.strictEqual(findBefore(paragraph, children[0], children[0]), null); | ||
assert.strictEqual(findBefore(paragraph, 0, children[0]), null); | ||
assert.strictEqual(findBefore(paragraph, 1, children[1]), null); | ||
}, | ||
'should return `node` when given a `node` and existing' | ||
); | ||
|
||
it('should return `node` when given a `node` and existing', function () { | ||
assert.strictEqual(findBefore(paragraph, 100, children[0]), children[0]); | ||
assert.strictEqual(findBefore(paragraph, children[1], children[0]), children[0]); | ||
assert.strictEqual(findBefore(paragraph, 1, children[0]), children[0]); | ||
assert.strictEqual(findBefore(paragraph, children[0], children[0]), null); | ||
assert.strictEqual(findBefore(paragraph, 0, children[0]), null); | ||
assert.strictEqual(findBefore(paragraph, 1, children[1]), null); | ||
}); | ||
t.doesNotThrow( | ||
function () { | ||
assert.strictEqual(findBefore(paragraph, 100, 'strong'), children[3]); | ||
assert.strictEqual(findBefore(paragraph, 3, 'strong'), null); | ||
assert.strictEqual(findBefore(paragraph, children[4], 'strong'), children[3]); | ||
assert.strictEqual(findBefore(paragraph, children[3], 'strong'), null); | ||
}, | ||
'should return a child when given a `type` and existing' | ||
); | ||
|
||
it('should return a child when given a `type` and existing', function () { | ||
assert.strictEqual(findBefore(paragraph, 100, 'strong'), children[3]); | ||
assert.strictEqual(findBefore(paragraph, 3, 'strong'), null); | ||
assert.strictEqual(findBefore(paragraph, children[4], 'strong'), children[3]); | ||
assert.strictEqual(findBefore(paragraph, children[3], 'strong'), null); | ||
}); | ||
t.doesNotThrow( | ||
function () { | ||
assert.strictEqual(findBefore(paragraph, 100, test), children[3]); | ||
assert.strictEqual(findBefore(paragraph, 3, test), null); | ||
assert.strictEqual(findBefore(paragraph, children[4], test), children[3]); | ||
assert.strictEqual(findBefore(paragraph, children[3], test), null); | ||
|
||
it('should return a child when given a `test` and existing', function () { | ||
assert.strictEqual(findBefore(paragraph, 100, test), children[3]); | ||
assert.strictEqual(findBefore(paragraph, 3, test), null); | ||
assert.strictEqual(findBefore(paragraph, children[4], test), children[3]); | ||
assert.strictEqual(findBefore(paragraph, children[3], test), null); | ||
function test(node, n) { | ||
return n === 3; | ||
} | ||
}, | ||
'should return a child when given a `test` and existing' | ||
); | ||
|
||
function test(node, n) { | ||
return n === 3; | ||
} | ||
}); | ||
t.end(); | ||
}); |