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
|
defmodule Irc.Parser.LineTest do
use ExUnit.Case
alias Irc.Parser.Line
alias Irc.Mask
doctest Irc.Parser.Line
test "isupport" do
str = ':nowhere 005 hrhrhr TOPICLEN=390 TARGMAX=NAMES:1,MONITOR: EXTBAN=$,acjorsxz CLIENTVER=3.0 :are supported by this server'
line = Line.parse(str)
assert line.source == "nowhere"
assert line.command == "005"
assert line.args == ["hrhrhr", "TOPICLEN=390", "TARGMAX=NAMES:1,MONITOR:", "EXTBAN=$,acjorsxz", "CLIENTVER=3.0", "are supported by this server"]
assert Line.encode(line) == to_string(str)
end
test "auth notice" do
str = ':zoidberg.chatspike.net NOTICE Auth :Welcome to ChatSpike!'
line = Line.parse(str)
assert line.source == %Mask{server: "zoidberg.chatspike.net"}
assert line.command =="NOTICE"
assert line.args == ["Auth", "Welcome to ChatSpike!"]
assert Line.encode(line) == to_string(str)
end
test "connect notice" do
str = ':livingstone.freenode.net NOTICE * :*** Checking Ident'
line = Line.parse(str)
assert line.command == "NOTICE"
assert line.source == %Mask{server: "livingstone.freenode.net"}
assert line.args == ["*", "*** Checking Ident"]
assert Line.encode(line) == to_string(str)
end
test "numeric" do
str = ':stitch.chatspike.net 042 derp ABCDEFGHI :your unique ID'
line = Line.parse(str)
assert line.source == %Mask{server: "stitch.chatspike.net"}
assert line.command == "042"
assert line.args == ["derp", "ABCDEFGHI", "your unique ID"]
assert Line.encode(line) == to_string(str)
end
test "ping" do
str = 'PING :bender.chatspike.net'
line = Line.parse(str)
assert line.command == "PING"
assert line.args == ["bender.chatspike.net"]
assert Line.encode(line) == to_string(str)
end
test "tags" do
str = '@lol=dongs :href PRIVMSG #dongs :dongs dongs dongs'
line = Line.parse(str)
assert line.tags == %{"lol" => "dongs"}
refute Line.encode(line) == to_string(str)
assert Line.encode(line, %Irc.Connection{capabs: ["message-tags"]}) == to_string(str)
end
test "self?" do
line = Line.parse(':href!href@sade.random.sh PRIVMSG #dongs')
line2 = Line.parse(':blep PRIVMSG #blep')
mask = %Irc.Mask{nick: "href", user: "href", host: "sade.random.sh"}
user = Irc.User.from_mask(mask)
conn = %Irc.Connection{nick: "href"}
assert Line.self?(line, mask)
assert Line.self?(line, user)
assert Line.self?(line, conn)
refute Line.self?(line2, mask)
refute Line.self?(line2, user)
refute Line.self?(line2, conn)
end
test "to?" do
line = Line.parse(':sade.irc.random.sh 332 href #dongs :lol')
line2 = Line.parse(':sade.random.sh 332 blep')
mask = %Irc.Mask{nick: "href", user: "href", host: "sade.random.sh"}
user = Irc.User.from_mask(mask)
conn = %Irc.Connection{nick: "href"}
assert Line.to?(line, mask)
assert Line.to?(line, user)
assert Line.to?(line, conn)
refute Line.to?(line2, mask)
refute Line.to?(line2, user)
refute Line.to?(line2, conn)
end
end
|