Sha256: 8d18ac4a7aa8d4679aad37fc65fed8085ae002f848492bcd198f92a45a28bfb1

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

require 'minitest'
require 'minitest/autorun'
require 'minitest-power_assert'

require 'simple_option_parser'

class SimpleOptionParser

  class Test < Minitest::Test

    def test_new_then_parse
      op = SimpleOptionParser.new
      argv = %w{--foo blah}
      options = op.parse(argv)
      assert {
        options == { foo: true }
      }
      assert {
        argv == ['blah']
      }
    end

    def test_direct_parse
      argv = %w{--foo blah}
      options = SimpleOptionParser.parse(argv, foo: true)
      assert {
        options == { foo: true }
      }
      assert {
        argv == ['blah']
      }
    end

    def test_values
      op = SimpleOptionParser.new
      argv = %w{--foo --bar=xyz --zot=false --blargh=1.0 --grotz=5}
      options = op.parse(argv)
      assert {
        options == { foo: true, bar: 'xyz', zot: false, blargh: 1.0, grotz: 5 }
      }
    end

    def test_defaults
      op = SimpleOptionParser.new(foo: 'def', bar: 'ghi')
      argv = %w{--foo=abc}
      options = op.parse(argv)
      assert {
        options == { foo: 'abc', bar: 'ghi' }
      }
    end

    def test_multiple
      op = SimpleOptionParser.new
      argv = %w{--foo --bar=a --bar=b --zot=c}
      options = op.parse(argv)
      assert {
        options == { foo: true, bar: ['a', 'b'], zot: 'c' }
      }
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
simple_option_parser-0.8 test/test.rb
simple_option_parser-0.7 test/test.rb