Class: PPCycleTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/pp.rb

Defined Under Namespace

Classes: S

Instance Method Summary collapse

Instance Method Details

#test_anonymousObject



625
626
627
628
# File 'lib/pp.rb', line 625

def test_anonymous
  a = Class.new.new
  assert_equal(a.inspect + "\n", PP.pp(a, ''))
end

#test_arrayObject



597
598
599
600
601
602
# File 'lib/pp.rb', line 597

def test_array
  a = []
  a << a
  assert_equal("[[...]]\n", PP.pp(a, ''))
  assert_equal("#{a.inspect}\n", PP.pp(a, ''))
end

#test_hashObject



604
605
606
607
608
609
# File 'lib/pp.rb', line 604

def test_hash
  a = {}
  a[0] = a
  assert_equal("{0=>{...}}\n", PP.pp(a, ''))
  assert_equal("#{a.inspect}\n", PP.pp(a, ''))
end

#test_objectObject



619
620
621
622
623
# File 'lib/pp.rb', line 619

def test_object
  a = Object.new
  a.instance_eval {@a = a}
  assert_equal(a.inspect + "\n", PP.pp(a, ''))
end

#test_share_nilObject



637
638
639
640
641
642
643
644
645
# File 'lib/pp.rb', line 637

def test_share_nil
  begin
    PP.sharing_detection = true
    a = [nil, nil]
    assert_equal("[nil, nil]\n", PP.pp(a, ''))
  ensure
    PP.sharing_detection = false
  end
end

#test_structObject



612
613
614
615
616
617
# File 'lib/pp.rb', line 612

def test_struct
  a = S.new(1,2)
  a.b = a
  assert_equal("#<struct Struct::S a=1, b=#<struct Struct::S:...>>\n", PP.pp(a, ''))
  assert_equal("#{a.inspect}\n", PP.pp(a, ''))
end

#test_withinspectObject



630
631
632
633
634
635
# File 'lib/pp.rb', line 630

def test_withinspect
  a = []
  a << HasInspect.new(a)
  assert_equal("[<inspect:[...]>]\n", PP.pp(a, ''))
  assert_equal("#{a.inspect}\n", PP.pp(a, ''))
end