summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorfatkodima <fatkodima123@gmail.com>2023-10-14 21:52:01 +0300
committergit <svn-admin@ruby-lang.org>2024-02-09 03:31:13 +0000
commitf7a407cabda6eb787fb95fc6e3c1b2215b1aec19 (patch)
tree2de17790b0b88d1fe85b57e7db7e03201b2ec83f /test
parent50bcaa62868d806ae861c9dc3353e1f4e85a99f6 (diff)
[ruby/optparse] Fix `require_exact` to work with options defined as `--[no]-something`
https://github.com/ruby/optparse/commit/4e346ad337
Diffstat (limited to 'test')
-rw-r--r--test/optparse/test_optparse.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/test/optparse/test_optparse.rb b/test/optparse/test_optparse.rb
index bfa705ad03..be9bcb8425 100644
--- a/test/optparse/test_optparse.rb
+++ b/test/optparse/test_optparse.rb
@@ -88,9 +88,9 @@ class TestOptionParser < Test::Unit::TestCase
end
@opt.require_exact = true
- %w(--zrs -F -Ffoo).each do |arg|
+ [%w(--zrs foo), %w(--zrs=foo), %w(-F foo), %w(-Ffoo)].each do |args|
result = {}
- @opt.parse([arg, 'foo'], into: result)
+ @opt.parse(args, into: result)
assert_equal({zrs: 'foo'}, result)
end
@@ -99,6 +99,14 @@ class TestOptionParser < Test::Unit::TestCase
assert_raise(OptionParser::InvalidOption) {@opt.parse(%w(-zrs foo))}
assert_raise(OptionParser::InvalidOption) {@opt.parse(%w(-zr foo))}
assert_raise(OptionParser::InvalidOption) {@opt.parse(%w(-z foo))}
+
+ @opt.def_option('-f', '--[no-]foo', 'foo') {|arg| @foo = arg}
+ @opt.parse(%w[-f])
+ assert_equal(true, @foo)
+ @opt.parse(%w[--foo])
+ assert_equal(true, @foo)
+ @opt.parse(%w[--no-foo])
+ assert_equal(false, @foo)
end
def test_raise_unknown