diff options
author | Jeremy Evans <code@jeremyevans.net> | 2019-07-01 15:19:16 -0700 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-03-29 15:55:41 +0900 |
commit | eca8ffaa0b446db0a1cacc82a2e73155f6fd3fce (patch) | |
tree | b1b350e2320862b9f9d1054171eacbc4f43b1693 /test/optparse/test_optparse.rb | |
parent | d474b19b5bcae951817319b821e62e68364767ad (diff) |
[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
https://github.com/ruby/optparse/commit/dfefb2d2e2
Diffstat (limited to 'test/optparse/test_optparse.rb')
-rw-r--r-- | test/optparse/test_optparse.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/optparse/test_optparse.rb b/test/optparse/test_optparse.rb index e4aeb07aac..fec14fc318 100644 --- a/test/optparse/test_optparse.rb +++ b/test/optparse/test_optparse.rb @@ -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 |