diff options
Diffstat (limited to 'test/parser/line_test.exs')
-rw-r--r-- | test/parser/line_test.exs | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/test/parser/line_test.exs b/test/parser/line_test.exs new file mode 100644 index 0000000..242e5b0 --- /dev/null +++ b/test/parser/line_test.exs @@ -0,0 +1,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 |