Initial commit with IRC and bot example.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-06-12 17:29:35 -04:00
commit 6340936895
20 changed files with 793 additions and 0 deletions

24
test/config_test.exs Normal file
View File

@@ -0,0 +1,24 @@
defmodule ConfigTest do
use ExUnit.Case
alias Omnibot.Config
test "config all_channels works correctly" do
cfg = %Config {
server: "test",
modules: [
{Test, channels: ["#foo", "#bar"]},
{Test, channels: ["#foo"]},
{Test, channels: ["#bar"]},
{Test, channels: ["#baz"]},
]
}
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)
end
end

76
test/irc/msg_test.exs Normal file
View File

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

1
test/test_helper.exs Normal file
View File

@@ -0,0 +1 @@
ExUnit.start()

15
test/util_test.exs Normal file
View File

@@ -0,0 +1,15 @@
alias Omnibot.Util
defmodule Omnibot.UtilTest do
use ExUnit.Case
test "string_empty?" do
assert Util.string_empty?("")
assert !Util.string_empty?("asdf")
end
test "string_or_nil" do
assert Util.string_or_nil("") == nil
assert Util.string_or_nil("asdf") == "asdf"
end
end