Class: TC_testParsing
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- TC_testParsing
- Defined in:
- lib/bbcloud/vendor/gli/test/tc_parsing.rb
Instance Method Summary collapse
- #teardown ⇒ Object
- #test_case_that_busted ⇒ Object
- #test_parse_command_line ⇒ Object
- #test_parse_command_line_all_switches ⇒ Object
- #test_parse_command_line_errors ⇒ Object
- #test_parse_command_line_errors_2 ⇒ Object
- #test_parse_command_line_simple ⇒ Object
- #test_parse_command_line_simplish ⇒ Object
- #test_parse_command_line_with_stop_processing ⇒ Object
- #test_parse_command_line_with_stop_processing2 ⇒ Object
- #test_possible_issue_with_numbers ⇒ Object
- #test_repeated_arguments ⇒ Object
- #test_switch_and_flag_order ⇒ Object
- #test_switch_and_flag_order_with_global ⇒ Object
Instance Method Details
#teardown ⇒ Object
276 277 278 |
# File 'lib/bbcloud/vendor/gli/test/tc_parsing.rb', line 276 def teardown GLI.reset end |
#test_case_that_busted ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/bbcloud/vendor/gli/test/tc_parsing.rb', line 206 def test_case_that_busted GLI.reset GLI.desc 'Some Global Option' GLI.switch :g glob = nil verbose = nil glob_verbose = nil configure = nil args = nil GLI.desc 'Some Basic Command' GLI.command :basic do |c| c.desc 'be verbose' c.switch :v c.desc 'configure something' c.flag [:c,:configure] c.action do |,,arguments| glob = [:g] ? 'true' : 'false' verbose = [:v] ? 'true' : 'false' glob_verbose = [:v] ? 'true' : 'false' configure = [:c] args = arguments end end args = %w(-g basic -v -c foo bar baz quux) ,command,,arguments = GLI.(args) assert([:g]) assert_equal(:basic,command.name) assert([:v]) assert_equal('foo',[:c]) assert_equal(%w(bar baz quux),arguments) end |
#test_parse_command_line ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/bbcloud/vendor/gli/test/tc_parsing.rb', line 49 def test_parse_command_line GLI.reset GLI.switch :v GLI.flag :f GLI.command :doit do |c| c.flag :file c.flag :v end argv = %w(-v -f blah doit -v 4 --file=foo bar) ,command,,arguments = GLI.(argv) assert([:v]) assert_equal('blah',[:f]) assert_equal(:doit,command.name) assert_equal('4',[:v]) assert_equal('foo',[:file]) assert_equal(1,arguments.size) assert_equal('bar',arguments[0]) end |
#test_parse_command_line_all_switches ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/bbcloud/vendor/gli/test/tc_parsing.rb', line 156 def test_parse_command_line_all_switches GLI.reset argv = %w(-v -f doit -f -v -x) GLI.switch :v GLI.switch :f GLI.command :doit do |c| c.flag :file c.switch :v c.switch :f c.switch :x end ,command,,arguments = GLI.(argv) assert([:v]) assert([:f]) assert_equal(:doit,command.name) assert([:f]) assert([:v]) assert([:x]) assert_equal(0,arguments.size) end |
#test_parse_command_line_errors ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/bbcloud/vendor/gli/test/tc_parsing.rb', line 68 def test_parse_command_line_errors GLI.reset GLI.switch :v GLI.flag :f GLI.command :doit do |c| c.flag :file c.flag :v end argv = %w(-x doit) assert_raises(UnknownGlobalArgument) do ,command,,arguments = GLI.(argv) end end |
#test_parse_command_line_errors_2 ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/bbcloud/vendor/gli/test/tc_parsing.rb', line 82 def test_parse_command_line_errors_2 GLI.reset GLI.switch :v GLI.flag :f GLI.command :doit do |c| c.flag :file c.flag :v end argv = %w(doit -x) assert_raises(UnknownCommandArgument) do ,command,,arguments = GLI.(argv) end end |
#test_parse_command_line_simple ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/bbcloud/vendor/gli/test/tc_parsing.rb', line 7 def test_parse_command_line_simple GLI.reset GLI.switch :v GLI.flag :f GLI.command :doit do |c| c.flag :file c.flag :v end argv = %w(-v doit) ,command,,arguments = GLI.(argv) assert([:v]) assert_equal(:doit,command.name) end |
#test_parse_command_line_simplish ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/bbcloud/vendor/gli/test/tc_parsing.rb', line 35 def test_parse_command_line_simplish GLI.reset GLI.switch :v GLI.flag :f GLI.command :doit do |c| c.flag :file c.flag :v end argv = %w(doit) ,command,,arguments = GLI.(argv) assert(![:v]) assert_equal(:doit,command.name) end |
#test_parse_command_line_with_stop_processing ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/bbcloud/vendor/gli/test/tc_parsing.rb', line 114 def test_parse_command_line_with_stop_processing GLI.reset argv = %w(-v -f doit -f -v -x -- -blah crud foo --x=blah) GLI.switch :v GLI.switch :f GLI.command :doit do |c| c.flag :file c.switch :v c.switch :f c.switch :x end ,command,,arguments = GLI.(argv) assert([:v]) assert([:f]) assert_equal(:doit,command.name) assert([:f]) assert([:v]) assert([:x]) assert_equal(['-blah','crud','foo','--x=blah'],arguments) end |
#test_parse_command_line_with_stop_processing2 ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/bbcloud/vendor/gli/test/tc_parsing.rb', line 135 def test_parse_command_line_with_stop_processing2 GLI.reset argv = %w(-v -f doit -f -v -x --) GLI.switch :v GLI.switch :f GLI.command :doit do |c| c.flag :file c.switch :v c.switch :f c.switch :x end ,command,,arguments = GLI.(argv) assert([:v]) assert([:f]) assert_equal(:doit,command.name) assert([:f]) assert([:v]) assert([:x]) assert_equal([],arguments) end |
#test_possible_issue_with_numbers ⇒ Object
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/bbcloud/vendor/gli/test/tc_parsing.rb', line 238 def test_possible_issue_with_numbers GLI.reset GLI.desc 'Create a day''s worth of data for a particular service point' GLI.arg_name 'service point ids' GLI.command :data do |c| c.desc 'Type of data' c.arg_name 'either bill, day, or halfhour' c.flag [:t,:type] c.desc 'Date for the reads (start date for billing)' c.arg_name 'date (in yyyy-mm-dd format)' c.default_value '2010-04-01' c.flag [:d,:date] c.desc 'Number of reads, for billing' c.arg_name 'number' c.default_value '1' c.flag :n c.desc 'Make like gas data' c.switch :g c.action do |,,args| raise "at least one service point id required" if args.nil? || args.empty? Generate::Data.new([:t],[:d],[:n].to_i,[:g],args).go end end args = %w(data -t bill -n 10 1234) ,command,,arguments = GLI.(args) assert(.empty?) assert_equal(:data,command.name) assert_equal('bill',[:t]) assert_equal('10',[:n]) assert_equal(['1234'],arguments) end |
#test_repeated_arguments ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bbcloud/vendor/gli/test/tc_parsing.rb', line 21 def test_repeated_arguments GLI.reset GLI.command :doit do |c| c.flag :file c.flag :v end argv = %w(doit foo foo bar) ,command,,arguments = GLI.(argv) assert_equal 3,arguments.size assert_equal "foo",arguments[0] assert_equal "foo",arguments[1] assert_equal "bar",arguments[2] end |
#test_switch_and_flag_order ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/bbcloud/vendor/gli/test/tc_parsing.rb', line 177 def test_switch_and_flag_order GLI.reset GLI.command :doit do |c| c.desc "list stuff" c.flag [:l,'stuff'] end argv = %w(doit -l 10 list) ,command,,arguments = GLI.(argv) assert_equal '10', [:l] assert arguments.include?('list') end |
#test_switch_and_flag_order_with_global ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/bbcloud/vendor/gli/test/tc_parsing.rb', line 190 def test_switch_and_flag_order_with_global GLI.reset argv = %w(-v -f doit list -l 10) GLI.switch :v GLI.switch :f GLI.command :doit do |c| c.desc "list stuff" c.flag [:l,'stuff'] end ,command,,arguments = GLI.(argv) assert_equal '10', [:l] assert arguments.include?('list') end |