test/test_utils.rb in logging-0.9.0 vs test/test_utils.rb in logging-0.9.1
- old
+ new
@@ -3,11 +3,11 @@
module TestLogging
class TestUtils < Test::Unit::TestCase
- def test_getopt
+ def test_hash_getopt
opts = {
:foo => 'foo_value',
'bar' => 'bar_value',
'one' => '1',
:two => '2',
@@ -37,9 +37,52 @@
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
+
+ def test_string_reduce
+ str = 'this is the foobar string'
+ len = str.length
+
+ r = str.reduce(len + 1)
+ assert_same str, r
+
+ r = str.reduce(len)
+ assert_same str, r
+
+ r = str.reduce(len - 1)
+ assert_equal 'this is the...bar string', r
+
+ r = str.reduce(len - 10)
+ assert_equal 'this i...string', r
+
+ r = str.reduce(4)
+ assert_equal 't...', r
+
+ r = str.reduce(3)
+ assert_equal '...', r
+
+ r = str.reduce(0)
+ assert_equal '...', r
+
+ assert_raises(ArgumentError) { str.reduce(-1) }
+
+ r = str.reduce(len - 1, '##')
+ assert_equal 'this is the##obar string', r
+
+ r = str.reduce(len - 10, '##')
+ assert_equal 'this is##string', r
+
+ r = str.reduce(4, '##')
+ assert_equal 't##g', r
+
+ r = str.reduce(3, '##')
+ assert_equal 't##', r
+
+ r = str.reduce(0, '##')
+ assert_equal '##', r
end
end # class TestUtils
end # module TestLogging