summaryrefslogtreecommitdiff
path: root/test/optparse/test_optarg.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/optparse/test_optarg.rb')
-rw-r--r--test/optparse/test_optarg.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/optparse/test_optarg.rb b/test/optparse/test_optarg.rb
index 81127a8a37..f94460527f 100644
--- a/test/optparse/test_optarg.rb
+++ b/test/optparse/test_optarg.rb
@@ -9,6 +9,8 @@ class TestOptionParserOptArg < TestOptionParser
@opt.def_option("--regexp[=REGEXP]", Regexp) {|x| @reopt = x}
@opt.def_option "--with_underscore[=VAL]" do |x| @flag = x end
@opt.def_option "--with-hyphen[=VAL]" do |x| @flag = x end
+ @opt.def_option("--fallback[=VAL]") do |x = "fallback"| @flag = x end
+ @opt.def_option("--lambda[=VAL]", &->(x) {@flag = x})
@reopt = nil
end
@@ -57,4 +59,18 @@ class TestOptionParserOptArg < TestOptionParser
assert_equal(%w"", no_error {@opt.parse!(%w"--with_hyphen=foo4")})
assert_equal("foo4", @flag)
end
+
+ def test_default_argument
+ assert_equal(%w"", no_error {@opt.parse!(%w"--fallback=val1")})
+ assert_equal("val1", @flag)
+ assert_equal(%w"", no_error {@opt.parse!(%w"--fallback")})
+ assert_equal("fallback", @flag)
+ end
+
+ def test_lambda
+ assert_equal(%w"", no_error {@opt.parse!(%w"--lambda=lambda1")})
+ assert_equal("lambda1", @flag)
+ assert_equal(%w"", no_error {@opt.parse!(%w"--lambda")})
+ assert_equal(nil, @flag)
+ end
end