2012-05-25 02:20:36 +00:00
|
|
|
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
|
2012-08-15 07:23:38 +00:00
|
|
|
|
|
|
|
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
|
2012-08-15 07:26:55 +00:00
|
|
|
|
|
|
|
def test_taint
|
2012-08-16 02:52:09 +00:00
|
|
|
obj = Object.new.taint
|
2012-08-15 07:26:55 +00:00
|
|
|
assert_equal({to_s: true, inspect: true},
|
|
|
|
{
|
2012-08-16 02:52:09 +00:00
|
|
|
to_s: Bug::Printf.s(obj).tainted?,
|
|
|
|
inspect: Bug::Printf.v(obj).tainted?,
|
2012-08-15 07:26:55 +00:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2012-08-16 02:52:09 +00:00
|
|
|
def test_untrust
|
|
|
|
obj = Object.new.untrust
|
2012-08-15 07:26:55 +00:00
|
|
|
assert_equal({to_s: true, inspect: true},
|
|
|
|
{
|
2012-08-16 02:52:09 +00:00
|
|
|
to_s: Bug::Printf.s(obj).untrusted?,
|
|
|
|
inspect: Bug::Printf.v(obj).untrusted?,
|
2012-08-15 07:26:55 +00:00
|
|
|
})
|
|
|
|
end
|
2012-05-25 02:20:36 +00:00
|
|
|
end
|