Skip to content

Commit 51aed00

Browse files
committed
Add missing test cases
1 parent 0a875ad commit 51aed00

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

spec/std/option_parser_spec.cr

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ describe "OptionParser" do
791791

792792
describe "boolean args" do
793793
describe "only-negative options" do
794-
context "when chosen" do
794+
context "when option specified" do
795795
it "should accept a negative option as a value of 'false'" do
796796
flag = true
797797
args = %w(--no-verbose)
@@ -803,10 +803,11 @@ describe "OptionParser" do
803803
flag.should eq(false)
804804
end
805805
end
806-
context "when not chosen" do
806+
807+
context "when option not specified" do
807808
it "should produce a value of 'true' (the default)" do
808809
flag = true
809-
args = [] of String
810+
args = %w()
810811
OptionParser.parse(args) do |opts|
811812
opts.on("--no-verbose", "Turn off verbose") do
812813
flag = false
@@ -815,9 +816,23 @@ describe "OptionParser" do
815816
flag.should eq(true)
816817
end
817818
end
819+
820+
context "when option without 'no-' prefix specified" do
821+
it "does not recognize it" do
822+
args = %w(--verbose)
823+
824+
expect_raises(OptionParser::InvalidOption, "Invalid option: --verbose") do
825+
OptionParser.parse(args) do |opts|
826+
opts.on("--no-verbose", "Turn off verbose") do
827+
end
828+
end
829+
end
830+
end
831+
end
818832
end
833+
819834
describe "both-forms boolean" do
820-
it "should be true when chosen" do
835+
it "should be true when positive option specified" do
821836
flag = nil
822837
args = %w(--verbose)
823838
OptionParser.parse(args) do |opts|
@@ -827,7 +842,8 @@ describe "OptionParser" do
827842
end
828843
flag.should eq(true)
829844
end
830-
it "should be true when chosen" do
845+
846+
it "should be false when negative option specified" do
831847
flag = nil
832848
args = %w(--no-verbose)
833849
OptionParser.parse(args) do |opts|
@@ -837,6 +853,17 @@ describe "OptionParser" do
837853
end
838854
flag.should eq(false)
839855
end
856+
857+
it "should not be changed when option not specified" do
858+
flag = nil
859+
args = %w()
860+
OptionParser.parse(args) do |opts|
861+
opts.bool("--[no-]verbose", "Run verbosely") do |v|
862+
flag = v
863+
end
864+
end
865+
flag.should be_nil
866+
end
840867
end
841868
end
842869
end

0 commit comments

Comments
 (0)