Sha256: dd563fa661052db5fe7049e6621b4d79e49dc4aa61490a802f407a2edbda62ef

Contents?: true

Size: 1.31 KB

Versions: 6

Compression:

Stored size: 1.31 KB

Contents

# Test for facets/arguments.rb.

require 'test/unit'
require 'facets/arguments.rb'

class TestArguments < Test::Unit::TestCase

  include CLI

  def test_parameters
    line = "-x baz --foo=8 bar"
    cargs = Arguments.new(line)
    args, keys = cargs.parameters
    assert_equal(['baz','bar'], args)
    assert_equal({'foo'=>'8','x'=>true}, keys)
  end

  def test_parameters_with_arity
    line = "-g a -x b -x c"
    cargs = Arguments.new(line, :g=>1, :x=>1)
    args, keys = cargs.parameters
    assert_equal({'g'=>'a','x'=>['b','c']}, keys)
    assert_equal([], args)
  end

  def test_flags
    line = "-x baz --foo=8 bar"
    cargs = Arguments.new(line)
    flags = cargs.flags
    assert_equal(['x'], flags)
  end

  def test_repeat
    line = "-x baz --foo=1 --foo=2 bar"
    cargs = Arguments.new(line)
    args, keys = cargs.parameters
    assert_equal(['baz','bar'], args)
    assert_equal({'x'=>true,'foo'=>['1','2']}, keys)
  end

  def test_preoptions
    line = "-x --foo=7 baz -y bar"
    cargs = Arguments.new(line)
    flags = cargs.preoptions
    assert_equal({'x'=>true,'foo'=>'7'}, flags)
  end

  def test_with_arity
    line = "-q baz --aq 5 bar"
    cargs = Arguments.new(line,'aq'=>1)
    words, flags = cargs.parameters
    assert_equal(['baz','bar'],words)
    assert_equal({'q'=>true,'aq'=>'5'},flags)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
facets-2.4.0 test/test_arguments.rb
facets-2.4.1 test/test_arguments.rb
facets-2.4.2 test/more/test_arguments.rb
facets-2.4.3 test/more/test_arguments.rb
facets-2.4.4 test/more/test_arguments.rb
facets-2.4.5 test/more/test_arguments.rb