2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2006-09-26 10:59:20 -04:00
|
|
|
require 'test/unit'
|
2010-02-02 08:58:56 -05:00
|
|
|
require 'optparse'
|
2006-09-26 10:59:20 -04:00
|
|
|
|
2022-04-22 16:01:43 -04:00
|
|
|
class TestOptionParserGetopts < Test::Unit::TestCase
|
2006-09-26 10:59:20 -04:00
|
|
|
def setup
|
|
|
|
@opt = OptionParser.new
|
|
|
|
end
|
|
|
|
|
2006-09-26 11:20:05 -04:00
|
|
|
def test_short_noarg
|
|
|
|
o = @opt.getopts(%w[-a], "ab")
|
|
|
|
assert_equal(true, o['a'])
|
|
|
|
assert_equal(false, o['b'])
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_short_arg
|
|
|
|
o = @opt.getopts(%w[-a1], "a:b:")
|
|
|
|
assert_equal("1", o['a'])
|
|
|
|
assert_equal(nil, o['b'])
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_long_noarg
|
|
|
|
o = @opt.getopts(%w[--foo], "", "foo", "bar")
|
|
|
|
assert_equal(true, o['foo'])
|
|
|
|
assert_equal(false, o['bar'])
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_long_arg
|
|
|
|
o = @opt.getopts(%w[--bar ZOT], "", "foo:FOO", "bar:BAR")
|
|
|
|
assert_equal("FOO", o['foo'])
|
|
|
|
assert_equal("ZOT", o['bar'])
|
2006-09-26 10:59:20 -04:00
|
|
|
end
|
|
|
|
end
|