1 | import test from 'ava';
|
2 | import reachableUrls from '.';
|
3 |
|
4 | test('Check all URLs are reachable', async t => {
|
5 | const string = 'https://google.com https://github.com';
|
6 | t.deepEqual(await reachableUrls(string), {
|
7 | 'https://google.com': true,
|
8 | 'https://github.com': true
|
9 | });
|
10 | });
|
11 |
|
12 | test('Check some URLs are reachable', async t => {
|
13 | const string = 'https://foobarbaz.com https://github.com';
|
14 | t.deepEqual(await reachableUrls(string), {
|
15 | 'https://github.com': true,
|
16 | 'https://foobarbaz.com': false
|
17 | });
|
18 | });
|
19 |
|
20 | test('Check text which does not contain URLs', async t => {
|
21 | const string = 'Lorem ipsum';
|
22 | t.deepEqual(await reachableUrls(string), {});
|
23 | });
|
24 |
|
25 | test('Remove needless URL suffixes', async t => {
|
26 | const strings = [
|
27 | 'https://google.com/+shogosensui[',
|
28 | 'https://github.com/1000ch(',
|
29 | 'https://twitter.com/<',
|
30 | 'https://facebook.com#hash"',
|
31 | 'https://www.mozilla.jp?key=valueあ',
|
32 | 'https://travis-ci.org/。'
|
33 | ];
|
34 | t.deepEqual(await reachableUrls(strings.join(' ')), {
|
35 | 'https://google.com/+shogosensui': true,
|
36 | 'https://github.com/1000ch': true,
|
37 | 'https://twitter.com/': true,
|
38 | 'https://facebook.com#hash': true,
|
39 | 'https://www.mozilla.jp?key=value': true,
|
40 | 'https://travis-ci.org/': true
|
41 | });
|
42 | });
|