Add more parser tests, alias for quiet flag.

This commit is contained in:
Brandon Shroyer 2016-02-02 17:11:54 -05:00
parent a18e230afa
commit 30004992e5
2 changed files with 21 additions and 6 deletions

View File

@ -3,8 +3,8 @@ defmodule Parser do
def parse(command) do
{options, cmd, _} = OptionParser.parse(
command,
switches: [node: :atom],
aliases: [n: :node]
switches: [node: :atom, quiet: :boolean],
aliases: [n: :node, q: :quiet]
)
{clear_on_empty_command(cmd), options}
end

View File

@ -9,22 +9,37 @@ defmodule ParserTest do
assert Parser.parse(["sandwich", "pastrami"]) == {["sandwich", "pastrami"], []}
end
test "one arity 0 command, one single-dash option" do
test "one arity 1 command, one double-dash quiet flag" do
assert Parser.parse(["sandwich", "pastrami", "--quiet"]) ==
{["sandwich", "pastrami"], [quiet: true]}
end
test "one arity 1 command, one single-dash quiet flag" do
assert Parser.parse(["sandwich", "pastrami", "-q"]) ==
{["sandwich", "pastrami"], [quiet: true]}
end
test "one arity 0 command, one single-dash node option" do
assert Parser.parse(["sandwich", "-n", "rabbitmq@localhost"]) ==
{["sandwich"], [node: "rabbitmq@localhost"]}
end
test "one arity 1 command, one single-dash option" do
test "one arity 1 command, one single-dash node option" do
assert Parser.parse(["sandwich", "pastrami", "-n", "rabbitmq@localhost"]) ==
{["sandwich", "pastrami"], [node: "rabbitmq@localhost"]}
end
test "single-dash option before command" do
test "one arity 1 command, one single-dash node option and one quiet flag" do
assert Parser.parse(["sandwich", "pastrami", "-n", "rabbitmq@localhost", "--quiet"]) ==
{["sandwich", "pastrami"], [node: "rabbitmq@localhost", quiet: true]}
end
test "single-dash node option before command" do
assert Parser.parse(["-n", "rabbitmq@localhost", "sandwich", "pastrami"]) ==
{["sandwich", "pastrami"], [node: "rabbitmq@localhost"]}
end
test "no commands, one double-dash option" do
test "no commands, one double-dash node option" do
assert Parser.parse(["-n=rabbitmq@localhost"]) == {[], [node: "rabbitmq@localhost"]}
end