Skip to content

Commit 7ee11d8

Browse files
committed
Merge tests
1 parent 3ab84c1 commit 7ee11d8

File tree

3 files changed

+80
-94
lines changed

3 files changed

+80
-94
lines changed

test/test.js renamed to test.js

Lines changed: 80 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
var remove = require('..');
44

5-
var it = require('tape'),
5+
var test = require('tape'),
66
u = require('unist-builder');
77

88

9-
it('should compare nodes by partial properties', function (t) {
9+
test('should compare nodes by partial properties', function (t) {
1010
var ast = u('node', [
1111
u('node', 'foo'),
1212
u('node', 'bar')
@@ -24,7 +24,7 @@ it('should compare nodes by partial properties', function (t) {
2424
});
2525

2626

27-
it('should remove nodes with children', function (t) {
27+
test('should remove nodes with children', function (t) {
2828
var ast = u('root', [
2929
u('node', [
3030
u('leaf', 1)
@@ -46,7 +46,7 @@ it('should remove nodes with children', function (t) {
4646
});
4747

4848

49-
it('should return `null` if root node is removed', function (t) {
49+
test('should return `null` if root node is removed', function (t) {
5050
var ast = u('root', [
5151
u('node', [
5252
u('leaf', 1)
@@ -59,7 +59,7 @@ it('should return `null` if root node is removed', function (t) {
5959
});
6060

6161

62-
it('should cascade remove parent nodes', function (t) {
62+
test('should cascade remove parent nodes', function (t) {
6363
t.test(function (t) {
6464
var ast = u('root', [
6565
u('node', [
@@ -97,7 +97,7 @@ it('should cascade remove parent nodes', function (t) {
9797
});
9898

9999

100-
it('should not cascade-remove nodes that were empty initially', function (t) {
100+
test('should not cascade-remove nodes that were empty initially', function (t) {
101101
var ast = u('node', [
102102
u('node', []),
103103
u('node', [
@@ -114,7 +114,7 @@ it('should not cascade-remove nodes that were empty initially', function (t) {
114114
});
115115

116116

117-
it('should support type tests and predicate functions', function (t) {
117+
test('should support type tests and predicate functions', function (t) {
118118
t.test(function (t) {
119119
var ast = u('node', [
120120
u('node', [
@@ -169,3 +169,76 @@ it('should support type tests and predicate functions', function (t) {
169169
t.end();
170170
});
171171
});
172+
173+
test('opts.cascade', function (t) {
174+
t.test('opts.cascade = true', function (t) {
175+
var ast = u('root', [
176+
u('node', [
177+
u('leaf', 1)
178+
]),
179+
u('leaf', 2)
180+
]);
181+
182+
var newAst = remove(ast, { cascade: true }, function (node) {
183+
return node === ast.children[0].children[0] || node === ast.children[1];
184+
});
185+
186+
t.equal(newAst, null);
187+
t.end();
188+
});
189+
190+
t.test('opts.cascade = false', function (t) {
191+
var ast = u('root', [
192+
u('node', [
193+
u('leaf', 1)
194+
]),
195+
u('leaf', 2)
196+
]);
197+
var children = ast.children;
198+
var innerNode = ast.children[0];
199+
var grandChildren = ast.children[0].children;
200+
201+
var newAst = remove(ast, { cascade: false }, function (node) {
202+
return node === ast.children[0].children[0] || node === ast.children[1];
203+
});
204+
205+
t.equal(newAst, ast);
206+
t.deepEqual(ast, u('root', [
207+
u('node', [])
208+
]));
209+
t.equal(ast.children, children);
210+
t.equal(ast.children[0], innerNode);
211+
t.equal(ast.children[0].children, grandChildren);
212+
t.end();
213+
});
214+
});
215+
216+
test('example from README', function (t) {
217+
var ast = u('root', [
218+
u('leaf', 1),
219+
u('node', [
220+
u('leaf', 2),
221+
u('node', [
222+
u('leaf', 3),
223+
u('other', 4)
224+
]),
225+
u('node', [
226+
u('leaf', 5),
227+
])
228+
]),
229+
u('leaf', 6)
230+
]);
231+
232+
t.deepEqual(
233+
remove(ast, 'leaf'),
234+
u('root', [
235+
u('node', [
236+
u('node', [
237+
u('other', 4)
238+
])
239+
])
240+
])
241+
);
242+
243+
t.end();
244+
});

test/example.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

test/opts.js

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)