1require 'test/unit' 2require 'optparse' 3 4class TestOptionParser < Test::Unit::TestCase 5end 6class TestOptionParser::BashCompletion < Test::Unit::TestCase 7 def setup 8 @opt = OptionParser.new 9 @opt.define("-z", "zzz") {} 10 @opt.define("--foo") {} 11 @opt.define("--bar=BAR") {} 12 @opt.define("--for=TYPE", [:hello, :help, :zot]) {} 13 end 14 15 def test_empty 16 assert_equal([], @opt.candidate("")) 17 end 18 19 def test_one_hyphen 20 assert_equal(%w[-z --foo --bar= --for=], @opt.candidate("-")) 21 end 22 23 def test_two_hyphen 24 assert_equal(%w[--foo --bar= --for=], @opt.candidate("--")) 25 end 26 27 def test_long_f 28 assert_equal(%w[--foo --for=], @opt.candidate("--f")) 29 end 30 31 def test_long_for_option 32 assert_equal(%w[--for=], @opt.candidate("--for")) 33 end 34 35 def test_long_for_option_args 36 assert_equal(%w[hello help zot], @opt.candidate("--for=")) 37 end 38 39 def test_long_for_option_complete 40 assert_equal(%w[hello help], @opt.candidate("--for=h")) 41 end 42end 43