devstar插件
This commit is contained in:
41
node_modules/mark.js/test/specs/ranges/across-elements.js
generated
vendored
Normal file
41
node_modules/mark.js/test/specs/ranges/across-elements.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
'use strict';
|
||||
describe('mark with range across elements', function() {
|
||||
var $ctx, txt, ranges, index;
|
||||
beforeEach(function(done) {
|
||||
loadFixtures('ranges/across-elements.html');
|
||||
|
||||
$ctx = $('.ranges-across-elements');
|
||||
txt = $ctx.text();
|
||||
ranges = [];
|
||||
|
||||
// searching for "do<span>lor sit</span> amet"
|
||||
index = txt.indexOf('dolor');
|
||||
// don't include span tags when determining length
|
||||
ranges.push({ start: index, length: 14 });
|
||||
|
||||
// searching for "amet.\n </p><p>\n Testing"
|
||||
index = txt.lastIndexOf('amet');
|
||||
ranges.push({
|
||||
start: index,
|
||||
length: txt.indexOf(' 1234') - index
|
||||
});
|
||||
|
||||
new Mark($ctx[0]).markRanges(ranges, {
|
||||
'each': function(node, range) {
|
||||
$(node).attr('data-range-start', range.start);
|
||||
},
|
||||
'done': done
|
||||
});
|
||||
});
|
||||
|
||||
it('should properly mark ranges across elements', function() {
|
||||
var match1 = $ctx.find(
|
||||
'mark[data-range-start=' + ranges[0].start + ']'
|
||||
).text(),
|
||||
match2 = $ctx.find(
|
||||
'mark[data-range-start=' + ranges[1].start + ']'
|
||||
).text().replace(/\s+/g, '');
|
||||
expect(match1).toEqual('dolor sit amet');
|
||||
expect(match2).toEqual('amet.Testing');
|
||||
});
|
||||
});
|
35
node_modules/mark.js/test/specs/ranges/each.js
generated
vendored
Normal file
35
node_modules/mark.js/test/specs/ranges/each.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
describe('mark with range each callback', function() {
|
||||
var $ctx, $elements, ranges;
|
||||
beforeEach(function(done) {
|
||||
loadFixtures('ranges/each.html');
|
||||
|
||||
$elements = $();
|
||||
$ctx = $('.ranges-each');
|
||||
ranges = [];
|
||||
new Mark($ctx[0]).markRanges([
|
||||
{ start: 20, length: 5 },
|
||||
{ start: 64, length: 5 }
|
||||
], {
|
||||
'each': function(node, range) {
|
||||
$elements = $elements.add($(node));
|
||||
ranges.push(range);
|
||||
},
|
||||
'done': done
|
||||
});
|
||||
});
|
||||
|
||||
it('should call the each callback for each range element', function() {
|
||||
expect($elements).toHaveLength(2);
|
||||
});
|
||||
it('should pass the correct parameters', function() {
|
||||
var textOpts = ['ipsum', 'elitr'];
|
||||
$elements.each(function() {
|
||||
expect($.inArray($(this).text(), textOpts)).toBeGreaterThan(-1);
|
||||
});
|
||||
expect(ranges).toEqual([
|
||||
{ start: 20, length: 5 },
|
||||
{ start: 64, length: 5 }
|
||||
]);
|
||||
});
|
||||
});
|
83
node_modules/mark.js/test/specs/ranges/filter.js
generated
vendored
Normal file
83
node_modules/mark.js/test/specs/ranges/filter.js
generated
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
'use strict';
|
||||
describe('mark with range filter callback', function() {
|
||||
var $ctx, filterCalled, nodeCounter, termCount, rangeCount, ranges, results,
|
||||
// will target the first unique term
|
||||
terms = ['ipsum', 'amet', 'elitr', 'tempor', 'nonumy'],
|
||||
// term to filter out
|
||||
skip = 'elitr';
|
||||
|
||||
// in case the fixture whitespace is altered
|
||||
function getRange($el, string) {
|
||||
var start = $el.text().indexOf(string),
|
||||
length = string.length;
|
||||
return start > -1 ? { 'start': start, 'length': length } : null;
|
||||
}
|
||||
|
||||
beforeEach(function(done) {
|
||||
loadFixtures('ranges/filter.html');
|
||||
|
||||
filterCalled = 0;
|
||||
nodeCounter = 0;
|
||||
termCount = 0;
|
||||
rangeCount = 0;
|
||||
$ctx = $('.ranges-filter');
|
||||
ranges = [];
|
||||
results = {};
|
||||
|
||||
terms.forEach(function(item, index) {
|
||||
var range = getRange($ctx, item);
|
||||
if (range) {
|
||||
results[item] = {
|
||||
'name': item,
|
||||
'start': range.start,
|
||||
'length': range.length,
|
||||
'index': index
|
||||
};
|
||||
range.index = index;
|
||||
// make sure the entire range object is being passed
|
||||
range.foo = 'bar' + index;
|
||||
ranges.push(range);
|
||||
}
|
||||
});
|
||||
|
||||
new Mark($ctx[0]).markRanges(ranges, {
|
||||
'filter': function(node, range, match, counter) {
|
||||
filterCalled++;
|
||||
if (node.nodeType === 3) {
|
||||
nodeCounter++;
|
||||
}
|
||||
var item = results[match];
|
||||
// check indexes; this won't always equal the counter
|
||||
// because the values within "terms" may not be in order
|
||||
if (
|
||||
item &&
|
||||
item.index === range.index &&
|
||||
// make sure we're getting a counter value
|
||||
(counter === filterCalled - 1)
|
||||
) {
|
||||
termCount++;
|
||||
if (
|
||||
item.start === range.start &&
|
||||
item.length === range.length &&
|
||||
// check extra data
|
||||
range.foo === 'bar' + item.index
|
||||
) {
|
||||
rangeCount++;
|
||||
}
|
||||
}
|
||||
return match !== skip;
|
||||
},
|
||||
'done': done
|
||||
});
|
||||
});
|
||||
|
||||
it('should call the filter callback for each range element', function() {
|
||||
var length = terms.length;
|
||||
expect(filterCalled).toBe(length);
|
||||
expect(nodeCounter).toBe(length);
|
||||
expect(termCount).toBe(length);
|
||||
expect(rangeCount).toBe(length);
|
||||
expect($ctx.find('mark')).toHaveLength(length - 1);
|
||||
expect($ctx.find('mark:contains(' + skip + ')')).toHaveLength(0);
|
||||
});
|
||||
});
|
25
node_modules/mark.js/test/specs/ranges/iframes.js
generated
vendored
Normal file
25
node_modules/mark.js/test/specs/ranges/iframes.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
describe('mark with range in iframes', function() {
|
||||
var $ctx;
|
||||
beforeEach(function(done) {
|
||||
loadFixtures('ranges/iframes.html');
|
||||
|
||||
$ctx = $('.ranges-iframes');
|
||||
new Mark($ctx[0]).markRanges([
|
||||
// "lorem" in iframes.html
|
||||
{ start: 14, length: 5 },
|
||||
// "lorem" in inc.html iframe
|
||||
{ start: 70, length: 5 },
|
||||
// "testing" in inc.html iframe
|
||||
{ start: 82, length: 7 }
|
||||
], {
|
||||
'iframes': true,
|
||||
'done': done
|
||||
});
|
||||
});
|
||||
|
||||
it('should mark correct range including iframes', function() {
|
||||
expect($ctx.find('mark')).toHaveLength(1);
|
||||
expect($ctx.find('iframe').contents().find('mark')).toHaveLength(2);
|
||||
});
|
||||
});
|
94
node_modules/mark.js/test/specs/ranges/main.js
generated
vendored
Normal file
94
node_modules/mark.js/test/specs/ranges/main.js
generated
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
'use strict';
|
||||
|
||||
describe('mark with range', function() {
|
||||
var $ctx1, $ctx2, ranges, range, notFound,
|
||||
// [single word, characters spanning spaces, anything]
|
||||
terms = ['nonumy', 'nt ut labor', 'vero'];
|
||||
|
||||
// in case the fixture whitespace is altered
|
||||
function getRange($el, string) {
|
||||
var start = $el.text().indexOf(string),
|
||||
length = string.length;
|
||||
return start > -1 ? {
|
||||
'start': start,
|
||||
'length': length
|
||||
} : null;
|
||||
}
|
||||
|
||||
function each(node, range) {
|
||||
$(node).attr('data-range-start', range.start);
|
||||
$(node).attr('data-range-length', range.length);
|
||||
}
|
||||
|
||||
beforeEach(function(done) {
|
||||
loadFixtures('ranges/main.html');
|
||||
|
||||
notFound = [];
|
||||
ranges = [];
|
||||
$ctx1 = $('.ranges > div:nth-child(1)');
|
||||
$ctx2 = $('.ranges > div:nth-child(2)');
|
||||
|
||||
// single word
|
||||
range = getRange($ctx1, terms[0]);
|
||||
ranges.push({
|
||||
start: range.start,
|
||||
length: range.length
|
||||
});
|
||||
// characters spanning spaces
|
||||
ranges.push(getRange($ctx1, terms[1]));
|
||||
range = getRange($ctx1, terms[2]);
|
||||
// will be parsed into integers
|
||||
ranges.push({
|
||||
start: range.start + '.674',
|
||||
length: range.length + .234
|
||||
});
|
||||
|
||||
new Mark($ctx1[0]).markRanges(ranges, {
|
||||
'each': each,
|
||||
'done': function() {
|
||||
new Mark($ctx2[0]).markRanges([
|
||||
{ start: 10, length: 0 },
|
||||
{ start: 20, length: 0 },
|
||||
{ start: 30, length: 0.6 }
|
||||
], {
|
||||
'noMatch': function(item) {
|
||||
notFound = notFound.concat(item);
|
||||
},
|
||||
'each': each,
|
||||
'done': done
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should mark correct range', function() {
|
||||
var $match = $ctx1.find('mark:eq(0)'),
|
||||
range = getRange($ctx1, terms[0]);
|
||||
expect($match.text()).toBe(terms[0]);
|
||||
expect($match.attr('data-range-start')).toBe(range.start.toString());
|
||||
expect($match.attr('data-range-length')).toBe(range.length.toString());
|
||||
// extra mark around <br>
|
||||
expect($ctx1.find('mark')).toHaveLength(4);
|
||||
});
|
||||
it('should mark correct range including spaces and breaks', function() {
|
||||
var range = getRange($ctx1, terms[1]),
|
||||
$match = $ctx1.find('mark[data-range-start=\'' + range.start + '\']');
|
||||
expect($match.text()).toBe(terms[1]);
|
||||
expect($match.attr('data-range-start')).toBe(range.start.toString());
|
||||
expect($match.attr('data-range-length')).toBe(range.length.toString());
|
||||
});
|
||||
it('should mark and parse integer ranges', function() {
|
||||
var $match,
|
||||
range = getRange($ctx1, terms[2]);
|
||||
$match = $ctx1.find('mark[data-range-start=\'' + range.start + '\']');
|
||||
expect($match.text()).toBe(terms[2]);
|
||||
expect($match.attr('data-range-length')).toBe(range.length.toString());
|
||||
});
|
||||
it('should ignore ranges with length of zero', function() {
|
||||
expect(JSON.stringify(notFound)).toBe(JSON.stringify([
|
||||
{ start: 10, length: 0 },
|
||||
{ start: 20, length: 0 },
|
||||
{ start: 30, length: 0.6 }
|
||||
]));
|
||||
});
|
||||
});
|
87
node_modules/mark.js/test/specs/ranges/no-match.js
generated
vendored
Normal file
87
node_modules/mark.js/test/specs/ranges/no-match.js
generated
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
'use strict';
|
||||
describe('mark with range no matches', function() {
|
||||
var $ctx1, $ctx2, $ctx3, errCall, notFound;
|
||||
beforeEach(function(done) {
|
||||
loadFixtures('ranges/no-match.html');
|
||||
|
||||
errCall = 0;
|
||||
notFound = [];
|
||||
$ctx1 = $('.ranges-no-match > div:nth-child(1)');
|
||||
$ctx2 = $('.ranges-no-match > div:nth-child(2)');
|
||||
$ctx3 = $('.ranges-no-match > div:nth-child(3)');
|
||||
new Mark($ctx1[0]).markRanges([
|
||||
{ start: -20, length: -12 },
|
||||
// { start: 0, length: 3 } "should" only contain whitespace, so it
|
||||
// will be skipped
|
||||
{ start: 0, length: 3 },
|
||||
// found
|
||||
{ start: 30, length: 5},
|
||||
// skipped
|
||||
{ start: 1500, length: 500 }
|
||||
], {
|
||||
'noMatch': function(item) {
|
||||
notFound = notFound.concat(item);
|
||||
},
|
||||
'done': function() {
|
||||
new Mark($ctx2[0]).markRanges([
|
||||
{ start: -8, length: 5 },
|
||||
{ start: -1, length: 20 }
|
||||
], {
|
||||
'noMatch': function(item) {
|
||||
notFound = notFound.concat(item);
|
||||
},
|
||||
'done': function() {
|
||||
new Mark($ctx3[0]).markRanges([
|
||||
{ start: 99, length: 9999 }
|
||||
], {
|
||||
'each': function(node, range) {
|
||||
$(node).attr({
|
||||
'data-range-start': range.start,
|
||||
'data-range-length': range.length
|
||||
});
|
||||
},
|
||||
'noMatch': function(item) {
|
||||
notFound = notFound.concat(item);
|
||||
},
|
||||
'done': function() {
|
||||
// non-array first element shows an error
|
||||
new Mark($ctx3[0]).markRanges(['pie'], {
|
||||
'noMatch': function(item) {
|
||||
errCall++;
|
||||
notFound = notFound.concat(item);
|
||||
},
|
||||
'done': done
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should report each range non-match', function() {
|
||||
expect($ctx1.find('mark')).toHaveLength(1);
|
||||
expect($ctx2.find('mark')).toHaveLength(0);
|
||||
var ranges = notFound.sort(function(a, b) {
|
||||
return a[0] - b[0];
|
||||
});
|
||||
expect(JSON.stringify(ranges)).toEqual(JSON.stringify([
|
||||
{ start: -20, length: -12 },
|
||||
{ start: 0, length: 3 },
|
||||
{ start: 1500, length: 500 },
|
||||
{ start: -8, length: 5 },
|
||||
{ start: -1, length: 20 },
|
||||
'pie'
|
||||
]));
|
||||
expect(errCall).toBe(1);
|
||||
});
|
||||
it('should allow out of range max', function() {
|
||||
var $mark3 = $ctx3.find('mark');
|
||||
// using 2 because the closing </p> gets wrapped creating a second mark
|
||||
expect($mark3).toHaveLength(2);
|
||||
expect($mark3.attr('data-range-start')).toBe('99');
|
||||
// end range does not get adjusted
|
||||
expect($mark3.attr('data-range-length')).toBe('9999');
|
||||
});
|
||||
});
|
27
node_modules/mark.js/test/specs/ranges/overlap.js
generated
vendored
Normal file
27
node_modules/mark.js/test/specs/ranges/overlap.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
describe('mark ranges ignoring overlapping values', function() {
|
||||
var $ctx;
|
||||
beforeEach(function(done) {
|
||||
loadFixtures('ranges/overlap.html');
|
||||
|
||||
$ctx = $('.ranges-overlap');
|
||||
new Mark($ctx[0]).markRanges([
|
||||
{ start: 0, length: 30 },
|
||||
{ start: 25, length: 1 },
|
||||
{ start: 40, length: 10 },
|
||||
{ start: 45, length: 1 }
|
||||
], {
|
||||
'each': function(node, range) {
|
||||
$(node).attr('data-range-start', range.start);
|
||||
},
|
||||
'done': done
|
||||
});
|
||||
});
|
||||
|
||||
it('should ignore overlapping ranges', function() {
|
||||
// length = 3 because whitespace before the <p> is wrapped
|
||||
expect($ctx.find('mark')).toHaveLength(3);
|
||||
expect($ctx.find('mark[data-range-start=25]')).toHaveLength(0);
|
||||
expect($ctx.find('mark[data-range-start=45]')).toHaveLength(0);
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user