X-Git-Url: https://git.josue.xyz/?a=blobdiff_plain;f=.config%2Fcoc%2Fextensions%2Fnode_modules%2Fcoc-prettier%2Fnode_modules%2Funist-util-find-all-after%2Ftest.js;fp=.config%2Fcoc%2Fextensions%2Fnode_modules%2Fcoc-prettier%2Fnode_modules%2Funist-util-find-all-after%2Ftest.js;h=5a31a35374095379e500d0069672f017efd3ab78;hb=3aba54c891969552833dbc350b3139e944e17a97;hp=0000000000000000000000000000000000000000;hpb=1def8ecce8e6f3aa32e6978d0ba7846a99b8de34;p=dotfiles%2F.git diff --git a/.config/coc/extensions/node_modules/coc-prettier/node_modules/unist-util-find-all-after/test.js b/.config/coc/extensions/node_modules/coc-prettier/node_modules/unist-util-find-all-after/test.js new file mode 100644 index 00000000..5a31a353 --- /dev/null +++ b/.config/coc/extensions/node_modules/coc-prettier/node_modules/unist-util-find-all-after/test.js @@ -0,0 +1,116 @@ +'use strict' + +var assert = require('assert') +var test = require('tape') +var remark = require('remark') +var findAllAfter = require('.') + +var tree = remark().parse('Some *emphasis*, **importance**, and `code`.') +var paragraph = tree.children[0] +var children = paragraph.children + +test('unist-util-find-all-after', function(t) { + t.throws( + function() { + findAllAfter() + }, + /Expected parent node/, + 'should fail without parent' + ) + + t.throws( + function() { + findAllAfter({type: 'foo'}) + }, + /Expected parent node/, + 'should fail without parent node' + ) + + t.doesNotThrow(function() { + assert.throws(function() { + findAllAfter({type: 'foo', children: []}) + }, /Expected positive finite index or child node/) + + assert.throws(function() { + findAllAfter({type: 'foo', children: []}, -1) + }, /Expected positive finite index or child node/) + + assert.throws(function() { + findAllAfter({type: 'foo', children: []}, {type: 'bar'}) + }, /Expected positive finite index or child node/) + }, 'should fail without index') + + t.doesNotThrow(function() { + assert.throws(function() { + findAllAfter( + { + type: 'foo', + children: [{type: 'bar'}, {type: 'baz'}] + }, + 0, + false + ) + }, /Expected function, string, or object as test/) + + assert.throws(function() { + findAllAfter( + { + type: 'foo', + children: [{type: 'bar'}, {type: 'baz'}] + }, + 0, + true + ) + }, /Expected function, string, or object as test/) + }, 'should fail for invalid `test`') + + t.doesNotThrow(function() { + var res = children.slice(2) + + assert.deepStrictEqual(findAllAfter(paragraph, children[1]), res) + assert.deepStrictEqual(findAllAfter(paragraph, 1), res) + assert.deepStrictEqual(findAllAfter(paragraph, 7), []) + }, 'should return the following node when without `test`') + + t.doesNotThrow(function() { + assert.deepStrictEqual(findAllAfter(paragraph, 0, children[6]), [ + children[6] + ]) + assert.deepStrictEqual(findAllAfter(paragraph, children[0], children[1]), [ + children[1] + ]) + assert.deepStrictEqual(findAllAfter(paragraph, 0, children[1]), [ + children[1] + ]) + assert.deepStrictEqual( + findAllAfter(paragraph, children[0], children[0]), + [] + ) + assert.deepStrictEqual(findAllAfter(paragraph, 0, children[0]), []) + assert.deepStrictEqual(findAllAfter(paragraph, 1, children[1]), []) + }, 'should return `node` when given a `node` and existing') + + t.doesNotThrow(function() { + assert.deepStrictEqual(findAllAfter(paragraph, 0, 'strong'), [children[3]]) + assert.deepStrictEqual(findAllAfter(paragraph, 3, 'strong'), []) + assert.deepStrictEqual(findAllAfter(paragraph, children[0], 'strong'), [ + children[3] + ]) + assert.deepStrictEqual(findAllAfter(paragraph, children[3], 'strong'), []) + }, 'should return a child when given a `type` and existing') + + t.doesNotThrow(function() { + var res = children.slice(5) + + assert.deepStrictEqual(findAllAfter(paragraph, 0, test), res) + assert.deepStrictEqual(findAllAfter(paragraph, 6, test), []) + assert.deepStrictEqual(findAllAfter(paragraph, children[4], test), res) + assert.deepStrictEqual(findAllAfter(paragraph, children[6], test), []) + + function test(node, n) { + return n >= 5 + } + }, 'should return a child when given a `test` and existing') + + t.end() +})