-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
103 lines (98 loc) · 2.84 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
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
// adapted from https://github.com/grawity/code/blob/master/lib/tests/irc-prefix-split.txt
var parse = require('./')
var assert = require('assert')
describe('#parsePrefix()', function() {
it('should correctly parse valid prefixes', function() {
var prefixes = {
'nick': {
isServer: false,
nick: 'nick',
user: null,
host: null
},
'nick!user': {
isServer: false,
nick: 'nick',
user: 'user',
host: null
},
'se.rv.er': {
isServer: true,
nick: null,
user: null,
host: 'se.rv.er'
},
'nick!us.er@host': {
isServer: false,
nick: 'nick',
user: 'us.er',
host: 'host'
},
'nick!user@ho.st': {
isServer: false,
nick: 'nick',
user: 'user',
host: 'ho.st'
},
'nick!': {
isServer: false,
nick: 'nick',
user: '',
host: null
},
'nick@': {
isServer: false,
nick: 'nick',
user: null,
host: ''
},
'nick!@': {
isServer: false,
nick: 'nick',
user: '',
host: ''
},
'nick!user!resu@host': {
isServer: false,
nick: 'nick',
user: 'user!resu',
host: 'host'
},
'nick@kcin!user@host': {
isServer: false,
nick: 'nick@kcin',
user: 'user',
host: 'host'
},
'nick!user@host!resu': {
isServer: false,
nick: 'nick',
user: 'user',
host: 'host!resu'
},
'nick!user@host@tsoh': {
isServer: false,
nick: 'nick',
user: 'user',
host: 'host@tsoh'
},
'ni.ck!user@host': {
isServer: false,
nick: 'ni.ck',
user: 'user',
host: 'host'
}
}
Object.keys(prefixes).forEach(function(prefix) {
var expected = prefixes[prefix]
expected.raw = prefix
assert.deepEqual(parse(prefix), expected)
})
})
it('should return null on invalid prefixes', function() {
var prefixes = ['', '@host', '!user@host', '!@host', '!user@']
prefixes.forEach(function(prefix) {
assert.equal(parse(prefix), null)
})
})
})