From 0bfb185654b13237b874dc00d5719e695416b711 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 30 Oct 2022 00:36:19 +0900 Subject: [ruby/optparse] Add `raise_unknown` flag (https://github.com/ruby/optparse/pull/38) https://github.com/ruby/optparse/commit/12529653cd --- test/optparse/test_optparse.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/optparse') diff --git a/test/optparse/test_optparse.rb b/test/optparse/test_optparse.rb index 5f5ea183b0..285c4a5d1b 100644 --- a/test/optparse/test_optparse.rb +++ b/test/optparse/test_optparse.rb @@ -98,6 +98,18 @@ class TestOptionParser < Test::Unit::TestCase assert_raise(OptionParser::InvalidOption) {@opt.parse(%w(-z foo))} end + def test_raise_unknown + @opt.def_option('--foo [ARG]') {|arg| @foo = arg} + assert @opt.raise_unknown + + @opt.raise_unknown = false + assert_equal(%w[--bar], @opt.parse(%w[--foo --bar])) + assert_nil(@foo) + + assert_equal(%w[--bar], @opt.parse(%w[--foo x --bar])) + assert_equal("x", @foo) + end + def test_nonopt_pattern @opt.def_option(/^[^-]/) do |arg| assert(false, "Never gets called") -- cgit v1.2.3