OSDN Git Service

ruby-1.9.1-rc1
[splhack/AndroidRuby.git] / lib / ruby-1.9.1-rc1 / test / optparse / test_placearg.rb
1 require 'test_optparse'
2
3 class TestOptionParser::PlaceArg < TestOptionParser
4   def setup
5     super
6     @opt.def_option("-x [VAL]") {|x| @flag = x}
7     @opt.def_option("--option [VAL]") {|x| @flag = x}
8     @opt.def_option("-n") {}
9   end
10
11   def test_short
12     assert_equal(%w"", no_error {@opt.parse!(%w"-x -n")})
13     assert_equal(nil, @flag)
14     @flag = false
15     assert_equal(%w"", no_error {@opt.parse!(%w"-x foo")})
16     assert_equal("foo", @flag)
17     assert_equal(%w"", no_error {@opt.parse!(%w"-xbar")})
18     assert_equal("bar", @flag)
19     assert_equal(%w"", no_error {@opt.parse!(%w"-x=")})
20     assert_equal("=", @flag)
21   end
22
23   def test_abbrev
24     assert_equal(%w"", no_error {@opt.parse!(%w"-o -n")})
25     assert_equal(nil, @flag)
26     @flag = false
27     assert_equal(%w"", no_error {@opt.parse!(%w"-o foo")})
28     assert_equal("foo", @flag)
29     assert_equal(%w"", no_error {@opt.parse!(%w"-obar")})
30     assert_equal("bar", @flag)
31     assert_equal(%w"", no_error {@opt.parse!(%w"-o=")})
32     assert_equal("=", @flag)
33   end
34
35   def test_long
36     assert_equal(%w"", no_error {@opt.parse!(%w"--opt -n")})
37     assert_equal(nil, @flag)
38     assert_equal(%w"foo", no_error {@opt.parse!(%w"--opt= foo")})
39     assert_equal("", @flag)
40     assert_equal(%w"", no_error {@opt.parse!(%w"--opt=foo")})
41     assert_equal("foo", @flag)
42     assert_equal(%w"", no_error {@opt.parse!(%w"--opt bar")})
43     assert_equal("bar", @flag)
44   end
45 end