2006-09-26 10:59:20 -04:00
|
|
|
require 'test/unit'
|
|
|
|
|
2006-10-03 19:53:24 -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
|