Comparing version 0.0.3 to 0.1.0
@@ -11,9 +11,4 @@ /** | ||
matcher = new Qlobber(); | ||
matcher.add('foo.*', 'it matched!', function () | ||
{ | ||
matcher.match('foo.bar', function (err, vals) | ||
{ | ||
assert.deepEqual(vals, ['it matched!']); | ||
}); | ||
}); | ||
matcher.add('foo.*', 'it matched!'); | ||
assert.deepEqual(matcher.match('foo.bar'), ['it matched!']); | ||
``` | ||
@@ -36,30 +31,23 @@ | ||
```javascript | ||
async.parallel( | ||
[matcher.add.bind(matcher, '*.orange.*', 'Q1'), | ||
matcher.add.bind(matcher, '*.*.rabbit', 'Q2'), | ||
matcher.add.bind(matcher, 'lazy.#', 'Q2')], | ||
async.mapSeries.bind(async, | ||
['quick.orange.rabbit', | ||
'lazy.orange.elephant', | ||
'quick.orange.fox', | ||
'lazy.brown.fox', | ||
'lazy.pink.rabbit', | ||
'quick.brown.fox', | ||
'orange', | ||
'quick.orange.male.rabbit', | ||
'lazy.orange.male.rabbit'], | ||
matcher.match, | ||
function (err, vals) | ||
{ | ||
assert.deepEqual(vals, | ||
[['Q1', 'Q2'], | ||
['Q1', 'Q2'], | ||
['Q1'], | ||
['Q2'], | ||
['Q2'], | ||
[], | ||
[], | ||
[], | ||
['Q2']]); | ||
})); | ||
matcher.add('*.orange.*', 'Q1'); | ||
matcher.add('*.*.rabbit', 'Q2'); | ||
matcher.add('lazy.#', 'Q2'); | ||
assert.deepEqual(['quick.orange.rabbit', | ||
'lazy.orange.elephant', | ||
'quick.orange.fox', | ||
'lazy.brown.fox', | ||
'lazy.pink.rabbit', | ||
'quick.brown.fox', | ||
'orange', | ||
'quick.orange.male.rabbit', | ||
'lazy.orange.male.rabbit'].map(matcher.match), | ||
[['Q1', 'Q2'], | ||
['Q1', 'Q2'], | ||
['Q1'], | ||
['Q2'], | ||
['Q2'], | ||
[], | ||
[], | ||
[], | ||
['Q2']]); | ||
``` | ||
@@ -93,4 +81,2 @@ | ||
var async = require('async'); | ||
/** | ||
@@ -120,3 +106,3 @@ Creates a new qlobber. | ||
add = function (val, i, words, sub_trie, cb) | ||
add = function (val, i, words, sub_trie) | ||
{ | ||
@@ -129,3 +115,2 @@ var st, word; | ||
st.push(val); | ||
process.nextTick(cb); | ||
return; | ||
@@ -135,11 +120,10 @@ } | ||
word = words[i]; | ||
st = sub_trie[word] = (sub_trie[word] || {}); | ||
process.nextTick(add.bind(this, val, i + 1, words, st, cb)); | ||
add(val, i + 1, words, st); | ||
}, | ||
remove = function (val, i, words, sub_trie, cb) | ||
remove = function (val, i, words, sub_trie) | ||
{ | ||
var word, st, index; | ||
var st, index, word; | ||
@@ -172,3 +156,2 @@ if (i === words.length) | ||
process.nextTick(cb); | ||
return; | ||
@@ -182,33 +165,21 @@ } | ||
{ | ||
process.nextTick(cb); | ||
return; | ||
} | ||
process.nextTick(remove.bind(this, val, i + 1, words, st, function () | ||
remove(val, i + 1, words, st); | ||
for (word in st) | ||
{ | ||
var w, st = sub_trie[word]; | ||
if (!st) | ||
if (st.hasOwnProperty(word)) | ||
{ | ||
process.nextTick(cb); | ||
return; | ||
} | ||
} | ||
for (w in st) | ||
{ | ||
if (st.hasOwnProperty(w)) | ||
{ | ||
process.nextTick(cb); | ||
return; | ||
} | ||
} | ||
delete sub_trie[word]; | ||
process.nextTick(cb); | ||
})); | ||
delete sub_trie[word]; | ||
}, | ||
match = function (i, words, sub_trie, cb) | ||
match = function (i, words, sub_trie) | ||
{ | ||
var word, st, sts = [], w, j, done = cb; | ||
var word, st, sts = [], w, j, iv = []; | ||
@@ -245,6 +216,3 @@ st = sub_trie[wildcard_some]; | ||
{ | ||
done = function (st, err, r) | ||
{ | ||
cb(err, st.concat(r)); | ||
}.bind(this, st); | ||
iv = st; | ||
} | ||
@@ -277,9 +245,6 @@ } | ||
process.nextTick(async.concat.bind(this, sts, function (st, cb) | ||
return sts.reduce(function(v, st) | ||
{ | ||
match(st.i, words, st.st, cb); | ||
}, function (err, r) | ||
{ | ||
process.nextTick(done.bind(this, err, r)); | ||
})); | ||
return v.concat(match(st.i, words, st.st)); | ||
}, iv); | ||
}; | ||
@@ -294,7 +259,6 @@ | ||
@param {Any} val The value to return if the topic is matched. `undefined` is not supported. | ||
@param {Function} cb Called when the matcher has been added. | ||
*/ | ||
QlobberObject.add = function (topic, val, cb) | ||
QlobberObject.add = function (topic, val) | ||
{ | ||
add(val, 0, topic.split(separator), trie, cb); | ||
add(val, 0, topic.split(separator), trie); | ||
}; | ||
@@ -307,13 +271,12 @@ | ||
@param {Any} [val] The value that's being matched. If you don't specify `val` then all matchers for `topic` are removed. | ||
@param {Function} cb Called when the matcher has been removed. | ||
*/ | ||
QlobberObject.remove = function (topic, val, cb) | ||
QlobberObject.remove = function (topic, val) | ||
{ | ||
if (arguments.length === 2) | ||
if (arguments.length === 1) | ||
{ | ||
remove(undefined, 0, topic.split(separator), trie, val); | ||
remove(undefined, 0, topic.split(separator), trie); | ||
} | ||
else | ||
{ | ||
remove(val, 0, topic.split(separator), trie, cb); | ||
remove(val, 0, topic.split(separator), trie); | ||
} | ||
@@ -326,30 +289,24 @@ }; | ||
@param {String} topic The topic to match against. | ||
@param {Function} cb Called with two arguments when the match has completed: | ||
- `{Any} err` `null` or an error, if one occurred. | ||
- `{Array} vals` List of values that matched the topic. `vals` will be sorted and have duplicates removed unless you configured [Qlobber](#qlobberoptions) otherwise. | ||
@return {Array} List of values that matched the topic. This will be sorted and have duplicates removed unless you configured [Qlobber](#qlobberoptions) otherwise. | ||
*/ | ||
QlobberObject.match = function (topic, cb) | ||
QlobberObject.match = function (topic) | ||
{ | ||
/*jslint unparam: true */ | ||
match(0, topic.split(separator), trie, function (err, r) | ||
var r = match(0, topic.split(separator), trie); | ||
if (options.compare !== false) | ||
{ | ||
if (options.compare !== false) | ||
r = r.sort(options.compare).reduce(function (prev, cur) | ||
{ | ||
r = r.sort(options.compare).reduce(function (prev, cur) | ||
if (prev[prev.length - 1] !== cur) | ||
{ | ||
if (prev[prev.length - 1] !== cur) | ||
{ | ||
prev.push(cur); | ||
} | ||
prev.push(cur); | ||
} | ||
return prev; | ||
}, [undefined]); | ||
return prev; | ||
}, [undefined]); | ||
r.shift(); | ||
} | ||
r.shift(); | ||
} | ||
cb(null, r); | ||
}); | ||
/*jslint unparam: false */ | ||
return r; | ||
}; | ||
@@ -361,9 +318,6 @@ | ||
Removes all topic matchers from the qlobber. | ||
@param {Function} cb Called when the qlobber has been reset. | ||
*/ | ||
QlobberObject.clear = function (cb) | ||
QlobberObject.clear = function () | ||
{ | ||
trie = {}; | ||
cb(); | ||
}; | ||
@@ -370,0 +324,0 @@ |
{ | ||
"name": "qlobber", | ||
"description": "Node.js globbing for amqp-like topics", | ||
"version": "0.0.3", | ||
"version": "0.1.0", | ||
"homepage": "https://github.com/davedoesdev/qlobber", | ||
@@ -39,5 +39,2 @@ "author": { | ||
], | ||
"dependencies": { | ||
"async": "~0.2.9" | ||
}, | ||
"devDependencies": { | ||
@@ -44,0 +41,0 @@ "grunt": "~0.4.1", |
@@ -10,9 +10,4 @@ # qlobber [![Build Status](https://travis-ci.org/davedoesdev/qlobber.png)](https://travis-ci.org/davedoesdev/qlobber) | ||
matcher = new Qlobber(); | ||
matcher.add('foo.*', 'it matched!', function () | ||
{ | ||
matcher.match('foo.bar', function (err, vals) | ||
{ | ||
assert.deepEqual(vals, ['it matched!']); | ||
}); | ||
}); | ||
matcher.add('foo.*', 'it matched!'); | ||
assert.deepEqual(matcher.match('foo.bar'), ['it matched!']); | ||
``` | ||
@@ -35,30 +30,23 @@ | ||
```javascript | ||
async.parallel( | ||
[matcher.add.bind(matcher, '*.orange.*', 'Q1'), | ||
matcher.add.bind(matcher, '*.*.rabbit', 'Q2'), | ||
matcher.add.bind(matcher, 'lazy.#', 'Q2')], | ||
async.mapSeries.bind(async, | ||
['quick.orange.rabbit', | ||
'lazy.orange.elephant', | ||
'quick.orange.fox', | ||
'lazy.brown.fox', | ||
'lazy.pink.rabbit', | ||
'quick.brown.fox', | ||
'orange', | ||
'quick.orange.male.rabbit', | ||
'lazy.orange.male.rabbit'], | ||
matcher.match, | ||
function (err, vals) | ||
{ | ||
assert.deepEqual(vals, | ||
[['Q1', 'Q2'], | ||
['Q1', 'Q2'], | ||
['Q1'], | ||
['Q2'], | ||
['Q2'], | ||
[], | ||
[], | ||
[], | ||
['Q2']]); | ||
})); | ||
matcher.add('*.orange.*', 'Q1'); | ||
matcher.add('*.*.rabbit', 'Q2'); | ||
matcher.add('lazy.#', 'Q2'); | ||
assert.deepEqual(['quick.orange.rabbit', | ||
'lazy.orange.elephant', | ||
'quick.orange.fox', | ||
'lazy.brown.fox', | ||
'lazy.pink.rabbit', | ||
'quick.brown.fox', | ||
'orange', | ||
'quick.orange.male.rabbit', | ||
'lazy.orange.male.rabbit'].map(matcher.match), | ||
[['Q1', 'Q2'], | ||
['Q1', 'Q2'], | ||
['Q1'], | ||
['Q2'], | ||
['Q2'], | ||
[], | ||
[], | ||
[], | ||
['Q2']]); | ||
``` | ||
@@ -93,6 +81,6 @@ | ||
- <a name="toc_qlobberoptions"></a>[Qlobber](#qlobberoptions) | ||
- <a name="toc_qlobberobjectaddtopic-val-cb"></a><a name="toc_qlobberobject"></a>[QlobberObject.add](#qlobberobjectaddtopic-val-cb) | ||
- <a name="toc_qlobberobjectremovetopic-val-cb"></a>[QlobberObject.remove](#qlobberobjectremovetopic-val-cb) | ||
- <a name="toc_qlobberobjectmatchtopic-cb"></a>[QlobberObject.match](#qlobberobjectmatchtopic-cb) | ||
- <a name="toc_qlobberobjectclearcb"></a>[QlobberObject.clear](#qlobberobjectclearcb) | ||
- <a name="toc_qlobberobjectaddtopic-val"></a><a name="toc_qlobberobject"></a>[QlobberObject.add](#qlobberobjectaddtopic-val) | ||
- <a name="toc_qlobberobjectremovetopic-val"></a>[QlobberObject.remove](#qlobberobjectremovetopic-val) | ||
- <a name="toc_qlobberobjectmatchtopic"></a>[QlobberObject.match](#qlobberobjectmatchtopic) | ||
- <a name="toc_qlobberobjectclear"></a>[QlobberObject.clear](#qlobberobjectclear) | ||
@@ -120,3 +108,3 @@ # Qlobber([options]) | ||
# QlobberObject.add(topic, val, cb) | ||
# QlobberObject.add(topic, val) | ||
@@ -131,7 +119,6 @@ > Add a topic matcher to the qlobber. | ||
- `{Any} val` The value to return if the topic is matched. `undefined` is not supported. | ||
- `{Function} cb` Called when the matcher has been added. | ||
<sub>Go: [TOC](#tableofcontents) | [QlobberObject](#toc_qlobberobject)</sub> | ||
# QlobberObject.remove(topic, [val], cb) | ||
# QlobberObject.remove(topic, [val]) | ||
@@ -144,7 +131,6 @@ > Remove a topic matcher from the qlobber. | ||
- `{Any} [val]` The value that's being matched. If you don't specify `val` then all matchers for `topic` are removed. | ||
- `{Function} cb` Called when the matcher has been removed. | ||
<sub>Go: [TOC](#tableofcontents) | [QlobberObject](#toc_qlobberobject)</sub> | ||
# QlobberObject.match(topic, cb) | ||
# QlobberObject.match(topic) | ||
@@ -156,11 +142,10 @@ > Match a topic. | ||
- `{String} topic` The topic to match against. | ||
- `{Function} cb` Called with two arguments when the match has completed: | ||
**Return:** | ||
- `{Any} err` `null` or an error, if one occurred. | ||
- `{Array} vals` List of values that matched the topic. `vals` will be sorted and have duplicates removed unless you configured [Qlobber](#qlobberoptions) otherwise. | ||
`{Array}` List of values that matched the topic. This will be sorted and have duplicates removed unless you configured [Qlobber](#qlobberoptions) otherwise. | ||
<sub>Go: [TOC](#tableofcontents) | [QlobberObject](#toc_qlobberobject)</sub> | ||
# QlobberObject.clear(cb) | ||
# QlobberObject.clear() | ||
@@ -171,8 +156,4 @@ > Reset the qlobber. | ||
**Parameters:** | ||
- `{Function} cb` Called when the qlobber has been reset. | ||
<sub>Go: [TOC](#tableofcontents) | [QlobberObject](#toc_qlobberobject)</sub> | ||
_—generated by [apidox](https://github.com/codeactual/apidox)—_ |
@@ -5,2 +5,3 @@ /*globals rabbitmq_test_bindings : false, | ||
rabbitmq_expected_results_after_remove : false, | ||
rabbitmq_expected_results_after_remove_all : false, | ||
rabbitmq_expected_results_after_clear : false, | ||
@@ -13,4 +14,3 @@ describe: false, | ||
var async = require('async'), | ||
expect = require('chai').expect, | ||
var expect = require('chai').expect, | ||
qlobber = require('..'); | ||
@@ -28,138 +28,96 @@ | ||
function add_bindings(bindings, in_series, mapper, done) | ||
function add_bindings(bindings, mapper) | ||
{ | ||
var each = in_series ? async.eachSeries : async.each; | ||
mapper = mapper || function (topic) { return topic; }; | ||
mapper = mapper || function (topic) | ||
bindings.forEach(function (topic_val) | ||
{ | ||
return topic; | ||
}; | ||
each(bindings, function (topic_val, cb) | ||
{ | ||
matcher.add(topic_val[0], mapper(topic_val[1]), cb); | ||
}, done); | ||
matcher.add(topic_val[0], mapper(topic_val[1])); | ||
}); | ||
} | ||
it('should support adding bindings', function (done) | ||
it('should support adding bindings', function () | ||
{ | ||
add_bindings(rabbitmq_test_bindings, true, null, function () | ||
{ | ||
expect(matcher.get_trie()).to.eql({"a":{"b":{"c":{".":["t1","t20"]},"b":{"c":{".":["t4"]},".":["t14"]},".":["t15"]},"*":{"c":{".":["t2"]},".":["t9"]},"#":{"b":{".":["t3"]},".":["t11"],"#":{".":["t12"]}}},"#":{".":["t5"],"#":{".":["t6"],"#":{".":["t24"]}},"b":{".":["t7"],"#":{".":["t26"]}},"*":{"#":{".":["t22"]}}},"*":{"*":{".":["t8"],"*":{".":["t18"]}},"b":{"c":{".":["t10"]}},"#":{".":["t21"],"#":{".":["t23"]}},".":["t25"]},"b":{"b":{"c":{".":["t13"]}},"c":{".":["t16"]}},"":{".":["t17"]},"vodka":{"martini":{".":["t19"]}}}); | ||
done(); | ||
}); | ||
add_bindings(rabbitmq_test_bindings); | ||
expect(matcher.get_trie()).to.eql({"a":{"b":{"c":{".":["t1","t20"]},"b":{"c":{".":["t4"]},".":["t14"]},".":["t15"]},"*":{"c":{".":["t2"]},".":["t9"]},"#":{"b":{".":["t3"]},".":["t11"],"#":{".":["t12"]}}},"#":{".":["t5"],"#":{".":["t6"],"#":{".":["t24"]}},"b":{".":["t7"],"#":{".":["t26"]}},"*":{"#":{".":["t22"]}}},"*":{"*":{".":["t8"],"*":{".":["t18"]}},"b":{"c":{".":["t10"]}},"#":{".":["t21"],"#":{".":["t23"]}},".":["t25"]},"b":{"b":{"c":{".":["t13"]}},"c":{".":["t16"]}},"":{".":["t17"]},"vodka":{"martini":{".":["t19"]}}}); | ||
}); | ||
it('should pass rabbitmq test', function (done) | ||
it('should pass rabbitmq test', function () | ||
{ | ||
add_bindings(rabbitmq_test_bindings, false, null, function () | ||
add_bindings(rabbitmq_test_bindings); | ||
rabbitmq_expected_results_before_remove.forEach(function (test) | ||
{ | ||
async.each(rabbitmq_expected_results_before_remove, function (test, cb) | ||
{ | ||
/*jslint unparam: true */ | ||
matcher.match(test[0], function (err, vals) | ||
{ | ||
expect(vals, test[0]).to.eql(test[1].sort()); | ||
cb(); | ||
}); | ||
}, done); | ||
expect(matcher.match(test[0]), test[0]).to.eql(test[1].sort()); | ||
}); | ||
}); | ||
it('should support removing bindings', function (done) | ||
it('should support removing bindings', function () | ||
{ | ||
add_bindings(rabbitmq_test_bindings, false, null, function () | ||
add_bindings(rabbitmq_test_bindings); | ||
rabbitmq_bindings_to_remove.forEach(function (i) | ||
{ | ||
async.each(rabbitmq_bindings_to_remove, function (i, cb) | ||
{ | ||
matcher.remove(rabbitmq_test_bindings[i-1][0], | ||
rabbitmq_test_bindings[i-1][1], | ||
cb); | ||
}, function () | ||
{ | ||
expect(matcher.get_trie()).to.eql({"a":{"b":{"c":{".":["t20"]},"b":{"c":{".":["t4"]},".":["t14"]},".":["t15"]},"*":{"c":{".":["t2"]},".":["t9"]},"#":{"b":{".":["t3"]},"#":{".":["t12"]}}},"#":{"#":{".":["t6"],"#":{".":["t24"]}},"b":{".":["t7"],"#":{".":["t26"]}},"*":{"#":{".":["t22"]}}},"*":{"*":{".":["t8"],"*":{".":["t18"]}},"b":{"c":{".":["t10"]}},"#":{"#":{".":["t23"]}},".":["t25"]},"b":{"b":{"c":{".":["t13"]}},"c":{".":["t16"]}},"":{".":["t17"]}}); | ||
matcher.remove(rabbitmq_test_bindings[i-1][0], | ||
rabbitmq_test_bindings[i-1][1]); | ||
}); | ||
async.each(rabbitmq_expected_results_after_remove, function (test, cb) | ||
{ | ||
/*jslint unparam: true */ | ||
matcher.match(test[0], function (err, vals) | ||
{ | ||
expect(vals, test[0]).to.eql(test[1].sort()); | ||
cb(); | ||
}); | ||
}, function () | ||
{ | ||
/*jslint unparam: true */ | ||
var remaining = rabbitmq_test_bindings.filter( | ||
function (topic_val, i) | ||
{ | ||
return rabbitmq_bindings_to_remove.indexOf(i + 1) < 0; | ||
}); | ||
/*jslint unparam: false */ | ||
expect(matcher.get_trie()).to.eql({"a":{"b":{"c":{".":["t20"]},"b":{"c":{".":["t4"]},".":["t14"]},".":["t15"]},"*":{"c":{".":["t2"]},".":["t9"]},"#":{"b":{".":["t3"]},"#":{".":["t12"]}}},"#":{"#":{".":["t6"],"#":{".":["t24"]}},"b":{".":["t7"],"#":{".":["t26"]}},"*":{"#":{".":["t22"]}}},"*":{"*":{".":["t8"],"*":{".":["t18"]}},"b":{"c":{".":["t10"]}},"#":{"#":{".":["t23"]}},".":["t25"]},"b":{"b":{"c":{".":["t13"]}},"c":{".":["t16"]}},"":{".":["t17"]}}); | ||
async.each(remaining, function (topic_val, cb) | ||
{ | ||
matcher.remove(topic_val[0], topic_val[1], cb); | ||
}, function () | ||
{ | ||
expect(matcher.get_trie()).to.eql({}); | ||
rabbitmq_expected_results_after_remove.forEach(function (test) | ||
{ | ||
expect(matcher.match(test[0]), test[0]).to.eql(test[1].sort()); | ||
}); | ||
/*jslint unparam: true */ | ||
var remaining = rabbitmq_test_bindings.filter(function (topic_val, i) | ||
{ | ||
return rabbitmq_bindings_to_remove.indexOf(i + 1) < 0; | ||
}); | ||
/*jslint unparam: false */ | ||
async.each(rabbitmq_expected_results_after_clear, function (test, cb) | ||
{ | ||
/*jslint unparam: true */ | ||
matcher.match(test[0], function (err, vals) | ||
{ | ||
expect(vals, test[0]).to.eql(test[1].sort()); | ||
cb(); | ||
}); | ||
}, done); | ||
}); | ||
}); | ||
}); | ||
remaining.forEach(function (topic_val) | ||
{ | ||
matcher.remove(topic_val[0], topic_val[1]); | ||
}); | ||
expect(matcher.get_trie()).to.eql({}); | ||
rabbitmq_expected_results_after_clear.forEach(function (test) | ||
{ | ||
expect(matcher.match(test[0]), test[0]).to.eql(test[1].sort()); | ||
}); | ||
}); | ||
it('should support clearing the bindings', function (done) | ||
it('should support clearing the bindings', function () | ||
{ | ||
add_bindings(rabbitmq_test_bindings, false, null, function () | ||
add_bindings(rabbitmq_test_bindings); | ||
matcher.clear(); | ||
rabbitmq_expected_results_after_clear.forEach(function (test) | ||
{ | ||
matcher.clear(function () | ||
{ | ||
async.each(rabbitmq_expected_results_after_clear, function (test, cb) | ||
{ | ||
/*jslint unparam: true */ | ||
matcher.match(test[0], function (err, vals) | ||
{ | ||
expect(vals, test[0]).to.eql(test[1].sort()); | ||
cb(); | ||
}); | ||
}, done); | ||
}); | ||
expect(matcher.match(test[0]), test[0]).to.eql(test[1].sort()); | ||
}); | ||
}); | ||
it('should support removing all values for a topic', function (done) | ||
it('should support removing all values for a topic', function () | ||
{ | ||
add_bindings(rabbitmq_test_bindings, false, null, function () | ||
add_bindings(rabbitmq_test_bindings); | ||
rabbitmq_bindings_to_remove.forEach(function (i) | ||
{ | ||
async.each(rabbitmq_bindings_to_remove, function (i, cb) | ||
{ | ||
matcher.remove(rabbitmq_test_bindings[i-1][0], cb); | ||
}, function () | ||
{ | ||
expect(matcher.get_trie()).to.eql({"a":{"b":{"b":{"c":{".":["t4"]},".":["t14"]},".":["t15"]},"*":{"c":{".":["t2"]},".":["t9"]},"#":{"b":{".":["t3"]},"#":{".":["t12"]}}},"#":{"#":{".":["t6"],"#":{".":["t24"]}},"b":{".":["t7"],"#":{".":["t26"]}},"*":{"#":{".":["t22"]}}},"*":{"*":{".":["t8"],"*":{".":["t18"]}},"b":{"c":{".":["t10"]}},"#":{"#":{".":["t23"]}},".":["t25"]},"b":{"b":{"c":{".":["t13"]}},"c":{".":["t16"]}},"":{".":["t17"]}}); | ||
matcher.remove(rabbitmq_test_bindings[i-1][0]); | ||
}); | ||
expect(matcher.get_trie()).to.eql({"a":{"b":{"b":{"c":{".":["t4"]},".":["t14"]},".":["t15"]},"*":{"c":{".":["t2"]},".":["t9"]},"#":{"b":{".":["t3"]},"#":{".":["t12"]}}},"#":{"#":{".":["t6"],"#":{".":["t24"]}},"b":{".":["t7"],"#":{".":["t26"]}},"*":{"#":{".":["t22"]}}},"*":{"*":{".":["t8"],"*":{".":["t18"]}},"b":{"c":{".":["t10"]}},"#":{"#":{".":["t23"]}},".":["t25"]},"b":{"b":{"c":{".":["t13"]}},"c":{".":["t16"]}},"":{".":["t17"]}}); | ||
async.each(rabbitmq_expected_results_after_remove_all, function (test, cb) | ||
{ | ||
matcher.match(test[0], function (err, vals) | ||
{ | ||
expect(vals, test[0]).to.eql(test[1].sort()); | ||
cb(); | ||
}); | ||
}, done); | ||
}); | ||
rabbitmq_expected_results_after_remove_all.forEach(function (test) | ||
{ | ||
expect(matcher.match(test[0]), test[0]).to.eql(test[1].sort()); | ||
}); | ||
}); | ||
it('should support functions as values', function (done) | ||
it('should support functions as values', function () | ||
{ | ||
@@ -174,4 +132,3 @@ matcher = new qlobber.Qlobber( | ||
add_bindings(rabbitmq_test_bindings, false, | ||
function (topic) | ||
add_bindings(rabbitmq_test_bindings, function (topic) | ||
{ | ||
@@ -186,65 +143,44 @@ var f = function () | ||
return f; | ||
}, | ||
function () | ||
}); | ||
rabbitmq_expected_results_before_remove.forEach(function (test) | ||
{ | ||
async.each(rabbitmq_expected_results_before_remove, function (test, cb) | ||
expect(matcher.match(test[0], test[0]).map(function (f) | ||
{ | ||
/*jslint unparam: true */ | ||
matcher.match(test[0], function (err, vals) | ||
{ | ||
expect(vals.map(function (f) { return f(); }), test[0]) | ||
.to.eql(test[1].sort()); | ||
cb(); | ||
}); | ||
}, done); | ||
return f(); | ||
})).to.eql(test[1].sort()); | ||
}); | ||
}); | ||
it('should pass example in README', function (done) | ||
it('should pass example in README', function () | ||
{ | ||
matcher.add('foo.*', 'Q1', function () | ||
{ | ||
/*jslint unparam: true */ | ||
matcher.match('foo.bar', function (err, vals) | ||
{ | ||
expect(vals).to.eql(['Q1']); | ||
done(); | ||
}); | ||
}); | ||
matcher.add('foo.*', 'it matched!'); | ||
expect(matcher.match('foo.bar')).to.eql(['it matched!']); | ||
}); | ||
it('should pass example in rabbitmq topic tutorial', function (done) | ||
it('should pass example in rabbitmq topic tutorial', function () | ||
{ | ||
/*jslint unparam: true */ | ||
async.parallel( | ||
[matcher.add.bind(matcher, '*.orange.*', 'Q1'), | ||
matcher.add.bind(matcher, '*.*.rabbit', 'Q2'), | ||
matcher.add.bind(matcher, 'lazy.#', 'Q2')], | ||
async.mapSeries.bind(async, | ||
['quick.orange.rabbit', | ||
'lazy.orange.elephant', | ||
'quick.orange.fox', | ||
'lazy.brown.fox', | ||
'lazy.pink.rabbit', | ||
'quick.brown.fox', | ||
'orange', | ||
'quick.orange.male.rabbit', | ||
'lazy.orange.male.rabbit'], | ||
matcher.match, | ||
function (err, vals) | ||
{ | ||
expect(vals).to.eql( | ||
[['Q1', 'Q2'], | ||
['Q1', 'Q2'], | ||
['Q1'], | ||
['Q2'], | ||
['Q2'], | ||
[], | ||
[], | ||
[], | ||
['Q2']]); | ||
done(); | ||
})); | ||
matcher.add('*.orange.*', 'Q1'); | ||
matcher.add('*.*.rabbit', 'Q2'); | ||
matcher.add('lazy.#', 'Q2'); | ||
expect(['quick.orange.rabbit', | ||
'lazy.orange.elephant', | ||
'quick.orange.fox', | ||
'lazy.brown.fox', | ||
'lazy.pink.rabbit', | ||
'quick.brown.fox', | ||
'orange', | ||
'quick.orange.male.rabbit', | ||
'lazy.orange.male.rabbit'].map(matcher.match)).to.eql( | ||
[['Q1', 'Q2'], | ||
['Q1', 'Q2'], | ||
['Q1'], | ||
['Q2'], | ||
['Q2'], | ||
[], | ||
[], | ||
[], | ||
['Q2']]); | ||
}); | ||
}); | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
0
26280
526
152
- Removedasync@~0.2.9
- Removedasync@0.2.10(transitive)