-
Notifications
You must be signed in to change notification settings - Fork 186
/
scanner-test.js
105 lines (93 loc) · 3.07 KB
/
scanner-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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
var
scanner = require('../../../../lib/linkify/core/scanner'),
TEXT_TOKENS = require('../../../../lib/linkify/core/tokens').text;
var
DOMAIN = TEXT_TOKENS.DOMAIN,
AT = TEXT_TOKENS.AT,
COLON = TEXT_TOKENS.COLON,
DOT = TEXT_TOKENS.DOT,
PUNCTUATION = TEXT_TOKENS.PUNCTUATION,
LOCALHOST = TEXT_TOKENS.LOCALHOST,
NL = TEXT_TOKENS.NL,
NUM = TEXT_TOKENS.NUM,
PLUS = TEXT_TOKENS.PLUS,
POUND = TEXT_TOKENS.POUND,
PROTOCOL = TEXT_TOKENS.PROTOCOL,
QUERY = TEXT_TOKENS.QUERY,
SLASH = TEXT_TOKENS.SLASH,
SYM = TEXT_TOKENS.SYM,
TLD = TEXT_TOKENS.TLD,
WS = TEXT_TOKENS.WS,
OPENBRACE = TEXT_TOKENS.OPENBRACE,
OPENBRACKET = TEXT_TOKENS.OPENBRACKET,
OPENPAREN = TEXT_TOKENS.OPENPAREN,
CLOSEBRACE = TEXT_TOKENS.CLOSEBRACE,
CLOSEBRACKET = TEXT_TOKENS.CLOSEBRACKET,
CLOSEPAREN = TEXT_TOKENS.CLOSEPAREN;
// The elements are
// 1. input string
// 2. Types for the resulting instances
// 3. String values for the resulting instances
var tests = [
['', [], []],
['@', [AT], ['@']],
[':', [COLON], [':']],
['.', [DOT], ['.']],
['-', [SYM], ['-']],
['\n', [NL], ['\n']],
['+', [PLUS], ['+']],
['#', [POUND], ['#']],
['/', [SLASH], ['/']],
['&', [SYM], ['&']],
['&?<>(', [SYM, QUERY, SYM, SYM, OPENPAREN], ['&', '?', '<', '>', '(']],
['([{}])', [OPENPAREN, OPENBRACKET, OPENBRACE, CLOSEBRACE, CLOSEBRACKET, CLOSEPAREN], ['(', '[', '{', '}', ']', ')']],
['!,;', [PUNCTUATION, PUNCTUATION, PUNCTUATION], ['!', ',', ';']],
['hello', [DOMAIN], ['hello']],
['Hello123', [DOMAIN], ['Hello123']],
['hello123world', [DOMAIN], ['hello123world']],
['0123', [NUM], ['0123']],
['123abc', [DOMAIN], ['123abc']],
['http', [DOMAIN], ['http']],
['http:', [PROTOCOL], ['http:']],
['https:', [PROTOCOL], ['https:']],
['files:', [DOMAIN, COLON], ['files', ':']],
['file//', [DOMAIN, SLASH, SLASH], ['file', '/', '/']],
['ftp://', [PROTOCOL, SLASH, SLASH], ['ftp:', '/', '/']],
['c', [DOMAIN], ['c']],
['co', [TLD], ['co']],
['com', [TLD], ['com']],
['comm', [DOMAIN], ['comm']],
['abc 123 DoReMi', [DOMAIN, WS, NUM, WS, DOMAIN], ['abc', ' ', '123', ' ', 'DoReMi']],
['abc 123 \n DoReMi', [DOMAIN, WS, NUM, WS, NL, WS, DOMAIN], ['abc', ' ', '123', ' ', '\n', ' ', 'DoReMi']],
['local', [DOMAIN], ['local']],
['localhost', [LOCALHOST], ['localhost']],
['localhosts', [DOMAIN], ['localhosts']],
['500px', [DOMAIN], ['500px']],
['500-px', [DOMAIN], ['500-px']],
['-500px', [SYM, DOMAIN], ['-', '500px']],
['500px-', [DOMAIN, SYM], ['500px', '-']],
['123-456', [DOMAIN], ['123-456']],
[
'Direniş İzleme Grubu\'nun',
[DOMAIN, SYM, WS, SYM, DOMAIN, WS, DOMAIN, SYM, DOMAIN],
['Direni', 'ş', ' ', 'İ', 'zleme', ' ', 'Grubu', '\'', 'nun']
]
];
describe('linkify/core/scanner#run()', function () {
function makeTest(test) {
return it('Tokenizes the string "' + test[0] + '"', function () {
var
str = test[0],
types = test[1],
values = test[2],
result = scanner.run(str);
expect(result.map(function (token) {
return token.toString();
})).to.eql(values);
expect(result.map(function (token) {
return token.constructor;
})).to.eql(types);
});
}
tests.map(makeTest, this);
});