Skip to content

Commit

Permalink
Merge pull request #7 from at-grandpa/nilable
Browse files Browse the repository at this point in the history
Nilable
  • Loading branch information
at-grandpa authored Jun 20, 2017
2 parents c55e6c5 + 5ca6728 commit bad598c
Show file tree
Hide file tree
Showing 11 changed files with 310 additions and 283 deletions.
13 changes: 6 additions & 7 deletions spec/clim/dsl_spec.cr
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
require "./../spec_helper"

def create_values(
string = {} of String => String,
bool = {} of String => Bool,
array = {} of String => Array(String))
string : Hash(String, String | Nil) = {} of String => String | Nil,
bool : Hash(String, Bool | Nil) = {} of String => Bool | Nil,
array : Hash(String, Array(String) | Nil) = {} of String => Array(String) | Nil)
values = Options::Values.new
values.string = string
values.bool = bool
values.array = array
values.string.merge!(string)
values.bool.merge!(bool)
values.array.merge!(array)
values
end

96 changes: 51 additions & 45 deletions spec/clim/dsl_spec/array_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe "main command with array." do
Options:
-h, --help Show this help.
-a ARG, --array=ARG Option description. [default:[]]
-a ARG, --array=ARG Option description.
HELP_MESSAGE
Expand All @@ -50,6 +50,16 @@ describe "main command with array." do
end
describe "returns opts and args when passing argv." do
[
{
argv: %w(),
expect_opts: create_values(array: {"array" => nil}),
expect_args: [] of String,
},
{
argv: %w(arg1),
expect_opts: create_values(array: {"array" => nil}),
expect_args: ["arg1"],
},
{
argv: %w(-a array1),
expect_opts: create_values(array: {"array" => ["array1"]}),
Expand All @@ -73,12 +83,12 @@ describe "main command with array." do
{
argv: %w(-a array1 arg1),
expect_opts: create_values(array: {"array" => ["array1"]}),
expect_args: ["arg1"] of String,
expect_args: ["arg1"],
},
{
argv: %w(arg1 -a array1),
expect_opts: create_values(array: {"array" => ["array1"]}),
expect_args: ["arg1"] of String,
expect_args: ["arg1"],
},
{
argv: %w(-array), # Unintended case.
Expand All @@ -102,14 +112,6 @@ describe "main command with array." do
end
describe "raises Exception when passing invalid argv." do
[
{
argv: %w(),
exception_message: "Please specify default value or required true. \"-a ARG\"",
},
{
argv: %w(arg1),
exception_message: "Please specify default value or required true. \"-a ARG\"",
},
{
argv: %w(-a),
exception_message: "Option that requires an argument. \"-a\"",
Expand Down Expand Up @@ -176,7 +178,7 @@ describe "main command with array only short option." do
Options:
-h, --help Show this help.
-a ARG Option description. [default:[]]
-a ARG Option description.
HELP_MESSAGE
Expand All @@ -186,6 +188,16 @@ describe "main command with array only short option." do
end
describe "returns opts and args when passing argv." do
[
{
argv: %w(),
expect_opts: create_values(array: {"a" => nil}),
expect_args: [] of String,
},
{
argv: %w(arg1),
expect_opts: create_values(array: {"a" => nil}),
expect_args: ["arg1"],
},
{
argv: %w(-a array1),
expect_opts: create_values(array: {"a" => ["array1"]}),
Expand All @@ -199,12 +211,12 @@ describe "main command with array only short option." do
{
argv: %w(-a array1 arg1),
expect_opts: create_values(array: {"a" => ["array1"]}),
expect_args: ["arg1"] of String,
expect_args: ["arg1"],
},
{
argv: %w(arg1 -a array1),
expect_opts: create_values(array: {"a" => ["array1"]}),
expect_args: ["arg1"] of String,
expect_args: ["arg1"],
},
{
argv: %w(-array), # Unintended case.
Expand All @@ -228,14 +240,6 @@ describe "main command with array only short option." do
end
describe "raises Exception when passing invalid argv." do
[
{
argv: %w(),
exception_message: "Please specify default value or required true. \"-a ARG\"",
},
{
argv: %w(arg1),
exception_message: "Please specify default value or required true. \"-a ARG\"",
},
{
argv: %w(-a),
exception_message: "Option that requires an argument. \"-a\"",
Expand Down Expand Up @@ -310,7 +314,7 @@ describe "main command with array desc." do
Options:
-h, --help Show this help.
-a ARG, --array=ARG Array option description. [default:[]]
-a ARG, --array=ARG Array option description.
HELP_MESSAGE
Expand Down Expand Up @@ -378,7 +382,7 @@ describe "main command with array default." do
{
argv: %w(arg1),
expect_opts: create_values(array: {"array" => ["default value"]}),
expect_args: ["arg1"] of String,
expect_args: ["arg1"],
},
{
argv: %w(-a array1),
Expand All @@ -403,12 +407,12 @@ describe "main command with array default." do
{
argv: %w(-a array1 arg1),
expect_opts: create_values(array: {"array" => ["default value", "array1"]}),
expect_args: ["arg1"] of String,
expect_args: ["arg1"],
},
{
argv: %w(arg1 -a array1),
expect_opts: create_values(array: {"array" => ["default value", "array1"]}),
expect_args: ["arg1"] of String,
expect_args: ["arg1"],
},
{
argv: %w(-array), # Unintended case.
Expand Down Expand Up @@ -531,12 +535,12 @@ describe "main command with array required true and default exists." do
{
argv: %w(-a array1 arg1),
expect_opts: create_values(array: {"array" => ["default value", "array1"]}),
expect_args: ["arg1"] of String,
expect_args: ["arg1"],
},
{
argv: %w(arg1 -a array1),
expect_opts: create_values(array: {"array" => ["default value", "array1"]}),
expect_args: ["arg1"] of String,
expect_args: ["arg1"],
},
{
argv: %w(-array), # Unintended case.
Expand Down Expand Up @@ -634,7 +638,7 @@ describe "main command with array required true only." do
Options:
-h, --help Show this help.
-a ARG, --array=ARG Array option description. [default:[]] [required]
-a ARG, --array=ARG Array option description. [required]
HELP_MESSAGE
Expand Down Expand Up @@ -667,12 +671,12 @@ describe "main command with array required true only." do
{
argv: %w(-a array1 arg1),
expect_opts: create_values(array: {"array" => ["array1"]}),
expect_args: ["arg1"] of String,
expect_args: ["arg1"],
},
{
argv: %w(arg1 -a array1),
expect_opts: create_values(array: {"array" => ["array1"]}),
expect_args: ["arg1"] of String,
expect_args: ["arg1"],
},
{
argv: %w(-array), # Unintended case.
Expand Down Expand Up @@ -788,7 +792,7 @@ describe "main command with array required false and default exists." do
{
argv: %w(arg1),
expect_opts: create_values(array: {"array" => ["default value"]}),
expect_args: ["arg1"] of String,
expect_args: ["arg1"],
},
{
argv: %w(-a array1),
Expand All @@ -813,12 +817,12 @@ describe "main command with array required false and default exists." do
{
argv: %w(-a array1 arg1),
expect_opts: create_values(array: {"array" => ["default value", "array1"]}),
expect_args: ["arg1"] of String,
expect_args: ["arg1"],
},
{
argv: %w(arg1 -a array1),
expect_opts: create_values(array: {"array" => ["default value", "array1"]}),
expect_args: ["arg1"] of String,
expect_args: ["arg1"],
},
{
argv: %w(-array), # Unintended case.
Expand Down Expand Up @@ -908,7 +912,7 @@ describe "main command with array required false only." do
Options:
-h, --help Show this help.
-a ARG, --array=ARG Array option description. [default:[]]
-a ARG, --array=ARG Array option description.
HELP_MESSAGE
Expand All @@ -918,6 +922,16 @@ describe "main command with array required false only." do
end
describe "returns opts and args when passing argv." do
[
{
argv: %w(),
expect_opts: create_values(array: {"array" => nil}),
expect_args: [] of String,
},
{
argv: %w(arg1),
expect_opts: create_values(array: {"array" => nil}),
expect_args: ["arg1"],
},
{
argv: %w(-a array1),
expect_opts: create_values(array: {"array" => ["array1"]}),
Expand All @@ -941,12 +955,12 @@ describe "main command with array required false only." do
{
argv: %w(-a array1 arg1),
expect_opts: create_values(array: {"array" => ["array1"]}),
expect_args: ["arg1"] of String,
expect_args: ["arg1"],
},
{
argv: %w(arg1 -a array1),
expect_opts: create_values(array: {"array" => ["array1"]}),
expect_args: ["arg1"] of String,
expect_args: ["arg1"],
},
{
argv: %w(-array), # Unintended case.
Expand All @@ -970,14 +984,6 @@ describe "main command with array required false only." do
end
describe "raises Exception when passing invalid argv." do
[
{
argv: %w(),
exception_message: "Please specify default value or required true. \"-a ARG\"",
},
{
argv: %w(arg1),
exception_message: "Please specify default value or required true. \"-a ARG\"",
},
{
argv: %w(-a),
exception_message: "Option that requires an argument. \"-a\"",
Expand Down
Loading

0 comments on commit bad598c

Please sign in to comment.