Skip to content

Commit 7536a9f

Browse files
committed
add tests for matching to make sure we don't encounter false matches
1 parent 9f3411b commit 7536a9f

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

test/find_matching_blocks.spec.js

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,121 @@ describe('findMatchingBlocks', function(){
162162
expect(res[2].length).eql(1);
163163
});
164164
});
165+
166+
describe('HTML special case', function(){
167+
beforeEach(function(){
168+
const before = htmlToTokens('<div>Hello <p>foo</p> world! Hello Earth!</div>');
169+
const after = htmlToTokens('<div>Hello <p>foo</p> world! <p>bar</p> baz!</div>');
170+
segment = createSegment(before, after, 0, 0);
171+
res = cut(segment);
172+
});
173+
174+
it('should return 2 matches', function(){
175+
expect(res.length).to.equal(2);
176+
});
177+
178+
it('should match "<div>Hello <p>foo</p> world!"', function(){
179+
expect(res[0].startInBefore).eql(0);
180+
expect(res[0].startInAfter).eql(0);
181+
expect(res[0].endInBefore).eql(8);
182+
expect(res[0].endInAfter).eql(8);
183+
expect(res[0].length).eql(9);
184+
});
185+
186+
it('should match "</div>"', function(){
187+
expect(res[1].startInBefore).eql(12);
188+
expect(res[1].startInAfter).eql(14);
189+
expect(res[1].endInBefore).eql(12);
190+
expect(res[1].endInAfter).eql(14);
191+
expect(res[1].length).eql(1);
192+
});
193+
});
194+
195+
describe('HTML special case -- reverse', function(){
196+
beforeEach(function(){
197+
const before = htmlToTokens('<div>Hello <p>foo</p> world! <p>bar</p> baz!</div>');
198+
const after = htmlToTokens('<div>Hello <p>foo</p> world! Hello Earth!</div>');
199+
segment = createSegment(before, after, 0, 0);
200+
res = cut(segment);
201+
});
202+
203+
it('should return 2 matches', function(){
204+
expect(res.length).to.equal(2);
205+
});
206+
207+
it('should match "<div>Hello <p>foo</p> world!"', function(){
208+
expect(res[0].startInBefore).eql(0);
209+
expect(res[0].startInAfter).eql(0);
210+
expect(res[0].endInBefore).eql(8);
211+
expect(res[0].endInAfter).eql(8);
212+
expect(res[0].length).eql(9);
213+
});
214+
215+
it('should match "</div>"', function(){
216+
expect(res[1].startInBefore).eql(14);
217+
expect(res[1].startInAfter).eql(12);
218+
expect(res[1].endInBefore).eql(14);
219+
expect(res[1].endInAfter).eql(12);
220+
expect(res[1].length).eql(1);
221+
});
222+
});
223+
224+
describe('HTML special case with blockquote', function(){
225+
beforeEach(function(){
226+
const before = htmlToTokens('<div>Hello <p>foo</p> world! <blockquote>Hello Earth!</blockquote></div>');
227+
const after = htmlToTokens('<div>Hello <p>foo</p> world! <p>Hello Earth!</p></div>');
228+
segment = createSegment(before, after, 0, 0);
229+
res = cut(segment);
230+
});
231+
232+
it('should return 2 matches', function(){
233+
expect(res.length).to.equal(2);
234+
});
235+
236+
it('should match "<div>Hello <p>foo</p> world!"', function(){
237+
expect(res[0].startInBefore).eql(0);
238+
expect(res[0].startInAfter).eql(0);
239+
expect(res[0].endInBefore).eql(8);
240+
expect(res[0].endInAfter).eql(8);
241+
expect(res[0].length).eql(9);
242+
});
243+
244+
it('should match "</div>"', function(){
245+
expect(res[1].startInBefore).eql(14);
246+
expect(res[1].startInAfter).eql(14);
247+
expect(res[1].endInBefore).eql(14);
248+
expect(res[1].endInAfter).eql(14);
249+
expect(res[1].length).eql(1);
250+
});
251+
});
252+
253+
describe('HTML special case with blockquote -- reverse', function(){
254+
beforeEach(function(){
255+
const before = htmlToTokens('<div>Hello <p>foo</p> world! <p>Hello Earth!</p></div>');
256+
const after = htmlToTokens('<div>Hello <p>foo</p> world! <blockquote>Hello Earth!</blockquote></div>');
257+
segment = createSegment(before, after, 0, 0);
258+
res = cut(segment);
259+
});
260+
261+
it('should return 2 matches', function(){
262+
expect(res.length).to.equal(2);
263+
});
264+
265+
it('should match "<div>Hello <p>foo</p> world!"', function(){
266+
expect(res[0].startInBefore).eql(0);
267+
expect(res[0].startInAfter).eql(0);
268+
expect(res[0].endInBefore).eql(8);
269+
expect(res[0].endInAfter).eql(8);
270+
expect(res[0].length).eql(9);
271+
});
272+
273+
it('should match "</div>"', function(){
274+
expect(res[1].startInBefore).eql(14);
275+
expect(res[1].startInAfter).eql(14);
276+
expect(res[1].endInBefore).eql(14);
277+
expect(res[1].endInAfter).eql(14);
278+
expect(res[1].length).eql(1);
279+
});
280+
});
165281
});
166282
});

0 commit comments

Comments
 (0)