OptionParser 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +110 -0
- data/docs/index.html +846 -0
- data/lib/commandline/optionparser.rb +16 -0
- data/lib/commandline/optionparser/option.rb +183 -0
- data/lib/commandline/optionparser/optiondata.rb +54 -0
- data/lib/commandline/optionparser/optionparser.rb +511 -0
- data/lib/commandline/text/format.rb +1451 -0
- data/test/tc_option.rb +121 -0
- data/test/testall.rb +16 -0
- metadata +50 -0
data/test/tc_option.rb
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
# $Id$
|
2
|
+
# $Source$
|
3
|
+
#
|
4
|
+
# Author: Jim Freeze
|
5
|
+
# Copyright (c) 2005
|
6
|
+
#
|
7
|
+
# =DESCRIPTION
|
8
|
+
# Test cases for Option Class
|
9
|
+
#
|
10
|
+
# =Revision History
|
11
|
+
# Jim.Freeze 2005/04/02 Birthday
|
12
|
+
#
|
13
|
+
|
14
|
+
require 'test/unit'
|
15
|
+
require 'commandline/optionparser'
|
16
|
+
|
17
|
+
class TC_Option < Test::Unit::TestCase
|
18
|
+
include CommandLine
|
19
|
+
|
20
|
+
def test_flag_parameters
|
21
|
+
opt = Option.new(:flag, :names => "-h")
|
22
|
+
assert_equal(%w(-h), opt.names)
|
23
|
+
assert_equal([0,0], opt.arg_arity)
|
24
|
+
assert_equal("", opt.opt_description)
|
25
|
+
assert_equal("", opt.arg_description)
|
26
|
+
assert_equal(true, opt.opt_found)
|
27
|
+
assert_equal(false, opt.opt_not_found)
|
28
|
+
assert_equal(false, opt.posix)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_posix
|
32
|
+
op = Option.new(:flag, :posix, :names => %w(-))
|
33
|
+
assert_equal(true, op.posix)
|
34
|
+
op = Option.new(:flag, :names => %w(-))
|
35
|
+
assert_equal(false, op.posix)
|
36
|
+
|
37
|
+
assert_raises(CommandLine::Option::InvalidOptionNameError) {
|
38
|
+
Option.new(:flag, :posix, :names => %w(--help))
|
39
|
+
}
|
40
|
+
assert_raises(CommandLine::Option::InvalidOptionNameError) {
|
41
|
+
Option.new(:flag, :posix, :names => %w(-help))
|
42
|
+
}
|
43
|
+
assert_nothing_raised {
|
44
|
+
Option.new(:flag, :posix, :names => %w(-h))
|
45
|
+
}
|
46
|
+
assert_nothing_raised {
|
47
|
+
Option.new(:flag, :posix, :names => %w(-H))
|
48
|
+
}
|
49
|
+
assert_nothing_raised {
|
50
|
+
Option.new(:flag, :posix, :names => %w(-))
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_no_dash_name
|
55
|
+
assert_raises(CommandLine::Option::InvalidOptionNameError) {
|
56
|
+
Option.new(:flag, :names => ["fred"])
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_flag_constructor
|
61
|
+
opt = nil
|
62
|
+
assert_nothing_raised { opt = Option.new(:flag, :names => %w(--debug -d) ) }
|
63
|
+
assert_equal("Sets debug to true.", opt.opt_description)
|
64
|
+
|
65
|
+
opt = Option.new(:flag,
|
66
|
+
:names => %w(--debug -d),
|
67
|
+
:opt_description => ""
|
68
|
+
)
|
69
|
+
assert_equal("", opt.opt_description)
|
70
|
+
|
71
|
+
opt = Option.new(:flag,
|
72
|
+
:names => %w(--debug -d),
|
73
|
+
:opt_description => "Custom description"
|
74
|
+
)
|
75
|
+
assert_equal("Custom description", opt.opt_description)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_block_constructor
|
79
|
+
assert_raises(CommandLine::Option::MissingPropertyError) {
|
80
|
+
opt = Option.new { |opp| opp.names = %w(--fred -f) }
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_no_arity
|
85
|
+
opt = nil
|
86
|
+
assert_nothing_raised { opt = Option.new(:flag, :names => %w(--debug -d) ) }
|
87
|
+
assert_equal([0,0], opt.arg_arity)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_arity_is_number
|
91
|
+
opt = nil
|
92
|
+
assert_nothing_raised { opt =
|
93
|
+
Option.new(:names => %w(--debug -d),
|
94
|
+
:arg_arity => 1) }
|
95
|
+
assert_equal([1,1], opt.arg_arity)
|
96
|
+
|
97
|
+
opt = nil
|
98
|
+
assert_nothing_raised { opt =
|
99
|
+
Option.new(:names => %w(--debug -d),
|
100
|
+
:arg_arity => 2) }
|
101
|
+
assert_equal([2,2], opt.arg_arity)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_names_not_array
|
105
|
+
op = nil
|
106
|
+
assert_nothing_raised { op = Option.new(:flag, :names => "-fred") }
|
107
|
+
assert_equal(["-fred"], op.names)
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_incompatible_properties
|
111
|
+
assert_raises(CommandLine::Option::InvalidArgumentArityError) {
|
112
|
+
opt = Option.new(:flag, :names => "-a", :arg_arity => 1) }
|
113
|
+
assert_raises(CommandLine::Option::InvalidArgumentArityError) {
|
114
|
+
Option.new(:flag, :names => "-b", :arg_arity => 1) }
|
115
|
+
|
116
|
+
assert_raises(CommandLine::Option::InvalidOptionNameError) {
|
117
|
+
Option.new(:posix, :names => "--fred") }
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
end#class TC_Option
|
data/test/testall.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib")
|
4
|
+
|
5
|
+
require 'commandline/optionparser'
|
6
|
+
|
7
|
+
#tc = %w( tc_option.rb tc_optionparser.rb tc_optiondata.rb )
|
8
|
+
tc = Dir["tc_*rb"]
|
9
|
+
|
10
|
+
tc.each { |lib|
|
11
|
+
fork {
|
12
|
+
require lib
|
13
|
+
#puts "===> Testing #{lib}"
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.10
|
3
|
+
specification_version: 1
|
4
|
+
name: OptionParser
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.5.0
|
7
|
+
date: 2005-06-16
|
8
|
+
summary: A flexible command line option parser.
|
9
|
+
require_paths:
|
10
|
+
- lib/commandline
|
11
|
+
email: optionpaser@freeze.org
|
12
|
+
homepage: http://optionparser.rubyforge.org/
|
13
|
+
rubyforge_project:
|
14
|
+
description:
|
15
|
+
autorequire: optionparser
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
-
|
22
|
+
- ">"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.0.0
|
25
|
+
version:
|
26
|
+
platform: ruby
|
27
|
+
authors:
|
28
|
+
- Jim Freeze
|
29
|
+
files:
|
30
|
+
- docs/api
|
31
|
+
- docs/index.html
|
32
|
+
- lib/commandline
|
33
|
+
- lib/commandline/optionparser
|
34
|
+
- lib/commandline/optionparser.rb
|
35
|
+
- lib/commandline/text
|
36
|
+
- lib/commandline/optionparser/option.rb
|
37
|
+
- lib/commandline/optionparser/optiondata.rb
|
38
|
+
- lib/commandline/optionparser/optionparser.rb
|
39
|
+
- lib/commandline/text/format.rb
|
40
|
+
- README
|
41
|
+
test_files:
|
42
|
+
- test/testall.rb
|
43
|
+
- test/tc_option.rb
|
44
|
+
rdoc_options: []
|
45
|
+
extra_rdoc_files:
|
46
|
+
- README
|
47
|
+
executables: []
|
48
|
+
extensions: []
|
49
|
+
requirements: []
|
50
|
+
dependencies: []
|