.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / unist-util-find-all-after / test.js
1 'use strict'
2
3 var assert = require('assert')
4 var test = require('tape')
5 var remark = require('remark')
6 var findAllAfter = require('.')
7
8 var tree = remark().parse('Some *emphasis*, **importance**, and `code`.')
9 var paragraph = tree.children[0]
10 var children = paragraph.children
11
12 test('unist-util-find-all-after', function(t) {
13   t.throws(
14     function() {
15       findAllAfter()
16     },
17     /Expected parent node/,
18     'should fail without parent'
19   )
20
21   t.throws(
22     function() {
23       findAllAfter({type: 'foo'})
24     },
25     /Expected parent node/,
26     'should fail without parent node'
27   )
28
29   t.doesNotThrow(function() {
30     assert.throws(function() {
31       findAllAfter({type: 'foo', children: []})
32     }, /Expected positive finite index or child node/)
33
34     assert.throws(function() {
35       findAllAfter({type: 'foo', children: []}, -1)
36     }, /Expected positive finite index or child node/)
37
38     assert.throws(function() {
39       findAllAfter({type: 'foo', children: []}, {type: 'bar'})
40     }, /Expected positive finite index or child node/)
41   }, 'should fail without index')
42
43   t.doesNotThrow(function() {
44     assert.throws(function() {
45       findAllAfter(
46         {
47           type: 'foo',
48           children: [{type: 'bar'}, {type: 'baz'}]
49         },
50         0,
51         false
52       )
53     }, /Expected function, string, or object as test/)
54
55     assert.throws(function() {
56       findAllAfter(
57         {
58           type: 'foo',
59           children: [{type: 'bar'}, {type: 'baz'}]
60         },
61         0,
62         true
63       )
64     }, /Expected function, string, or object as test/)
65   }, 'should fail for invalid `test`')
66
67   t.doesNotThrow(function() {
68     var res = children.slice(2)
69
70     assert.deepStrictEqual(findAllAfter(paragraph, children[1]), res)
71     assert.deepStrictEqual(findAllAfter(paragraph, 1), res)
72     assert.deepStrictEqual(findAllAfter(paragraph, 7), [])
73   }, 'should return the following node when without `test`')
74
75   t.doesNotThrow(function() {
76     assert.deepStrictEqual(findAllAfter(paragraph, 0, children[6]), [
77       children[6]
78     ])
79     assert.deepStrictEqual(findAllAfter(paragraph, children[0], children[1]), [
80       children[1]
81     ])
82     assert.deepStrictEqual(findAllAfter(paragraph, 0, children[1]), [
83       children[1]
84     ])
85     assert.deepStrictEqual(
86       findAllAfter(paragraph, children[0], children[0]),
87       []
88     )
89     assert.deepStrictEqual(findAllAfter(paragraph, 0, children[0]), [])
90     assert.deepStrictEqual(findAllAfter(paragraph, 1, children[1]), [])
91   }, 'should return `node` when given a `node` and existing')
92
93   t.doesNotThrow(function() {
94     assert.deepStrictEqual(findAllAfter(paragraph, 0, 'strong'), [children[3]])
95     assert.deepStrictEqual(findAllAfter(paragraph, 3, 'strong'), [])
96     assert.deepStrictEqual(findAllAfter(paragraph, children[0], 'strong'), [
97       children[3]
98     ])
99     assert.deepStrictEqual(findAllAfter(paragraph, children[3], 'strong'), [])
100   }, 'should return a child when given a `type` and existing')
101
102   t.doesNotThrow(function() {
103     var res = children.slice(5)
104
105     assert.deepStrictEqual(findAllAfter(paragraph, 0, test), res)
106     assert.deepStrictEqual(findAllAfter(paragraph, 6, test), [])
107     assert.deepStrictEqual(findAllAfter(paragraph, children[4], test), res)
108     assert.deepStrictEqual(findAllAfter(paragraph, children[6], test), [])
109
110     function test(node, n) {
111       return n >= 5
112     }
113   }, 'should return a child when given a `test` and existing')
114
115   t.end()
116 })