Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby18/lib64/ruby/1.8
File: pp.rb
# == Pretty-printer for Ruby objects.
[0] Fix | Delete
#
[1] Fix | Delete
# = Which seems better?
[2] Fix | Delete
#
[3] Fix | Delete
# non-pretty-printed output by #p is:
[4] Fix | Delete
# #<PP:0x81fedf0 @genspace=#<Proc:0x81feda0>, @group_queue=#<PrettyPrint::GroupQueue:0x81fed3c @queue=[[#<PrettyPrint::Group:0x81fed78 @breakables=[], @depth=0, @break=false>], []]>, @buffer=[], @newline="\n", @group_stack=[#<PrettyPrint::Group:0x81fed78 @breakables=[], @depth=0, @break=false>], @buffer_width=0, @indent=0, @maxwidth=79, @output_width=2, @output=#<IO:0x8114ee4>>
[5] Fix | Delete
#
[6] Fix | Delete
# pretty-printed output by #pp is:
[7] Fix | Delete
# #<PP:0x81fedf0
[8] Fix | Delete
# @buffer=[],
[9] Fix | Delete
# @buffer_width=0,
[10] Fix | Delete
# @genspace=#<Proc:0x81feda0>,
[11] Fix | Delete
# @group_queue=
[12] Fix | Delete
# #<PrettyPrint::GroupQueue:0x81fed3c
[13] Fix | Delete
# @queue=
[14] Fix | Delete
# [[#<PrettyPrint::Group:0x81fed78 @break=false, @breakables=[], @depth=0>],
[15] Fix | Delete
# []]>,
[16] Fix | Delete
# @group_stack=
[17] Fix | Delete
# [#<PrettyPrint::Group:0x81fed78 @break=false, @breakables=[], @depth=0>],
[18] Fix | Delete
# @indent=0,
[19] Fix | Delete
# @maxwidth=79,
[20] Fix | Delete
# @newline="\n",
[21] Fix | Delete
# @output=#<IO:0x8114ee4>,
[22] Fix | Delete
# @output_width=2>
[23] Fix | Delete
#
[24] Fix | Delete
# I like the latter. If you do too, this library is for you.
[25] Fix | Delete
#
[26] Fix | Delete
# = Usage
[27] Fix | Delete
#
[28] Fix | Delete
# pp(obj)
[29] Fix | Delete
#
[30] Fix | Delete
# output +obj+ to +$>+ in pretty printed format.
[31] Fix | Delete
#
[32] Fix | Delete
# It returns +nil+.
[33] Fix | Delete
#
[34] Fix | Delete
# = Output Customization
[35] Fix | Delete
# To define your customized pretty printing function for your classes,
[36] Fix | Delete
# redefine a method #pretty_print(+pp+) in the class.
[37] Fix | Delete
# It takes an argument +pp+ which is an instance of the class PP.
[38] Fix | Delete
# The method should use PP#text, PP#breakable, PP#nest, PP#group and
[39] Fix | Delete
# PP#pp to print the object.
[40] Fix | Delete
#
[41] Fix | Delete
# = Author
[42] Fix | Delete
# Tanaka Akira <akr@m17n.org>
[43] Fix | Delete
[44] Fix | Delete
require 'prettyprint'
[45] Fix | Delete
[46] Fix | Delete
module Kernel
[47] Fix | Delete
# returns a pretty printed object as a string.
[48] Fix | Delete
def pretty_inspect
[49] Fix | Delete
PP.pp(self, '')
[50] Fix | Delete
end
[51] Fix | Delete
[52] Fix | Delete
private
[53] Fix | Delete
# prints arguments in pretty form.
[54] Fix | Delete
#
[55] Fix | Delete
# pp returns nil.
[56] Fix | Delete
def pp(*objs) # :doc:
[57] Fix | Delete
objs.each {|obj|
[58] Fix | Delete
PP.pp(obj)
[59] Fix | Delete
}
[60] Fix | Delete
nil
[61] Fix | Delete
end
[62] Fix | Delete
module_function :pp
[63] Fix | Delete
end
[64] Fix | Delete
[65] Fix | Delete
class PP < PrettyPrint
[66] Fix | Delete
# Outputs +obj+ to +out+ in pretty printed format of
[67] Fix | Delete
# +width+ columns in width.
[68] Fix | Delete
#
[69] Fix | Delete
# If +out+ is omitted, +$>+ is assumed.
[70] Fix | Delete
# If +width+ is omitted, 79 is assumed.
[71] Fix | Delete
#
[72] Fix | Delete
# PP.pp returns +out+.
[73] Fix | Delete
def PP.pp(obj, out=$>, width=79)
[74] Fix | Delete
q = PP.new(out, width)
[75] Fix | Delete
q.guard_inspect_key {q.pp obj}
[76] Fix | Delete
q.flush
[77] Fix | Delete
#$pp = q
[78] Fix | Delete
out << "\n"
[79] Fix | Delete
end
[80] Fix | Delete
[81] Fix | Delete
# Outputs +obj+ to +out+ like PP.pp but with no indent and
[82] Fix | Delete
# newline.
[83] Fix | Delete
#
[84] Fix | Delete
# PP.singleline_pp returns +out+.
[85] Fix | Delete
def PP.singleline_pp(obj, out=$>)
[86] Fix | Delete
q = SingleLine.new(out)
[87] Fix | Delete
q.guard_inspect_key {q.pp obj}
[88] Fix | Delete
q.flush
[89] Fix | Delete
out
[90] Fix | Delete
end
[91] Fix | Delete
[92] Fix | Delete
# :stopdoc:
[93] Fix | Delete
def PP.mcall(obj, mod, meth, *args, &block)
[94] Fix | Delete
mod.instance_method(meth).bind(obj).call(*args, &block)
[95] Fix | Delete
end
[96] Fix | Delete
# :startdoc:
[97] Fix | Delete
[98] Fix | Delete
@sharing_detection = false
[99] Fix | Delete
class << self
[100] Fix | Delete
# Returns the sharing detection flag as a boolean value.
[101] Fix | Delete
# It is false by default.
[102] Fix | Delete
attr_accessor :sharing_detection
[103] Fix | Delete
end
[104] Fix | Delete
[105] Fix | Delete
module PPMethods
[106] Fix | Delete
InspectKey = :__inspect_key__
[107] Fix | Delete
[108] Fix | Delete
def guard_inspect_key
[109] Fix | Delete
if Thread.current[InspectKey] == nil
[110] Fix | Delete
Thread.current[InspectKey] = []
[111] Fix | Delete
end
[112] Fix | Delete
[113] Fix | Delete
save = Thread.current[InspectKey]
[114] Fix | Delete
[115] Fix | Delete
begin
[116] Fix | Delete
Thread.current[InspectKey] = []
[117] Fix | Delete
yield
[118] Fix | Delete
ensure
[119] Fix | Delete
Thread.current[InspectKey] = save
[120] Fix | Delete
end
[121] Fix | Delete
end
[122] Fix | Delete
[123] Fix | Delete
# Adds +obj+ to the pretty printing buffer
[124] Fix | Delete
# using Object#pretty_print or Object#pretty_print_cycle.
[125] Fix | Delete
#
[126] Fix | Delete
# Object#pretty_print_cycle is used when +obj+ is already
[127] Fix | Delete
# printed, a.k.a the object reference chain has a cycle.
[128] Fix | Delete
def pp(obj)
[129] Fix | Delete
id = obj.__id__
[130] Fix | Delete
[131] Fix | Delete
if Thread.current[InspectKey].include? id
[132] Fix | Delete
group {obj.pretty_print_cycle self}
[133] Fix | Delete
return
[134] Fix | Delete
end
[135] Fix | Delete
[136] Fix | Delete
begin
[137] Fix | Delete
Thread.current[InspectKey] << id
[138] Fix | Delete
group {obj.pretty_print self}
[139] Fix | Delete
ensure
[140] Fix | Delete
Thread.current[InspectKey].pop unless PP.sharing_detection
[141] Fix | Delete
end
[142] Fix | Delete
end
[143] Fix | Delete
[144] Fix | Delete
# A convenience method which is same as follows:
[145] Fix | Delete
#
[146] Fix | Delete
# group(1, '#<' + obj.class.name, '>') { ... }
[147] Fix | Delete
def object_group(obj, &block) # :yield:
[148] Fix | Delete
group(1, '#<' + obj.class.name, '>', &block)
[149] Fix | Delete
end
[150] Fix | Delete
[151] Fix | Delete
def object_address_group(obj, &block)
[152] Fix | Delete
id = "%x" % (obj.__id__ * 2)
[153] Fix | Delete
id.sub!(/\Af(?=[[:xdigit:]]{2}+\z)/, '') if id.sub!(/\A\.\./, '')
[154] Fix | Delete
group(1, "\#<#{obj.class}:0x#{id}", '>', &block)
[155] Fix | Delete
end
[156] Fix | Delete
[157] Fix | Delete
# A convenience method which is same as follows:
[158] Fix | Delete
#
[159] Fix | Delete
# text ','
[160] Fix | Delete
# breakable
[161] Fix | Delete
def comma_breakable
[162] Fix | Delete
text ','
[163] Fix | Delete
breakable
[164] Fix | Delete
end
[165] Fix | Delete
[166] Fix | Delete
# Adds a separated list.
[167] Fix | Delete
# The list is separated by comma with breakable space, by default.
[168] Fix | Delete
#
[169] Fix | Delete
# #seplist iterates the +list+ using +iter_method+.
[170] Fix | Delete
# It yields each object to the block given for #seplist.
[171] Fix | Delete
# The procedure +separator_proc+ is called between each yields.
[172] Fix | Delete
#
[173] Fix | Delete
# If the iteration is zero times, +separator_proc+ is not called at all.
[174] Fix | Delete
#
[175] Fix | Delete
# If +separator_proc+ is nil or not given,
[176] Fix | Delete
# +lambda { comma_breakable }+ is used.
[177] Fix | Delete
# If +iter_method+ is not given, :each is used.
[178] Fix | Delete
#
[179] Fix | Delete
# For example, following 3 code fragments has similar effect.
[180] Fix | Delete
#
[181] Fix | Delete
# q.seplist([1,2,3]) {|v| xxx v }
[182] Fix | Delete
#
[183] Fix | Delete
# q.seplist([1,2,3], lambda { comma_breakable }, :each) {|v| xxx v }
[184] Fix | Delete
#
[185] Fix | Delete
# xxx 1
[186] Fix | Delete
# q.comma_breakable
[187] Fix | Delete
# xxx 2
[188] Fix | Delete
# q.comma_breakable
[189] Fix | Delete
# xxx 3
[190] Fix | Delete
def seplist(list, sep=nil, iter_method=:each) # :yield: element
[191] Fix | Delete
sep ||= lambda { comma_breakable }
[192] Fix | Delete
first = true
[193] Fix | Delete
list.__send__(iter_method) {|*v|
[194] Fix | Delete
if first
[195] Fix | Delete
first = false
[196] Fix | Delete
else
[197] Fix | Delete
sep.call
[198] Fix | Delete
end
[199] Fix | Delete
yield(*v)
[200] Fix | Delete
}
[201] Fix | Delete
end
[202] Fix | Delete
[203] Fix | Delete
def pp_object(obj)
[204] Fix | Delete
object_address_group(obj) {
[205] Fix | Delete
seplist(obj.pretty_print_instance_variables, lambda { text ',' }) {|v|
[206] Fix | Delete
breakable
[207] Fix | Delete
v = v.to_s if Symbol === v
[208] Fix | Delete
text v
[209] Fix | Delete
text '='
[210] Fix | Delete
group(1) {
[211] Fix | Delete
breakable ''
[212] Fix | Delete
pp(obj.instance_eval(v))
[213] Fix | Delete
}
[214] Fix | Delete
}
[215] Fix | Delete
}
[216] Fix | Delete
end
[217] Fix | Delete
[218] Fix | Delete
def pp_hash(obj)
[219] Fix | Delete
group(1, '{', '}') {
[220] Fix | Delete
seplist(obj, nil, :each_pair) {|k, v|
[221] Fix | Delete
group {
[222] Fix | Delete
pp k
[223] Fix | Delete
text '=>'
[224] Fix | Delete
group(1) {
[225] Fix | Delete
breakable ''
[226] Fix | Delete
pp v
[227] Fix | Delete
}
[228] Fix | Delete
}
[229] Fix | Delete
}
[230] Fix | Delete
}
[231] Fix | Delete
end
[232] Fix | Delete
end
[233] Fix | Delete
[234] Fix | Delete
include PPMethods
[235] Fix | Delete
[236] Fix | Delete
class SingleLine < PrettyPrint::SingleLine
[237] Fix | Delete
include PPMethods
[238] Fix | Delete
end
[239] Fix | Delete
[240] Fix | Delete
module ObjectMixin
[241] Fix | Delete
# 1. specific pretty_print
[242] Fix | Delete
# 2. specific inspect
[243] Fix | Delete
# 3. specific to_s if instance variable is empty
[244] Fix | Delete
# 4. generic pretty_print
[245] Fix | Delete
[246] Fix | Delete
# A default pretty printing method for general objects.
[247] Fix | Delete
# It calls #pretty_print_instance_variables to list instance variables.
[248] Fix | Delete
#
[249] Fix | Delete
# If +self+ has a customized (redefined) #inspect method,
[250] Fix | Delete
# the result of self.inspect is used but it obviously has no
[251] Fix | Delete
# line break hints.
[252] Fix | Delete
#
[253] Fix | Delete
# This module provides predefined #pretty_print methods for some of
[254] Fix | Delete
# the most commonly used built-in classes for convenience.
[255] Fix | Delete
def pretty_print(q)
[256] Fix | Delete
if /\(Kernel\)#/ !~ Object.instance_method(:method).bind(self).call(:inspect).inspect
[257] Fix | Delete
q.text self.inspect
[258] Fix | Delete
elsif /\(Kernel\)#/ !~ Object.instance_method(:method).bind(self).call(:to_s).inspect && instance_variables.empty?
[259] Fix | Delete
q.text self.to_s
[260] Fix | Delete
else
[261] Fix | Delete
q.pp_object(self)
[262] Fix | Delete
end
[263] Fix | Delete
end
[264] Fix | Delete
[265] Fix | Delete
# A default pretty printing method for general objects that are
[266] Fix | Delete
# detected as part of a cycle.
[267] Fix | Delete
def pretty_print_cycle(q)
[268] Fix | Delete
q.object_address_group(self) {
[269] Fix | Delete
q.breakable
[270] Fix | Delete
q.text '...'
[271] Fix | Delete
}
[272] Fix | Delete
end
[273] Fix | Delete
[274] Fix | Delete
# Returns a sorted array of instance variable names.
[275] Fix | Delete
#
[276] Fix | Delete
# This method should return an array of names of instance variables as symbols or strings as:
[277] Fix | Delete
# +[:@a, :@b]+.
[278] Fix | Delete
def pretty_print_instance_variables
[279] Fix | Delete
instance_variables.sort
[280] Fix | Delete
end
[281] Fix | Delete
[282] Fix | Delete
# Is #inspect implementation using #pretty_print.
[283] Fix | Delete
# If you implement #pretty_print, it can be used as follows.
[284] Fix | Delete
#
[285] Fix | Delete
# alias inspect pretty_print_inspect
[286] Fix | Delete
#
[287] Fix | Delete
# However, doing this requires that every class that #inspect is called on
[288] Fix | Delete
# implement #pretty_print, or a RuntimeError will be raised.
[289] Fix | Delete
def pretty_print_inspect
[290] Fix | Delete
if /\(PP::ObjectMixin\)#/ =~ Object.instance_method(:method).bind(self).call(:pretty_print).inspect
[291] Fix | Delete
raise "pretty_print is not overridden for #{self.class}"
[292] Fix | Delete
end
[293] Fix | Delete
PP.singleline_pp(self, '')
[294] Fix | Delete
end
[295] Fix | Delete
end
[296] Fix | Delete
end
[297] Fix | Delete
[298] Fix | Delete
class Array
[299] Fix | Delete
def pretty_print(q)
[300] Fix | Delete
q.group(1, '[', ']') {
[301] Fix | Delete
q.seplist(self) {|v|
[302] Fix | Delete
q.pp v
[303] Fix | Delete
}
[304] Fix | Delete
}
[305] Fix | Delete
end
[306] Fix | Delete
[307] Fix | Delete
def pretty_print_cycle(q)
[308] Fix | Delete
q.text(empty? ? '[]' : '[...]')
[309] Fix | Delete
end
[310] Fix | Delete
end
[311] Fix | Delete
[312] Fix | Delete
class Hash
[313] Fix | Delete
def pretty_print(q)
[314] Fix | Delete
q.pp_hash self
[315] Fix | Delete
end
[316] Fix | Delete
[317] Fix | Delete
def pretty_print_cycle(q)
[318] Fix | Delete
q.text(empty? ? '{}' : '{...}')
[319] Fix | Delete
end
[320] Fix | Delete
end
[321] Fix | Delete
[322] Fix | Delete
class << ENV
[323] Fix | Delete
def pretty_print(q)
[324] Fix | Delete
q.pp_hash self
[325] Fix | Delete
end
[326] Fix | Delete
end
[327] Fix | Delete
[328] Fix | Delete
class Struct
[329] Fix | Delete
def pretty_print(q)
[330] Fix | Delete
q.group(1, '#<struct ' + PP.mcall(self, Kernel, :class).name, '>') {
[331] Fix | Delete
q.seplist(PP.mcall(self, Struct, :members), lambda { q.text "," }) {|member|
[332] Fix | Delete
q.breakable
[333] Fix | Delete
q.text member.to_s
[334] Fix | Delete
q.text '='
[335] Fix | Delete
q.group(1) {
[336] Fix | Delete
q.breakable ''
[337] Fix | Delete
q.pp self[member]
[338] Fix | Delete
}
[339] Fix | Delete
}
[340] Fix | Delete
}
[341] Fix | Delete
end
[342] Fix | Delete
[343] Fix | Delete
def pretty_print_cycle(q)
[344] Fix | Delete
q.text sprintf("#<struct %s:...>", PP.mcall(self, Kernel, :class).name)
[345] Fix | Delete
end
[346] Fix | Delete
end
[347] Fix | Delete
[348] Fix | Delete
class Range
[349] Fix | Delete
def pretty_print(q)
[350] Fix | Delete
q.pp self.begin
[351] Fix | Delete
q.breakable ''
[352] Fix | Delete
q.text(self.exclude_end? ? '...' : '..')
[353] Fix | Delete
q.breakable ''
[354] Fix | Delete
q.pp self.end
[355] Fix | Delete
end
[356] Fix | Delete
end
[357] Fix | Delete
[358] Fix | Delete
class File
[359] Fix | Delete
class Stat
[360] Fix | Delete
def pretty_print(q)
[361] Fix | Delete
require 'etc.so'
[362] Fix | Delete
q.object_group(self) {
[363] Fix | Delete
q.breakable
[364] Fix | Delete
q.text sprintf("dev=0x%x", self.dev); q.comma_breakable
[365] Fix | Delete
q.text "ino="; q.pp self.ino; q.comma_breakable
[366] Fix | Delete
q.group {
[367] Fix | Delete
m = self.mode
[368] Fix | Delete
q.text sprintf("mode=0%o", m)
[369] Fix | Delete
q.breakable
[370] Fix | Delete
q.text sprintf("(%s %c%c%c%c%c%c%c%c%c)",
[371] Fix | Delete
self.ftype,
[372] Fix | Delete
(m & 0400 == 0 ? ?- : ?r),
[373] Fix | Delete
(m & 0200 == 0 ? ?- : ?w),
[374] Fix | Delete
(m & 0100 == 0 ? (m & 04000 == 0 ? ?- : ?S) :
[375] Fix | Delete
(m & 04000 == 0 ? ?x : ?s)),
[376] Fix | Delete
(m & 0040 == 0 ? ?- : ?r),
[377] Fix | Delete
(m & 0020 == 0 ? ?- : ?w),
[378] Fix | Delete
(m & 0010 == 0 ? (m & 02000 == 0 ? ?- : ?S) :
[379] Fix | Delete
(m & 02000 == 0 ? ?x : ?s)),
[380] Fix | Delete
(m & 0004 == 0 ? ?- : ?r),
[381] Fix | Delete
(m & 0002 == 0 ? ?- : ?w),
[382] Fix | Delete
(m & 0001 == 0 ? (m & 01000 == 0 ? ?- : ?T) :
[383] Fix | Delete
(m & 01000 == 0 ? ?x : ?t)))
[384] Fix | Delete
}
[385] Fix | Delete
q.comma_breakable
[386] Fix | Delete
q.text "nlink="; q.pp self.nlink; q.comma_breakable
[387] Fix | Delete
q.group {
[388] Fix | Delete
q.text "uid="; q.pp self.uid
[389] Fix | Delete
begin
[390] Fix | Delete
pw = Etc.getpwuid(self.uid)
[391] Fix | Delete
rescue ArgumentError
[392] Fix | Delete
end
[393] Fix | Delete
if pw
[394] Fix | Delete
q.breakable; q.text "(#{pw.name})"
[395] Fix | Delete
end
[396] Fix | Delete
}
[397] Fix | Delete
q.comma_breakable
[398] Fix | Delete
q.group {
[399] Fix | Delete
q.text "gid="; q.pp self.gid
[400] Fix | Delete
begin
[401] Fix | Delete
gr = Etc.getgrgid(self.gid)
[402] Fix | Delete
rescue ArgumentError
[403] Fix | Delete
end
[404] Fix | Delete
if gr
[405] Fix | Delete
q.breakable; q.text "(#{gr.name})"
[406] Fix | Delete
end
[407] Fix | Delete
}
[408] Fix | Delete
q.comma_breakable
[409] Fix | Delete
q.group {
[410] Fix | Delete
q.text sprintf("rdev=0x%x", self.rdev)
[411] Fix | Delete
q.breakable
[412] Fix | Delete
q.text sprintf('(%d, %d)', self.rdev_major, self.rdev_minor)
[413] Fix | Delete
}
[414] Fix | Delete
q.comma_breakable
[415] Fix | Delete
q.text "size="; q.pp self.size; q.comma_breakable
[416] Fix | Delete
q.text "blksize="; q.pp self.blksize; q.comma_breakable
[417] Fix | Delete
q.text "blocks="; q.pp self.blocks; q.comma_breakable
[418] Fix | Delete
q.group {
[419] Fix | Delete
t = self.atime
[420] Fix | Delete
q.text "atime="; q.pp t
[421] Fix | Delete
q.breakable; q.text "(#{t.tv_sec})"
[422] Fix | Delete
}
[423] Fix | Delete
q.comma_breakable
[424] Fix | Delete
q.group {
[425] Fix | Delete
t = self.mtime
[426] Fix | Delete
q.text "mtime="; q.pp t
[427] Fix | Delete
q.breakable; q.text "(#{t.tv_sec})"
[428] Fix | Delete
}
[429] Fix | Delete
q.comma_breakable
[430] Fix | Delete
q.group {
[431] Fix | Delete
t = self.ctime
[432] Fix | Delete
q.text "ctime="; q.pp t
[433] Fix | Delete
q.breakable; q.text "(#{t.tv_sec})"
[434] Fix | Delete
}
[435] Fix | Delete
}
[436] Fix | Delete
end
[437] Fix | Delete
end
[438] Fix | Delete
end
[439] Fix | Delete
[440] Fix | Delete
class MatchData
[441] Fix | Delete
def pretty_print(q)
[442] Fix | Delete
q.object_group(self) {
[443] Fix | Delete
q.breakable
[444] Fix | Delete
q.seplist(1..self.size, lambda { q.breakable }) {|i|
[445] Fix | Delete
q.pp self[i-1]
[446] Fix | Delete
}
[447] Fix | Delete
}
[448] Fix | Delete
end
[449] Fix | Delete
end
[450] Fix | Delete
[451] Fix | Delete
class Object
[452] Fix | Delete
include PP::ObjectMixin
[453] Fix | Delete
end
[454] Fix | Delete
[455] Fix | Delete
[Numeric, Symbol, FalseClass, TrueClass, NilClass, Module].each {|c|
[456] Fix | Delete
c.class_eval {
[457] Fix | Delete
def pretty_print_cycle(q)
[458] Fix | Delete
q.text inspect
[459] Fix | Delete
end
[460] Fix | Delete
}
[461] Fix | Delete
}
[462] Fix | Delete
[463] Fix | Delete
[Numeric, FalseClass, TrueClass, Module].each {|c|
[464] Fix | Delete
c.class_eval {
[465] Fix | Delete
def pretty_print(q)
[466] Fix | Delete
q.text inspect
[467] Fix | Delete
end
[468] Fix | Delete
}
[469] Fix | Delete
}
[470] Fix | Delete
[471] Fix | Delete
# :enddoc:
[472] Fix | Delete
if __FILE__ == $0
[473] Fix | Delete
require 'test/unit'
[474] Fix | Delete
[475] Fix | Delete
class PPTest < Test::Unit::TestCase
[476] Fix | Delete
def test_list0123_12
[477] Fix | Delete
assert_equal("[0, 1, 2, 3]\n", PP.pp([0,1,2,3], '', 12))
[478] Fix | Delete
end
[479] Fix | Delete
[480] Fix | Delete
def test_list0123_11
[481] Fix | Delete
assert_equal("[0,\n 1,\n 2,\n 3]\n", PP.pp([0,1,2,3], '', 11))
[482] Fix | Delete
end
[483] Fix | Delete
[484] Fix | Delete
OverriddenStruct = Struct.new("OverriddenStruct", :members, :class)
[485] Fix | Delete
def test_struct_override_members # [ruby-core:7865]
[486] Fix | Delete
a = OverriddenStruct.new(1,2)
[487] Fix | Delete
assert_equal("#<struct Struct::OverriddenStruct members=1, class=2>\n", PP.pp(a, ''))
[488] Fix | Delete
end
[489] Fix | Delete
[490] Fix | Delete
def test_redefined_method
[491] Fix | Delete
o = ""
[492] Fix | Delete
def o.method
[493] Fix | Delete
end
[494] Fix | Delete
assert_equal(%(""\n), PP.pp(o, ""))
[495] Fix | Delete
end
[496] Fix | Delete
end
[497] Fix | Delete
[498] Fix | Delete
class HasInspect
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function