2020-06-13 17:13:05 -04:00
|
|
|
alias Omnibot.Irc.Msg
|
2020-06-12 17:29:35 -04:00
|
|
|
|
2020-06-13 16:07:16 -04:00
|
|
|
|
|
|
|
|
defmodule Omnibot.MsgTest do
|
2020-06-12 17:29:35 -04:00
|
|
|
use ExUnit.Case
|
|
|
|
|
|
|
|
|
|
# doctest Irc
|
|
|
|
|
|
|
|
|
|
test "irc message parsing" do
|
2020-06-13 16:07:16 -04:00
|
|
|
assert %Msg{
|
|
|
|
|
prefix: %Msg.Prefix{nick: "example.com"},
|
2020-06-12 17:29:35 -04:00
|
|
|
command: "PRIVMSG",
|
|
|
|
|
params: [],
|
2020-06-13 16:07:16 -04:00
|
|
|
} == Msg.parse(":example.com PRIVMSG")
|
2020-06-12 17:29:35 -04:00
|
|
|
|
2020-06-13 16:07:16 -04:00
|
|
|
assert %Msg{
|
|
|
|
|
prefix: %Msg.Prefix{nick: "example.com"},
|
2020-06-12 17:29:35 -04:00
|
|
|
command: "PRIVMSG",
|
|
|
|
|
params: ["#channel", "message text"],
|
2020-06-13 16:07:16 -04:00
|
|
|
} == Msg.parse(":example.com PRIVMSG #channel :message text")
|
2020-06-12 17:29:35 -04:00
|
|
|
|
2020-06-13 16:07:16 -04:00
|
|
|
assert %Msg{
|
|
|
|
|
prefix: %Msg.Prefix{nick: "example.com"},
|
2020-06-12 17:29:35 -04:00
|
|
|
command: "PRIVMSG",
|
|
|
|
|
params: ["#channel", "message", "text"],
|
2020-06-13 16:07:16 -04:00
|
|
|
} == Msg.parse(":example.com PRIVMSG #channel message text")
|
2020-06-12 17:29:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "irc message prefix parsing" do
|
2020-06-13 16:07:16 -04:00
|
|
|
alias Msg.Prefix
|
2020-06-12 17:29:35 -04:00
|
|
|
assert Prefix.parse(":example.com") != %Prefix{}
|
|
|
|
|
|
|
|
|
|
%Prefix{
|
|
|
|
|
nick: "example.com"
|
|
|
|
|
} = Prefix.parse("example.com")
|
|
|
|
|
|
|
|
|
|
%Prefix{
|
|
|
|
|
nick: "nick"
|
|
|
|
|
} = Prefix.parse("nick")
|
|
|
|
|
|
|
|
|
|
%Prefix{
|
|
|
|
|
nick: "nick",
|
|
|
|
|
user: "username"
|
|
|
|
|
} = Prefix.parse("nick!username")
|
|
|
|
|
|
|
|
|
|
%Prefix{
|
|
|
|
|
nick: "nick",
|
|
|
|
|
user: "username",
|
|
|
|
|
host: "example.com"
|
|
|
|
|
} = Prefix.parse("nick!username@example.com")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "irc message prefix to_string" do
|
2020-06-13 16:07:16 -04:00
|
|
|
alias Msg.Prefix
|
2020-06-12 17:29:35 -04:00
|
|
|
|
|
|
|
|
prefixes = [
|
|
|
|
|
"example.com",
|
|
|
|
|
"nick!username",
|
|
|
|
|
"nick!username@example.com"
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
for prefix <- prefixes,
|
|
|
|
|
do: assert(Prefix.parse(prefix) |> to_string() == prefix)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "irc message to_string" do
|
|
|
|
|
msgs = [
|
|
|
|
|
":example.com PRIVMSG #command",
|
|
|
|
|
":example.com PRIVMSG #channel :message text"
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
for msg <- msgs, do: assert(Msg.parse(msg) |> to_string() == msg)
|
|
|
|
|
end
|
2020-06-13 16:07:16 -04:00
|
|
|
|
|
|
|
|
test "irc message extracts channel properly" do
|
|
|
|
|
msg = Msg.parse(":example.com PRIVMSG #channel message text")
|
|
|
|
|
assert Msg.channel(msg) == "#channel"
|
|
|
|
|
|
|
|
|
|
msg = Msg.parse(":example.com JOIN #join")
|
|
|
|
|
assert Msg.channel(msg) == "#join"
|
|
|
|
|
|
|
|
|
|
msg = Msg.parse(":example.com PART #part")
|
|
|
|
|
assert Msg.channel(msg) == "#part"
|
|
|
|
|
|
|
|
|
|
msg = Msg.parse(":example.com KICK #kicked nick")
|
|
|
|
|
assert Msg.channel(msg) == "#kicked"
|
|
|
|
|
|
|
|
|
|
msg = Msg.parse(":example.com PING 1234")
|
|
|
|
|
assert Msg.channel(msg) == nil
|
|
|
|
|
end
|
2020-06-12 17:29:35 -04:00
|
|
|
end
|