-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.js
48 lines (43 loc) · 1.44 KB
/
test.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
describe('s.h.i.e.l.d.', function () {
'use strict';
var assume = require('assume')
, shield = require('./');
it('is exported as function', function () {
assume(shield).is.a('function');
});
it('returns false no string or array is given', function () {
assume(shield('www.host.com', {})).is.false();
assume(shield('www.host.com', new Date)).is.false();
assume(shield('www.host.com', true)).is.false();
});
[
{
host: 'http://example.com',
yes: ['example.com', '*', 'http://example.com', 'https://example.com', 'example.*'],
no: ['yahoo.com', '*.yahoo.com', 'example.com:8080', 'example.nl']
},
{
host: 'www.example.com',
yes: ['*.example.com', [/www\.example\.com/], ['*']],
no: ['gmail.example.com', 'foo.bar.com', ['foo.bar.com']]
},
{
host: 'foo.bar.example.com',
yes: ['*.*.example.com', '*.example.com', 'foo.*.example.com', '*.bar.example.com'],
no: ['hello.*.example.com', '*.*.yahoo.com']
}
].forEach(function each(spec) {
describe(spec.host, function () {
if (spec.yes) spec.yes.forEach(function yea(yes) {
it('should match with '+ yes, function () {
assume(shield(spec.host, yes)).is.true();
});
});
if (spec.no) spec.no.forEach(function nope(no) {
it('should NOT match with '+ no, function () {
assume(shield(spec.host, no)).is.false();
});
});
});
});
});