devstar插件
This commit is contained in:
29
node_modules/mark.js/test/specs/regexp/done.js
generated
vendored
Normal file
29
node_modules/mark.js/test/specs/regexp/done.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
describe('mark with regular expression and done callback', function() {
|
||||
var $ctx, doneCalled, totalMatches;
|
||||
beforeEach(function(done) {
|
||||
loadFixtures('regexp/main.html');
|
||||
|
||||
totalMatches = doneCalled = 0;
|
||||
$ctx = $('.regexp > div:first-child');
|
||||
new Mark($ctx[0]).markRegExp(/lorem/gmi, {
|
||||
'diacritics': false,
|
||||
'separateWordSearch': false,
|
||||
'done': function(counter) {
|
||||
doneCalled++;
|
||||
totalMatches = counter;
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should call the done callback once only', function(done) {
|
||||
setTimeout(function() {
|
||||
expect(doneCalled).toBe(1);
|
||||
done();
|
||||
}, 3000);
|
||||
});
|
||||
it('should call the done callback with total matches', function() {
|
||||
expect(totalMatches).toBe(4);
|
||||
});
|
||||
});
|
31
node_modules/mark.js/test/specs/regexp/filter.js
generated
vendored
Normal file
31
node_modules/mark.js/test/specs/regexp/filter.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
describe('mark with regular expression and filter callback', function() {
|
||||
var $ctx;
|
||||
beforeEach(function() {
|
||||
loadFixtures('regexp/filter.html');
|
||||
|
||||
$ctx = $('.regexp-filter');
|
||||
});
|
||||
|
||||
it('should call the callback with the right parameters', function(done) {
|
||||
var k = 0,
|
||||
textOpts = ['Lorem', 'ipsum'];
|
||||
new Mark($ctx[0]).markRegExp(/(Lore?m)|(ipsum)/gmi, {
|
||||
'filter': function(node, term, totalMatches) {
|
||||
expect(node.nodeType).toBe(3);
|
||||
expect($.inArray(term, textOpts)).toBeGreaterThan(-1);
|
||||
expect(k).toBe(totalMatches);
|
||||
if (term !== 'ipsum') {
|
||||
k++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'done': function() {
|
||||
expect($ctx.find('mark')).toHaveLength(4);
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
31
node_modules/mark.js/test/specs/regexp/ignore-groups.js
generated
vendored
Normal file
31
node_modules/mark.js/test/specs/regexp/ignore-groups.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
describe('mark with regular expression and ignoreGroups', function() {
|
||||
var $ctx1, $ctx2;
|
||||
beforeEach(function(done) {
|
||||
loadFixtures('regexp/ignore-groups.html');
|
||||
|
||||
$ctx1 = $('.regexp-ignore-groups > div:first-child');
|
||||
$ctx2 = $('.regexp-ignore-groups > div:last-child');
|
||||
new Mark($ctx1[0]).markRegExp(/(Lor)([^]?m[\s]*)(ipsum)/gmi, {
|
||||
'done': function() {
|
||||
new Mark($ctx2[0]).markRegExp(/(Lor)([^]?m[\s]*)(ipsum)/gmi, {
|
||||
'ignoreGroups': 2,
|
||||
'done': done
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should silently ignore groups when disabled', function() {
|
||||
expect($ctx1.find('mark')).toHaveLength(4);
|
||||
$ctx1.find('mark').each(function() {
|
||||
expect($(this).text()).toBe('Lorem ipsum');
|
||||
});
|
||||
});
|
||||
it('should ignore specified groups when enabled', function() {
|
||||
expect($ctx2.find('mark')).toHaveLength(4);
|
||||
$ctx2.find('mark').each(function() {
|
||||
expect($(this).text()).toBe('ipsum');
|
||||
});
|
||||
});
|
||||
});
|
38
node_modules/mark.js/test/specs/regexp/infinite.js
generated
vendored
Normal file
38
node_modules/mark.js/test/specs/regexp/infinite.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
describe('mark with regular expression with infinite results', function() {
|
||||
var $ctx1, $ctx2, errorThrown1, errorThrown2;
|
||||
beforeEach(function(done) {
|
||||
loadFixtures('regexp/infinite.html');
|
||||
|
||||
$ctx1 = $('.regexp-infinite > div:first-child');
|
||||
$ctx2 = $('.regexp-infinite > div:last-child');
|
||||
errorThrown1 = errorThrown2 = false;
|
||||
try {
|
||||
new Mark($ctx1[0]).markRegExp(/(|)/gmi, {
|
||||
'done': function() {
|
||||
try {
|
||||
new Mark($ctx2[0]).markRegExp(/\b/gmi, {
|
||||
'done': done
|
||||
});
|
||||
} catch (e) {
|
||||
errorThrown2 = true;
|
||||
done();
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
errorThrown1 = true;
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it(
|
||||
'should not mark regular expressions with infinite matches',
|
||||
function() {
|
||||
expect(errorThrown1).toBe(false);
|
||||
expect(errorThrown2).toBe(false);
|
||||
expect($ctx1.find('mark')).toHaveLength(0);
|
||||
expect($ctx2.find('mark')).toHaveLength(0);
|
||||
}
|
||||
);
|
||||
});
|
40
node_modules/mark.js/test/specs/regexp/jquery.js
generated
vendored
Normal file
40
node_modules/mark.js/test/specs/regexp/jquery.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
'use strict';
|
||||
describe('mark with regular expression called with jquery', function() {
|
||||
var $ctx1, $ctx2, errorThrown, ret;
|
||||
beforeEach(function(done) {
|
||||
loadFixtures('regexp/main.html');
|
||||
|
||||
$ctx1 = $('.regexp > div:first-child');
|
||||
$ctx2 = $('.regexp > div:last-child');
|
||||
errorThrown = false;
|
||||
ret = $ctx1.markRegExp(/Lor[^]?m/gmi, {
|
||||
'done': function() {
|
||||
try {
|
||||
$ctx2.markRegExp(/(Lor)([^]?m)/gmi, {
|
||||
'done': function() {
|
||||
// timeout, otherwise "ret =" will not be executed
|
||||
setTimeout(function() {
|
||||
done();
|
||||
}, 50);
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
errorThrown = true;
|
||||
done();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should wrap matches', function() {
|
||||
expect($ctx1.find('mark')).toHaveLength(4);
|
||||
});
|
||||
it('should silently ignore groups in regular expression', function() {
|
||||
expect($ctx2.find('mark')).toHaveLength(4);
|
||||
expect(errorThrown).toBe(false);
|
||||
});
|
||||
it('should return the provided context jquery element', function() {
|
||||
expect(ret instanceof $).toBe(true);
|
||||
expect(ret).toBeMatchedBy('.regexp > div:first-child');
|
||||
});
|
||||
});
|
42
node_modules/mark.js/test/specs/regexp/main.js
generated
vendored
Normal file
42
node_modules/mark.js/test/specs/regexp/main.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
'use strict';
|
||||
describe('mark with regular expression', function() {
|
||||
var $ctx1, $ctx2, errorThrown, ret;
|
||||
beforeEach(function(done) {
|
||||
loadFixtures('regexp/main.html');
|
||||
|
||||
$ctx1 = $('.regexp > div:first-child');
|
||||
$ctx2 = $('.regexp > div:last-child');
|
||||
errorThrown = false;
|
||||
ret = new Mark($ctx1[0]).markRegExp(/Lor[^]?m/gmi, {
|
||||
'done': function() {
|
||||
try {
|
||||
new Mark($ctx2[0]).markRegExp(/(Lor)([^]?m)/gmi, {
|
||||
'done': function() {
|
||||
// timeout, otherwise "ret =" will not be executed
|
||||
setTimeout(function() {
|
||||
done();
|
||||
}, 50);
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
errorThrown = true;
|
||||
done();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should wrap matches', function() {
|
||||
expect($ctx1.find('mark')).toHaveLength(4);
|
||||
});
|
||||
it('should silently ignore groups in regular expressions', function() {
|
||||
expect($ctx2.find('mark')).toHaveLength(4);
|
||||
expect(errorThrown).toBe(false);
|
||||
});
|
||||
it('should return an object with further methods', function() {
|
||||
expect(ret instanceof Mark).toBe(true);
|
||||
expect(typeof ret.mark).toBe('function');
|
||||
expect(typeof ret.unmark).toBe('function');
|
||||
expect(typeof ret.markRegExp).toBe('function');
|
||||
});
|
||||
});
|
25
node_modules/mark.js/test/specs/regexp/no-match.js
generated
vendored
Normal file
25
node_modules/mark.js/test/specs/regexp/no-match.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
describe('mark with regular expression and noMatch callback', function() {
|
||||
var $ctx, notFound, notFoundCalled;
|
||||
beforeEach(function(done) {
|
||||
loadFixtures('regexp/main.html');
|
||||
|
||||
$ctx = $('.regexp > div:first-child');
|
||||
notFound = null;
|
||||
notFoundCalled = 0;
|
||||
new Mark($ctx[0]).markRegExp(/test/gmi, {
|
||||
'noMatch': function(regexp) {
|
||||
notFoundCalled++;
|
||||
notFound = regexp;
|
||||
},
|
||||
'done': function() {
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should call noMatch with the regular expression', function() {
|
||||
expect(notFoundCalled).toBe(1);
|
||||
expect(notFound instanceof RegExp).toBe(true);
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user