|
1 |
| -const test = require('tape'); |
| 1 | +const test = require('ava'); |
2 | 2 | const xmlReader = require('xml-reader');
|
3 | 3 | const xQuery = require('..');
|
4 | 4 |
|
@@ -27,150 +27,130 @@ const xmlMessages =
|
27 | 27 | ${xmlMessage2}
|
28 | 28 | </collection>`;
|
29 | 29 |
|
30 |
| -test('constructor from ast', t => { |
| 30 | +test.cb('constructor from ast', t => { |
31 | 31 | const reader = xmlReader.create();
|
32 | 32 | reader.on('done', ast => {
|
33 | 33 | const xq = xQuery(ast);
|
34 |
| - t.equal(xq.length, 1, 'length is 1'); |
35 |
| - t.equal(xq.get(0), ast, 'item 0 is the same ast'); |
| 34 | + t.is(xq.length, 1, 'length is 1'); |
| 35 | + t.is(xq.get(0), ast, 'item 0 is the same ast'); |
36 | 36 | t.end();
|
37 | 37 | });
|
38 | 38 | reader.parse(xmlMessage1);
|
39 | 39 | });
|
40 | 40 |
|
41 |
| -test('constructor from ast array', t => { |
| 41 | +test.cb('constructor from ast array', t => { |
42 | 42 | const reader = xmlReader.create();
|
43 | 43 | reader.on('done', ast => {
|
44 | 44 | const xq = xQuery([ast, ast]);
|
45 |
| - t.equal(xq.length, 2, 'length is 2'); |
46 |
| - t.equal(xq.get(0), ast, 'item 0 is ok'); |
47 |
| - t.equal(xq.get(1), ast, 'item 1 is ok'); |
| 45 | + t.is(xq.length, 2, 'length is 2'); |
| 46 | + t.is(xq.get(0), ast, 'item 0 is ok'); |
| 47 | + t.is(xq.get(1), ast, 'item 1 is ok'); |
48 | 48 | t.end();
|
49 | 49 | });
|
50 | 50 | reader.parse(xmlMessage1);
|
51 | 51 | });
|
52 | 52 |
|
53 |
| -test('constructor from falsy values', t => { |
| 53 | +test.cb('constructor from falsy values', t => { |
54 | 54 | const values = [null, false, undefined, 0, [], ''];
|
55 | 55 | values.forEach(value => {
|
56 | 56 | const xq = xQuery(value);
|
57 |
| - t.equal(xq.length, 0, 'length is 0'); |
58 |
| - t.equal(xq.get(0), undefined, 'item 0 is undefined'); |
| 57 | + t.is(xq.length, 0, 'length is 0'); |
| 58 | + t.is(xq.get(0), undefined, 'item 0 is undefined'); |
59 | 59 | });
|
60 | 60 | t.end();
|
61 | 61 | });
|
62 | 62 |
|
63 |
| -test('find root element', t => { |
| 63 | +test.cb('find root element', t => { |
64 | 64 | const reader = xmlReader.create();
|
65 | 65 | reader.on('done', ast => {
|
66 | 66 | const xq = xQuery(ast);
|
67 | 67 | const result = xq.find('message');
|
68 |
| - t.equal(result.length, 1, 'one element found'); |
69 |
| - t.equal(result.get(0).name, 'message', 'element name is message'); |
| 68 | + t.is(result.length, 1, 'one element found'); |
| 69 | + t.is(result.get(0).name, 'message', 'element name is message'); |
70 | 70 | t.end();
|
71 | 71 | });
|
72 | 72 | reader.parse(xmlMessage1);
|
73 | 73 | });
|
74 | 74 |
|
75 |
| -test('find root elements from array', t => { |
| 75 | +test.cb('find root elements from array', t => { |
76 | 76 | const reader = xmlReader.create();
|
77 | 77 | reader.on('done', ast => {
|
78 | 78 | const xq = xQuery([ast, ast]);
|
79 | 79 | const result = xq.find('message');
|
80 |
| - t.equal(result.length, 2, 'two elements found'); |
81 |
| - t.equal(result.get(0).name, 'message', 'element #0 name is message'); |
82 |
| - t.equal(result.get(1).name, 'message', 'element #1 name is message'); |
| 80 | + t.is(result.length, 2, 'two elements found'); |
| 81 | + t.is(result.get(0).name, 'message', 'element #0 name is message'); |
| 82 | + t.is(result.get(1).name, 'message', 'element #1 name is message'); |
83 | 83 | t.end();
|
84 | 84 | });
|
85 | 85 | reader.parse(xmlMessage1);
|
86 | 86 | });
|
87 | 87 |
|
88 |
| -test('find deep', t => { |
| 88 | +test.cb('find deep', t => { |
89 | 89 | const reader = xmlReader.create();
|
90 | 90 | reader.on('done', ast => {
|
91 | 91 | const xq = xQuery(ast);
|
92 | 92 | const result = xq.find('to');
|
93 |
| - t.equal(result.length, 3, 'three elements found'); |
94 |
| - t.equal(result.get(0).children[0].value, 'Alice'); |
95 |
| - t.equal(result.get(1).children[0].value, 'Carl'); |
96 |
| - t.equal(result.get(2).children[0].value, 'Alice'); |
| 93 | + t.is(result.length, 3, 'three elements found'); |
| 94 | + t.is(result.get(0).children[0].value, 'Alice'); |
| 95 | + t.is(result.get(1).children[0].value, 'Carl'); |
| 96 | + t.is(result.get(2).children[0].value, 'Alice'); |
97 | 97 | t.end();
|
98 | 98 | });
|
99 | 99 | reader.parse(xmlMessages);
|
100 | 100 | });
|
101 | 101 |
|
102 |
| -test('attr', t => { |
| 102 | +test.cb('attr', t => { |
103 | 103 | const reader = xmlReader.create();
|
104 | 104 | reader.on('done', ast => {
|
| 105 | + let result, attr1, attr2; |
105 | 106 |
|
106 |
| - t.test('attr from ast - get all', t => { |
107 |
| - const result = xQuery(ast).find('message').attr(); |
108 |
| - t.deepEqual(result, {id: '1001', type: 'letter'}, 'got all attributes'); |
109 |
| - t.end(); |
110 |
| - }); |
111 |
| - |
112 |
| - t.test('attr from ast - get by name', t => { |
113 |
| - const attr1 = xQuery(ast).find('message').attr('id'); |
114 |
| - const attr2 = xQuery(ast).find('message').attr('type'); |
115 |
| - t.equal(attr1, '1001', 'attr value is correct'); |
116 |
| - t.equal(attr2, 'letter', 'attr value is correct'); |
117 |
| - t.end(); |
118 |
| - }); |
119 |
| - |
120 |
| - t.test('attr from ast - get by name miss', t => { |
121 |
| - const result = xQuery(ast).find('message').attr('miss'); |
122 |
| - t.equal(result, undefined, 'returns undefined'); |
123 |
| - t.end(); |
124 |
| - }); |
125 |
| - |
126 |
| - t.test('attr from ast array - get all', t => { |
127 |
| - const result = xQuery([ast, ast]).find('message').attr(); |
128 |
| - t.deepEqual(result, {id: '1001', type: 'letter'}, 'got all attributes'); |
129 |
| - t.end(); |
130 |
| - }); |
131 |
| - |
132 |
| - t.test('attr from ast array - get by name', t => { |
133 |
| - const attr1 = xQuery(ast).find('message').attr('id'); |
134 |
| - const attr2 = xQuery(ast).find('message').attr('type'); |
135 |
| - t.equal(attr1, '1001', 'attr value is correct'); |
136 |
| - t.equal(attr2, 'letter', 'attr value is correct'); |
137 |
| - t.end(); |
138 |
| - }); |
139 |
| - |
140 |
| - t.test('attr from empty array - get all', t => { |
141 |
| - const result = xQuery([]).attr(); |
142 |
| - t.deepEqual(result, undefined, 'returns undefined'); |
143 |
| - t.end(); |
144 |
| - }); |
145 |
| - |
146 |
| - t.test('attr from empty array - get by name', t => { |
147 |
| - const result = xQuery([]).attr('miss'); |
148 |
| - t.deepEqual(result, undefined, 'returns undefined'); |
149 |
| - t.end(); |
150 |
| - }); |
| 107 | + result = xQuery(ast).find('message').attr(); |
| 108 | + t.deepEqual(result, {id: '1001', type: 'letter'}, 'attr from ast - get all'); |
| 109 | + |
| 110 | + attr1 = xQuery(ast).find('message').attr('id'); |
| 111 | + attr2 = xQuery(ast).find('message').attr('type'); |
| 112 | + t.is(attr1, '1001', 'attr from ast - get by name'); |
| 113 | + t.is(attr2, 'letter', 'attr from ast - get by name'); |
| 114 | + |
| 115 | + result = xQuery(ast).find('message').attr('miss'); |
| 116 | + t.is(result, undefined, 'attr from ast - get by name miss'); |
| 117 | + |
| 118 | + result = xQuery([ast, ast]).find('message').attr(); |
| 119 | + t.deepEqual(result, {id: '1001', type: 'letter'}, 'attr from ast array - get all'); |
| 120 | + |
| 121 | + attr1 = xQuery(ast).find('message').attr('id'); |
| 122 | + attr2 = xQuery(ast).find('message').attr('type'); |
| 123 | + t.is(attr1, '1001', 'attr from ast array - get by name'); |
| 124 | + t.is(attr2, 'letter', 'attr from ast array - get by name'); |
| 125 | + |
| 126 | + result = xQuery([]).attr(); |
| 127 | + t.deepEqual(result, undefined, 'attr from empty array - get all'); |
| 128 | + |
| 129 | + result = xQuery([]).attr('miss'); |
| 130 | + t.deepEqual(result, undefined, 'attr from empty array - get by name'); |
151 | 131 |
|
152 | 132 | t.end();
|
153 | 133 | });
|
154 | 134 | reader.parse(xmlMessage1);
|
155 | 135 | });
|
156 | 136 |
|
157 |
| -test('children', t => { |
| 137 | +test.cb('children', t => { |
158 | 138 | const reader = xmlReader.create();
|
159 | 139 | reader.on('done', ast => {
|
160 | 140 | const xq = xQuery(ast).children();
|
161 |
| - t.equal(xq.length, 4, 'length is 4'); |
| 141 | + t.is(xq.length, 4, 'length is 4'); |
162 | 142 | t.deepEqual(xq.map(node => node.name), ['to', 'from', 'subject', 'body'], 'children names ok');
|
163 | 143 | t.end();
|
164 | 144 | });
|
165 | 145 | reader.parse(xmlMessage1);
|
166 | 146 | });
|
167 | 147 |
|
168 |
| -test('text', t => { |
| 148 | +test.cb('text', t => { |
169 | 149 | const reader = xmlReader.create();
|
170 | 150 | reader.on('done', ast => {
|
171 | 151 | const expected = 'AliceBobHelloThis is a demo!';
|
172 | 152 | const result = xQuery(ast).text();
|
173 |
| - t.equal(result, expected, 'text is correct'); |
| 153 | + t.is(result, expected, 'text is correct'); |
174 | 154 | t.end();
|
175 | 155 | });
|
176 | 156 | reader.parse(xmlMessage1);
|
|
0 commit comments