Sha256: 969f6ebc8db521af299a9307fc068fb63a441a6c1229ef94598fe14cf3b2295f

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

#!/usr/bin/env ruby

require 'test/unit'
require "Getopt/Declare"


class TC_Array < Test::Unit::TestCase

  def setup
    @file = __FILE__
    @args = Getopt::Declare.new( %q{
  		-v <value:i> [etc]	One or more values
  		<infile:if>		Input file [required]
  		-o <outfiles:of>...	Output files
  	}, :build )
  end

  def test_infile
    @args.parse(@file)
    assert_equal( @file, @args['<infile>'] )
  end

  def test_v_val
    @args.parse("-v 20 #@file")
    assert_equal( 20, @args['-v']['<value>'] )
    assert_equal( @file, @args['<infile>'] )
  end

  def test_v_val_etc
    @args.parse("-v 20 etc #@file")
    assert_equal( 20, @args['-v']['<value>'] )
    assert_equal( 'etc', @args['-v']['etc'] )
    assert_equal( @file, @args['<infile>'] )
  end

  def test_o_single
    @args.parse("-v 20 etc #@file -o goodbye")
    assert_equal( ['goodbye'], @args['-o'] )
  end

  def test_o_multi
    @args.parse("-v 20 etc #@file -o abc goodbye other")
    assert_equal( ['abc', 'goodbye', 'other'], @args['-o'] )
  end

  def test_unused
    @args.parse("-v 20 etc #@file crapola -o abc goodbye other")
    assert_equal( ['abc', 'goodbye', 'other'], @args['-o'] )
    assert_equal( ['crapola'], @args.unused )
  end

  def test_usage
    usage = @args.usage
    # We don't check first lines, as they contain date
    usage.sub!(/.*Options:/m, '')
    puts usage
    assert_equal( <<"EOF", usage )

                -v <value> [etc]        One or more values
                <infile>                Input file
                -o <outfiles>...        Output files
EOF
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
getopt-declare-1.25 test/test_cmdline_array.rb