test/test_option_parser.rb in cri-2.0b1 vs test/test_option_parser.rb in cri-2.0rc1

- old
+ new

@@ -4,72 +4,72 @@ def test_parse_without_options input = %w( foo bar baz ) definitions = [] - result = Cri::OptionParser.parse(input, definitions) + parser = Cri::OptionParser.parse(input, definitions) - assert_equal({}, result[:options]) - assert_equal([ 'foo', 'bar', 'baz' ], result[:arguments]) + assert_equal({}, parser.options) + assert_equal([ 'foo', 'bar', 'baz' ], parser.arguments) end def test_parse_with_invalid_option input = %w( foo -x ) definitions = [] result = nil assert_raises(Cri::OptionParser::IllegalOptionError) do - result = Cri::OptionParser.parse(input, definitions) + parser = Cri::OptionParser.parse(input, definitions) end end def test_parse_without_options input = %w( foo ) definitions = [ { :long => 'aaa', :short => 'a', :argument => :forbidden } ] - result = Cri::OptionParser.parse(input, definitions) + parser = Cri::OptionParser.parse(input, definitions) - assert(!result[:options][:aaa]) + assert(!parser.options[:aaa]) end def test_parse_with_long_valueless_option input = %w( foo --aaa bar ) definitions = [ { :long => 'aaa', :short => 'a', :argument => :forbidden } ] - result = Cri::OptionParser.parse(input, definitions) + parser = Cri::OptionParser.parse(input, definitions) - assert(result[:options][:aaa]) - assert_equal([ 'foo', 'bar' ], result[:arguments]) + assert(parser.options[:aaa]) + assert_equal([ 'foo', 'bar' ], parser.arguments) end def test_parse_with_long_valueful_option input = %w( foo --aaa xxx bar ) definitions = [ { :long => 'aaa', :short => 'a', :argument => :required } ] - result = Cri::OptionParser.parse(input, definitions) + parser = Cri::OptionParser.parse(input, definitions) - assert_equal({ :aaa => 'xxx' }, result[:options]) - assert_equal([ 'foo', 'bar' ], result[:arguments]) + assert_equal({ :aaa => 'xxx' }, parser.options) + assert_equal([ 'foo', 'bar' ], parser.arguments) end def test_parse_with_long_valueful_equalsign_option input = %w( foo --aaa=xxx bar ) definitions = [ { :long => 'aaa', :short => 'a', :argument => :required } ] - result = Cri::OptionParser.parse(input, definitions) + parser = Cri::OptionParser.parse(input, definitions) - assert_equal({ :aaa => 'xxx' }, result[:options]) - assert_equal([ 'foo', 'bar' ], result[:arguments]) + assert_equal({ :aaa => 'xxx' }, parser.options) + assert_equal([ 'foo', 'bar' ], parser.arguments) end def test_parse_with_long_valueful_option_with_missing_value input = %w( foo --aaa ) definitions = [ @@ -77,11 +77,11 @@ ] result = nil assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do - result = Cri::OptionParser.parse(input, definitions) + parser = Cri::OptionParser.parse(input, definitions) end end def test_parse_with_two_long_valueful_options input = %w( foo --all --port 2 ) @@ -91,64 +91,64 @@ ] result = nil assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do - result = Cri::OptionParser.parse(input, definitions) + parser = Cri::OptionParser.parse(input, definitions) end end def test_parse_with_long_valueless_option_with_optional_value input = %w( foo --aaa ) definitions = [ { :long => 'aaa', :short => 'a', :argument => :optional } ] - result = Cri::OptionParser.parse(input, definitions) + parser = Cri::OptionParser.parse(input, definitions) - assert(result[:options][:aaa]) - assert_equal([ 'foo' ], result[:arguments]) + assert(parser.options[:aaa]) + assert_equal([ 'foo' ], parser.arguments) end def test_parse_with_long_valueful_option_with_optional_value input = %w( foo --aaa xxx ) definitions = [ { :long => 'aaa', :short => 'a', :argument => :optional } ] - result = Cri::OptionParser.parse(input, definitions) + parser = Cri::OptionParser.parse(input, definitions) - assert_equal({ :aaa => 'xxx' }, result[:options]) - assert_equal([ 'foo' ], result[:arguments]) + assert_equal({ :aaa => 'xxx' }, parser.options) + assert_equal([ 'foo' ], parser.arguments) end def test_parse_with_long_valueless_option_with_optional_value_and_more_options input = %w( foo --aaa -b -c ) definitions = [ { :long => 'aaa', :short => 'a', :argument => :optional }, { :long => 'bbb', :short => 'b', :argument => :forbidden }, { :long => 'ccc', :short => 'c', :argument => :forbidden } ] - result = Cri::OptionParser.parse(input, definitions) + parser = Cri::OptionParser.parse(input, definitions) - assert(result[:options][:aaa]) - assert(result[:options][:bbb]) - assert(result[:options][:ccc]) - assert_equal([ 'foo' ], result[:arguments]) + assert(parser.options[:aaa]) + assert(parser.options[:bbb]) + assert(parser.options[:ccc]) + assert_equal([ 'foo' ], parser.arguments) end def test_parse_with_short_valueless_options input = %w( foo -a bar ) definitions = [ { :long => 'aaa', :short => 'a', :argument => :forbidden } ] - result = Cri::OptionParser.parse(input, definitions) + parser = Cri::OptionParser.parse(input, definitions) - assert(result[:options][:aaa]) - assert_equal([ 'foo', 'bar' ], result[:arguments]) + assert(parser.options[:aaa]) + assert_equal([ 'foo', 'bar' ], parser.arguments) end def test_parse_with_short_valueful_option_with_missing_value input = %w( foo -a ) definitions = [ @@ -156,11 +156,11 @@ ] result = nil assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do - result = Cri::OptionParser.parse(input, definitions) + parser = Cri::OptionParser.parse(input, definitions) end end def test_parse_with_short_combined_valueless_options input = %w( foo -abc bar ) @@ -168,16 +168,16 @@ { :long => 'aaa', :short => 'a', :argument => :forbidden }, { :long => 'bbb', :short => 'b', :argument => :forbidden }, { :long => 'ccc', :short => 'c', :argument => :forbidden } ] - result = Cri::OptionParser.parse(input, definitions) + parser = Cri::OptionParser.parse(input, definitions) - assert(result[:options][:aaa]) - assert(result[:options][:bbb]) - assert(result[:options][:ccc]) - assert_equal([ 'foo', 'bar' ], result[:arguments]) + assert(parser.options[:aaa]) + assert(parser.options[:bbb]) + assert(parser.options[:ccc]) + assert_equal([ 'foo', 'bar' ], parser.arguments) end def test_parse_with_short_combined_valueful_options_with_missing_value input = %w( foo -abc bar ) definitions = [ @@ -187,11 +187,11 @@ ] result = nil assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do - result = Cri::OptionParser.parse(input, definitions) + parser = Cri::OptionParser.parse(input, definitions) end end def test_parse_with_two_short_valueful_options input = %w( foo -a -p 2 ) @@ -201,81 +201,81 @@ ] result = nil assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do - result = Cri::OptionParser.parse(input, definitions) + parser = Cri::OptionParser.parse(input, definitions) end end def test_parse_with_short_valueless_option_with_optional_value input = %w( foo -a ) definitions = [ { :long => 'aaa', :short => 'a', :argument => :optional } ] - result = Cri::OptionParser.parse(input, definitions) + parser = Cri::OptionParser.parse(input, definitions) - assert(result[:options][:aaa]) - assert_equal([ 'foo' ], result[:arguments]) + assert(parser.options[:aaa]) + assert_equal([ 'foo' ], parser.arguments) end def test_parse_with_short_valueful_option_with_optional_value input = %w( foo -a xxx ) definitions = [ { :long => 'aaa', :short => 'a', :argument => :optional } ] - result = Cri::OptionParser.parse(input, definitions) + parser = Cri::OptionParser.parse(input, definitions) - assert_equal({ :aaa => 'xxx' }, result[:options]) - assert_equal([ 'foo' ], result[:arguments]) + assert_equal({ :aaa => 'xxx' }, parser.options) + assert_equal([ 'foo' ], parser.arguments) end def test_parse_with_short_valueless_option_with_optional_value_and_more_options input = %w( foo -a -b -c ) definitions = [ { :long => 'aaa', :short => 'a', :argument => :optional }, { :long => 'bbb', :short => 'b', :argument => :forbidden }, { :long => 'ccc', :short => 'c', :argument => :forbidden } ] - result = Cri::OptionParser.parse(input, definitions) + parser = Cri::OptionParser.parse(input, definitions) - assert(result[:options][:aaa]) - assert(result[:options][:bbb]) - assert(result[:options][:ccc]) - assert_equal([ 'foo' ], result[:arguments]) + assert(parser.options[:aaa]) + assert(parser.options[:bbb]) + assert(parser.options[:ccc]) + assert_equal([ 'foo' ], parser.arguments) end def test_parse_with_single_hyphen input = %w( foo - bar ) definitions = [] - result = Cri::OptionParser.parse(input, definitions) + parser = Cri::OptionParser.parse(input, definitions) - assert_equal({}, result[:options]) - assert_equal([ 'foo', '-', 'bar' ], result[:arguments]) + assert_equal({}, parser.options) + assert_equal([ 'foo', '-', 'bar' ], parser.arguments) end def test_parse_with_end_marker input = %w( foo bar -- -x --yyy -abc ) definitions = [] - result = Cri::OptionParser.parse(input, definitions) + parser = Cri::OptionParser.parse(input, definitions) - assert_equal({}, result[:options]) - assert_equal([ 'foo', 'bar', '-x', '--yyy', '-abc' ], result[:arguments]) + assert_equal({}, parser.options) + assert_equal([ 'foo', 'bar', '-x', '--yyy', '-abc' ], parser.arguments) end def test_parse_with_end_marker_between_option_key_and_value input = %w( foo --aaa -- zzz ) definitions = [ { :long => 'aaa', :short => 'a', :argument => :required } ] assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do - result = Cri::OptionParser.parse(input, definitions) + parser = Cri::OptionParser.parse(input, definitions) end end end