mirror of
https://github.com/ruby/ruby.git
synced 2025-08-23 13:04:13 +02:00
[ruby/optparse] Add OptionParser#require_exact accessor
This allows you to disable allowing abbreviations of long options
and using short options for long options.
Implements Ruby Feature #11523
dfefb2d2e2
This commit is contained in:
parent
d474b19b5b
commit
eca8ffaa0b
2 changed files with 31 additions and 0 deletions
|
@ -75,4 +75,26 @@ class TestOptionParser < Test::Unit::TestCase
|
|||
assert_equal({host: "localhost", port: 8000, verbose: true}, result)
|
||||
assert_equal(true, @verbose)
|
||||
end
|
||||
|
||||
def test_require_exact
|
||||
@opt.def_option('-F', '--zrs=IRS', 'zrs')
|
||||
%w(--zrs --zr --z -zfoo -z -F -Ffoo).each do |arg|
|
||||
result = {}
|
||||
@opt.parse([arg, 'foo'], into: result)
|
||||
assert_equal({zrs: 'foo'}, result)
|
||||
end
|
||||
|
||||
@opt.require_exact = true
|
||||
%w(--zrs -F -Ffoo).each do |arg|
|
||||
result = {}
|
||||
@opt.parse([arg, 'foo'], into: result)
|
||||
assert_equal({zrs: 'foo'}, result)
|
||||
end
|
||||
|
||||
assert_raise(OptionParser::InvalidOption) {@opt.parse(%w(--zr foo))}
|
||||
assert_raise(OptionParser::InvalidOption) {@opt.parse(%w(--z foo))}
|
||||
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))}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue