forked from 1000ch/reachable-urls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
63 lines (53 loc) · 1.54 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const test = require('ava');
const reachableUrls = require('.');
test('Check string', async t => {
const strings = [
'https://google.com',
'https://github.com',
'https://foobarbaz.com'
];
t.deepEqual(await reachableUrls(strings.join(' ')), {
'https://google.com': true,
'https://github.com': true,
'https://foobarbaz.com': false
});
});
test('Check also buffer', async t => {
const buffer = Buffer.from([
'https://foobarbaz.com',
'https://github.com'
].join(' '));
t.deepEqual(await reachableUrls(buffer), {
'https://github.com': true,
'https://foobarbaz.com': false
});
});
test('Filter URLs but http or https', async t => {
const strings = [
'ws://echo.websocket.org',
'file:///path/to/workspace'
];
t.deepEqual(await reachableUrls(strings.join(' ')), {});
});
test('Check string which does not contain URLs', async t => {
const string = 'Lorem ipsum';
t.deepEqual(await reachableUrls(string), {});
});
test('Remove needless URL suffixes', async t => {
const strings = [
'https://github.com/1000ch(',
'https://twitter.com/jxck_<',
'https://facebook.com#hash"',
'https://www.messenger.com/)',
'https://www.mozilla.jp?key=valueあ',
'https://travis-ci.org/。'
];
t.deepEqual(await reachableUrls(strings.join(' ')), {
'https://github.com/1000ch': true,
'https://twitter.com/jxck_': true,
'https://facebook.com#hash': true,
'https://www.messenger.com/': true,
'https://www.mozilla.jp?key=value': true,
'https://travis-ci.org/': true
});
});