WIP: Add more tests for new behaviors

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-06-13 16:07:16 -04:00
parent 73c5f58243
commit 590b3ddbec
2 changed files with 68 additions and 19 deletions

View File

@@ -11,14 +11,48 @@ defmodule ConfigTest do
{Test, channels: ["#foo"]}, {Test, channels: ["#foo"]},
{Test, channels: ["#bar"]}, {Test, channels: ["#bar"]},
{Test, channels: ["#baz"]}, {Test, channels: ["#baz"]},
{Test, channels: :all},
] ]
} }
channels = Config.all_channels(cfg) channels = Config.all_channels(cfg)
assert length(channels) == 3 assert length(channels) == 3
assert Enum.any?(channels, fn channel -> channel == "#foo" end) assert Enum.member?(channels, "#foo")
assert Enum.any?(channels, fn channel -> channel == "#bar" end) assert Enum.member?(channels, "#bar")
assert Enum.any?(channels, fn channel -> channel == "#baz" end) assert Enum.member?(channels, "#baz")
end
test "config channel_modules works correctly" do
cfg = %Config {
server: "test",
modules: [
{FooBar, channels: ["#foo", "#bar"]},
{Foo, channels: ["#foo"]},
{Bar, channels: ["#bar"]},
{Baz, channels: ["#baz"]},
{All, channels: :all},
]
}
modules = Config.channel_modules(cfg, "#foo")
|> Enum.map(fn {module, _} -> module end)
assert length(modules) == 3
assert Enum.member?(modules, FooBar)
assert Enum.member?(modules, Foo)
assert Enum.member?(modules, All)
modules = Config.channel_modules(cfg, "#bar")
|> Enum.map(fn {module, _} -> module end)
assert length(modules) == 3
assert Enum.member?(modules, FooBar)
assert Enum.member?(modules, Bar)
assert Enum.member?(modules, All)
modules = Config.channel_modules(cfg, "#baz")
|> Enum.map(fn {module, _} -> module end)
assert length(modules) == 2
assert Enum.member?(modules, Baz)
assert Enum.member?(modules, All)
end end
end end

View File

@@ -1,33 +1,33 @@
alias Omnibot.Irc alias Omnibot.{Irc, Irc.Msg}
alias Omnibot.Msg
defmodule Omnibot.Irc.MsgTest do
defmodule Omnibot.MsgTest do
use ExUnit.Case use ExUnit.Case
# doctest Irc # doctest Irc
test "irc message parsing" do test "irc message parsing" do
assert %Irc.Msg{ assert %Msg{
prefix: %Irc.Msg.Prefix{nick: "example.com"}, prefix: %Msg.Prefix{nick: "example.com"},
command: "PRIVMSG", command: "PRIVMSG",
params: [], params: [],
} == Irc.Msg.parse(":example.com PRIVMSG") } == Msg.parse(":example.com PRIVMSG")
assert %Irc.Msg{ assert %Msg{
prefix: %Irc.Msg.Prefix{nick: "example.com"}, prefix: %Msg.Prefix{nick: "example.com"},
command: "PRIVMSG", command: "PRIVMSG",
params: ["#channel", "message text"], params: ["#channel", "message text"],
} == Irc.Msg.parse(":example.com PRIVMSG #channel :message text") } == Msg.parse(":example.com PRIVMSG #channel :message text")
assert %Irc.Msg{ assert %Msg{
prefix: %Irc.Msg.Prefix{nick: "example.com"}, prefix: %Msg.Prefix{nick: "example.com"},
command: "PRIVMSG", command: "PRIVMSG",
params: ["#channel", "message", "text"], params: ["#channel", "message", "text"],
} == Irc.Msg.parse(":example.com PRIVMSG #channel message text") } == Msg.parse(":example.com PRIVMSG #channel message text")
end end
test "irc message prefix parsing" do test "irc message prefix parsing" do
alias Irc.Msg.Prefix alias Msg.Prefix
assert Prefix.parse(":example.com") != %Prefix{} assert Prefix.parse(":example.com") != %Prefix{}
%Prefix{ %Prefix{
@@ -51,7 +51,7 @@ defmodule Omnibot.Irc.MsgTest do
end end
test "irc message prefix to_string" do test "irc message prefix to_string" do
alias Irc.Msg.Prefix alias Msg.Prefix
prefixes = [ prefixes = [
"example.com", "example.com",
@@ -64,8 +64,6 @@ defmodule Omnibot.Irc.MsgTest do
end end
test "irc message to_string" do test "irc message to_string" do
alias Irc.Msg
msgs = [ msgs = [
":example.com PRIVMSG #command", ":example.com PRIVMSG #command",
":example.com PRIVMSG #channel :message text" ":example.com PRIVMSG #channel :message text"
@@ -73,4 +71,21 @@ defmodule Omnibot.Irc.MsgTest do
for msg <- msgs, do: assert(Msg.parse(msg) |> to_string() == msg) for msg <- msgs, do: assert(Msg.parse(msg) |> to_string() == msg)
end end
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
end end