Files: 83ccc060f8a25977d0a70d8d4a0e8b6c3f721531 / test / mentions.js
3776 bytesRaw
1 | var test = require('tape') |
2 | var mentions = require('../') |
3 | |
4 | test('mentions in links are detected', function (t) { |
5 | t.deepEquals(mentions( |
6 | '[@feed](@3HO6R2i60XNR3h6XCHAWCdt1k9Dwy+gaa2rVs6LzZ6Y=.ed25519)'), [ |
7 | { |
8 | link: '@3HO6R2i60XNR3h6XCHAWCdt1k9Dwy+gaa2rVs6LzZ6Y=.ed25519', |
9 | name: 'feed', |
10 | } |
11 | ], 'feed link') |
12 | |
13 | t.deepEquals(mentions( |
14 | '[a msg](%A2LvseOYKDXyuSGlXl3Sz0F5j2khVCN6JTf8ORD/tM8=.sha256)'), [ |
15 | { |
16 | link: '%A2LvseOYKDXyuSGlXl3Sz0F5j2khVCN6JTf8ORD/tM8=.sha256', |
17 | name: 'a msg', |
18 | } |
19 | ], 'msg link') |
20 | |
21 | t.deepEquals(mentions( |
22 | '[a blob](&9SSTQys34p9f4zqjxvRwENjFX0JapgtesRey7+fxK14=.sha256)'), [ |
23 | { |
24 | link: '&9SSTQys34p9f4zqjxvRwENjFX0JapgtesRey7+fxK14=.sha256', |
25 | name: 'a blob', |
26 | } |
27 | ], 'blob link') |
28 | |
29 | t.deepEquals(mentions( |
30 | '[an encrypted blob](&6lF87HG0l6vGnto3M7/mTNFShOFmp/zAH05Ett1+eqk=.sha256#47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=)'), [ |
31 | { |
32 | link: '&6lF87HG0l6vGnto3M7/mTNFShOFmp/zAH05Ett1+eqk=.sha256', |
33 | key: '47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=', |
34 | name: 'an encrypted blob', |
35 | } |
36 | ], 'encrypted blob link') |
37 | |
38 | t.deepEquals(mentions( |
39 | '[a querystring encrypted blob](&6lF87HG0l6vGnto3M7/mTNFShOFmp/zAH05Ett1+eqk=.sha256?unbox=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=.boxs)'), [ |
40 | { |
41 | link: '&6lF87HG0l6vGnto3M7/mTNFShOFmp/zAH05Ett1+eqk=.sha256', |
42 | key: '47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=', |
43 | name: 'a querystring encrypted blob', |
44 | } |
45 | ], 'querystring encrypted blob links') |
46 | |
47 | t.end() |
48 | }) |
49 | |
50 | test('ref mentions are detected', function (t) { |
51 | t.deepEquals(mentions( |
52 | '@3HO6R2i60XNR3h6XCHAWCdt1k9Dwy+gaa2rVs6LzZ6Y=.ed25519'), [ |
53 | { |
54 | link: '@3HO6R2i60XNR3h6XCHAWCdt1k9Dwy+gaa2rVs6LzZ6Y=.ed25519', |
55 | name: undefined |
56 | } |
57 | ], 'feed link') |
58 | |
59 | t.deepEquals(mentions( |
60 | '%A2LvseOYKDXyuSGlXl3Sz0F5j2khVCN6JTf8ORD/tM8=.sha256'), [ |
61 | { |
62 | link: '%A2LvseOYKDXyuSGlXl3Sz0F5j2khVCN6JTf8ORD/tM8=.sha256', |
63 | name: undefined |
64 | } |
65 | ], 'msg link') |
66 | |
67 | t.deepEquals(mentions( |
68 | '&9SSTQys34p9f4zqjxvRwENjFX0JapgtesRey7+fxK14=.sha256'), [ |
69 | { |
70 | link: '&9SSTQys34p9f4zqjxvRwENjFX0JapgtesRey7+fxK14=.sha256', |
71 | name: undefined |
72 | } |
73 | ], 'blob link') |
74 | |
75 | /* |
76 | t.deepEquals(mentions( |
77 | '&6lF87HG0l6vGnto3M7/mTNFShOFmp/zAH05Ett1+eqk=.sha256#47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU='), [ |
78 | { |
79 | link: '&6lF87HG0l6vGnto3M7/mTNFShOFmp/zAH05Ett1+eqk=.sha256', |
80 | key: '47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=', |
81 | name: undefined, |
82 | } |
83 | ], 'encrypted blob link') |
84 | */ |
85 | |
86 | t.end() |
87 | }) |
88 | |
89 | test('bare feed name mentions can be detected', function (t) { |
90 | t.deepEquals(mentions('a @feed mention', {bareFeedNames: true}), |
91 | [{name: 'feed', link: '@'}], 'feed link') |
92 | t.end() |
93 | }) |
94 | |
95 | test('detect hashtags', function (t) { |
96 | t.deepEquals(mentions('a nice #hashtag here'), |
97 | [{link: '#hashtag'}], 'hashtag link') |
98 | t.end() |
99 | }) |
100 | |
101 | test('no html tags in link names', function (t) { |
102 | t.deepEquals(mentions('link: [`code` *em* **strong** ~~del~~]' + |
103 | '(&9SSTQys34p9f4zqjxvRwENjFX0JapgtesRey7+fxK14=.sha256)'), [ |
104 | { |
105 | link: '&9SSTQys34p9f4zqjxvRwENjFX0JapgtesRey7+fxK14=.sha256', |
106 | name: 'code em strong del' |
107 | } |
108 | ], 'no tags') |
109 | t.end() |
110 | }) |
111 | |
112 | test('detect emoji', function (t) { |
113 | t.deepEquals(mentions('some nice :+1: :emoji: here', {emoji: true}), [ |
114 | {name: '+1', emoji: true}, |
115 | {name: 'emoji', emoji: true}, |
116 | ], 'emoji') |
117 | t.end() |
118 | }) |
119 | |
120 | test('colons in link names are ok', function (t) { |
121 | t.deepEquals(mentions('[:asdf:](&9SSTQys34p9f4zqjxvRwENjFX0JapgtesRey7+fxK14=.sha256)'), [ |
122 | {name: ':asdf:', link: '&9SSTQys34p9f4zqjxvRwENjFX0JapgtesRey7+fxK14=.sha256'} |
123 | ], 'colons') |
124 | t.end() |
125 | }) |
126 |
Built with git-ssb-web