WIP: Add more tests for new behaviors
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -11,14 +11,48 @@ defmodule ConfigTest do
|
||||
{Test, channels: ["#foo"]},
|
||||
{Test, channels: ["#bar"]},
|
||||
{Test, channels: ["#baz"]},
|
||||
{Test, channels: :all},
|
||||
]
|
||||
}
|
||||
|
||||
channels = Config.all_channels(cfg)
|
||||
|
||||
assert length(channels) == 3
|
||||
assert Enum.any?(channels, fn channel -> channel == "#foo" end)
|
||||
assert Enum.any?(channels, fn channel -> channel == "#bar" end)
|
||||
assert Enum.any?(channels, fn channel -> channel == "#baz" end)
|
||||
assert Enum.member?(channels, "#foo")
|
||||
assert Enum.member?(channels, "#bar")
|
||||
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
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
alias Omnibot.Irc
|
||||
alias Omnibot.Msg
|
||||
alias Omnibot.{Irc, Irc.Msg}
|
||||
|
||||
defmodule Omnibot.Irc.MsgTest do
|
||||
|
||||
defmodule Omnibot.MsgTest do
|
||||
use ExUnit.Case
|
||||
|
||||
# doctest Irc
|
||||
|
||||
test "irc message parsing" do
|
||||
assert %Irc.Msg{
|
||||
prefix: %Irc.Msg.Prefix{nick: "example.com"},
|
||||
assert %Msg{
|
||||
prefix: %Msg.Prefix{nick: "example.com"},
|
||||
command: "PRIVMSG",
|
||||
params: [],
|
||||
} == Irc.Msg.parse(":example.com PRIVMSG")
|
||||
} == Msg.parse(":example.com PRIVMSG")
|
||||
|
||||
assert %Irc.Msg{
|
||||
prefix: %Irc.Msg.Prefix{nick: "example.com"},
|
||||
assert %Msg{
|
||||
prefix: %Msg.Prefix{nick: "example.com"},
|
||||
command: "PRIVMSG",
|
||||
params: ["#channel", "message text"],
|
||||
} == Irc.Msg.parse(":example.com PRIVMSG #channel :message text")
|
||||
} == Msg.parse(":example.com PRIVMSG #channel :message text")
|
||||
|
||||
assert %Irc.Msg{
|
||||
prefix: %Irc.Msg.Prefix{nick: "example.com"},
|
||||
assert %Msg{
|
||||
prefix: %Msg.Prefix{nick: "example.com"},
|
||||
command: "PRIVMSG",
|
||||
params: ["#channel", "message", "text"],
|
||||
} == Irc.Msg.parse(":example.com PRIVMSG #channel message text")
|
||||
} == Msg.parse(":example.com PRIVMSG #channel message text")
|
||||
end
|
||||
|
||||
test "irc message prefix parsing" do
|
||||
alias Irc.Msg.Prefix
|
||||
alias Msg.Prefix
|
||||
assert Prefix.parse(":example.com") != %Prefix{}
|
||||
|
||||
%Prefix{
|
||||
@@ -51,7 +51,7 @@ defmodule Omnibot.Irc.MsgTest do
|
||||
end
|
||||
|
||||
test "irc message prefix to_string" do
|
||||
alias Irc.Msg.Prefix
|
||||
alias Msg.Prefix
|
||||
|
||||
prefixes = [
|
||||
"example.com",
|
||||
@@ -64,8 +64,6 @@ defmodule Omnibot.Irc.MsgTest do
|
||||
end
|
||||
|
||||
test "irc message to_string" do
|
||||
alias Irc.Msg
|
||||
|
||||
msgs = [
|
||||
":example.com PRIVMSG #command",
|
||||
":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)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user