Sha256: 3ac5c7c72935b70df1a6a57f7469b4cb96843c9b477eedbc9d9127a836267852

Contents?: true

Size: 1.39 KB

Versions: 3

Compression:

Stored size: 1.39 KB

Contents

# $Id: test_utils.rb 65 2007-12-23 04:48:55Z tim_pease $

require 'test/setup.rb'
require 'stringio'

module TestLogging

  class TestUtils < Test::Unit::TestCase

    def test_getopt
      opts = {
        :foo => 'foo_value',
        'bar' => 'bar_value',
        'one' => '1',
        :two => '2',
        :three => 3.0
      }

      assert_equal('foo_value', opts.getopt(:foo))
      assert_equal('foo_value', opts.getopt('foo'))
      assert_equal(:foo_value, opts.getopt(:foo, :as => Symbol))

      assert_equal('bar_value', opts.getopt(:bar))
      assert_equal('bar_value', opts.getopt('bar'))

      assert_equal('1', opts.getopt(:one))
      assert_equal(1, opts.getopt('one', :as => Integer))
      assert_instance_of(Float, opts.getopt('one', :as => Float))

      assert_equal('2', opts.getopt(:two))
      assert_equal(['2'], opts.getopt(:two, :as => Array))

      assert_equal(3.0, opts.getopt(:three))
      assert_equal('3.0', opts.getopt('three', :as => String))

      assert_equal(nil, opts.getopt(:baz))
      assert_equal('default', opts.getopt('baz', 'default'))
      assert_equal(:default, opts.getopt(:key, 'default', :as => Symbol))
      assert_equal(['default'], opts.getopt('key', 'default', :as => Array))

      assert_equal(3.0, opts.getopt(:three, :as => Object))

      assert_nil opts.getopt(:key, :as => Symbol)
    end

  end  # class TestUtils
end  # module TestLogging

# EOF

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
logging-0.6.0 test/test_utils.rb
logging-0.6.1 test/test_utils.rb
logging-0.6.2 test/test_utils.rb