1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
require File.expand_path('setup', File.dirname(__FILE__))
module TestLogging
class TestUtils < Test::Unit::TestCase
def test_string_shrink
str = 'this is the foobar string'
len = str.length
r = str.shrink(len + 1)
assert_same str, r
r = str.shrink(len)
assert_same str, r
r = str.shrink(len - 1)
assert_equal 'this is the...bar string', r
r = str.shrink(len - 10)
assert_equal 'this i...string', r
r = str.shrink(4)
assert_equal 't...', r
r = str.shrink(3)
assert_equal '...', r
r = str.shrink(0)
assert_equal '...', r
assert_raises(ArgumentError) { str.shrink(-1) }
r = str.shrink(len - 1, '##')
assert_equal 'this is the##obar string', r
r = str.shrink(len - 10, '##')
assert_equal 'this is##string', r
r = str.shrink(4, '##')
assert_equal 't##g', r
r = str.shrink(3, '##')
assert_equal 't##', r
r = str.shrink(0, '##')
assert_equal '##', r
end
def test_logger_name
assert_equal 'Array', Array.logger_name
# some lines are commented out for compatibility with ruby 1.9
c = Class.new(Array)
# assert_equal '', c.name
assert_equal 'Array', c.logger_name
meta = class << Array; self; end
# assert_equal '', meta.name
assert_equal 'Array', meta.logger_name
m = Module.new
# assert_equal '', m.name
assert_equal 'anonymous', m.logger_name
c = Class.new(::Logging::Logger)
# assert_equal '', c.name
assert_equal 'Logging::Logger', c.logger_name
meta = class << ::Logging::Logger; self; end
# assert_equal '', meta.name
assert_equal 'Logging::Logger', meta.logger_name
end
end # class TestUtils
end # module TestLogging
|