1require_relative 'test_optparse'
2
3class TestOptionParser::SummaryTest < TestOptionParser
4  def test_short_clash
5    r = nil
6    o = OptionParser.new do |opts|
7      opts.on("-f", "--first-option", "description 1", "description 2"){r = "first-option"}
8      opts.on("-t", "--test-option"){r = "test-option"}
9      opts.on("-t", "--another-test-option"){r = "another-test-option"}
10      opts.separator "this is\nseparator"
11      opts.on("-l", "--last-option"){r = "last-option"}
12    end
13    s = o.summarize
14    o.parse("-t")
15    assert_match(/--#{r}/, s.grep(/^\s*-t,/)[0])
16    assert_match(/first-option/, s[0])
17    assert_match(/description 1/, s[0])
18    assert_match(/description 2/, s[1])
19    assert_match(/last-option/, s[-1])
20  end
21
22  def test_banner
23    o = OptionParser.new("foo bar")
24    assert_equal("foo bar", o.banner)
25  end
26
27  def test_banner_from_progname
28    o = OptionParser.new
29    o.program_name = "foobar"
30    assert_equal("Usage: foobar [options]\n", o.help)
31  end
32
33  def test_summary
34    o = OptionParser.new("foo\nbar")
35    assert_equal("foo\nbar\n", o.to_s)
36    assert_equal(["foo\n", "bar"], o.to_a)
37  end
38
39  def test_summary_containing_space
40    # test for r35467. OptionParser#to_a shouldn't split str by spaces.
41    bug6348 = '[ruby-dev:45568]'
42    o = OptionParser.new("foo bar")
43    assert_equal("foo bar\n", o.to_s, bug6348)
44    assert_equal(["foo bar"], o.to_a, bug6348)
45  end
46end
47