summaryrefslogtreecommitdiff
path: root/test/-ext-/test_printf.rb
blob: 29f384b1d7091383925da964d3f1d45dde71ee7a (plain)
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
require 'test/unit'
require "-test-/printf"

class Test_SPrintf < Test::Unit::TestCase
  def to_s
    "#{self.class}:#{object_id}"
  end

  def inspect
    "<#{self.class}:#{object_id}>"
  end

  def test_int
    assert_match(/\A<-?\d+>\z/, Bug::Printf.i(self))
  end

  def test_to_str
    assert_equal("<#{self.class}:#{object_id}>", Bug::Printf.s(self))
  end

  def test_inspect
    assert_equal("{<#{self.class}:#{object_id}>}", Bug::Printf.v(self))
  end

  def test_encoding
    def self.to_s
      "\u{3042 3044 3046 3048 304a}"
    end
    assert_equal("<\u{3042 3044 3046 3048 304a}>", Bug::Printf.s(self))
  end

  def test_taint
    obj = Object.new.taint
    assert_equal({to_s: true, inspect: true},
                 {
                   to_s: Bug::Printf.s(obj).tainted?,
                   inspect: Bug::Printf.v(obj).tainted?,
                 })
  end
end