File: test_utils.rb

package info (click to toggle)
ruby-logging 2.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 660 kB
  • sloc: ruby: 6,139; sh: 11; makefile: 2
file content (79 lines) | stat: -rw-r--r-- 1,817 bytes parent folder | download | duplicates (3)
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