-
Notifications
You must be signed in to change notification settings - Fork 155
/
Copy pathtest.sub.matches.js
32 lines (25 loc) · 997 Bytes
/
test.sub.matches.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var assert = require('better-assert')
, axon = require('..')
, sub = axon.socket('sub');
function test(pattern, str) {
sub.clearSubscriptions();
sub.subscribe(pattern);
return sub.matches(str);
}
assert(true == test('foo', 'foo'));
assert(false == test('foo', 'foobar'));
assert(false == test('foo', 'barfoo'));
assert(false == test('foo*', 'foo'));
assert(true == test('foo*', 'foobar'));
assert(true == test('foo*', 'foobarbaz'));
assert(false == test('foo*', 'barfoo'));
assert(true == test('user:*', 'user:login'));
assert(true == test('user:*', 'user:logout'));
assert(false == test('user:*', 'user'));
assert(true == test('user:*:logout', 'user:tj:logout'));
assert(false == test('user:*:logout', 'user::logout'));
assert(false == test('user:*:logout', 'user:logout'));
assert(true == test('user:*:*', 'user:tj:login'));
assert(true == test('user:*:*', 'user:tj:logout'));
assert(false == test('user:*:*', 'user::logout'));
assert(false == test('user:*:*', 'user:logout'));