elixir_rss/test/cli_test.exs
2024-10-12 20:50:00 -05:00

32 lines
1.2 KiB
Elixir

defmodule CliTest do
use ExUnit.Case
doctest ElixirRss
import ElixirRss.CLI, only: [parse_args: 1]
test ":help returned for -h, --help, and default" do
assert parse_args(["-h"]) == :help
assert parse_args(["--help"]) == :help
assert parse_args(["other", "-h", "stuff"]) == :help
assert parse_args(["other", "--help", "stuff"]) == :help
end
test "all switches given" do
assert parse_args(["--host", "127.0.0.1", "--port", "80", "--path", "/path"]) == {"127.0.0.1", 80, "/path"}
end
test "defaults returned for missing args" do
assert parse_args([]) == {"0.0.0.0", 8080, "/"}
assert parse_args(["--host", "127.0.0.1"]) == {"127.0.0.1", 8080, "/"}
assert parse_args(["--port", "80"]) == {"0.0.0.0", 80, "/"}
assert parse_args(["--path", "/path"]) == {"0.0.0.0", 8080, "/path"}
assert parse_args(["--host", "127.0.0.1", "--port", "80"]) == {"127.0.0.1", 80, "/"}
assert parse_args(["--host", "127.0.0.1", "--path", "/path"]) == {"127.0.0.1", 8080, "/path"}
assert parse_args(["--port", "80", "--path", "/path"]) == {"0.0.0.0", 80, "/path"}
end
test "out of order switches" do
assert parse_args(["--port", "80", "--host", "127.0.0.1", "--path", "/path"]) == {"127.0.0.1", 80, "/path"}
end
end