Class: PPInspectTest

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

Instance Method Summary collapse

Instance Method Details

#test_hasbothObject



557
558
559
560
# File 'lib/pp.rb', line 557

def test_hasboth
  a = HasBoth.new(1)
  assert_equal("<pretty_print:1>\n", PP.pp(a, ''))
end

#test_hasinspectObject



547
548
549
550
# File 'lib/pp.rb', line 547

def test_hasinspect
  a = HasInspect.new(1)
  assert_equal("<inspect:1>\n", PP.pp(a, ''))
end

#test_hasprettyprintObject



552
553
554
555
# File 'lib/pp.rb', line 552

def test_hasprettyprint
  a = HasPrettyPrint.new(1)
  assert_equal("<pretty_print:1>\n", PP.pp(a, ''))
end

#test_pretty_print_inspectObject



562
563
564
565
566
567
# File 'lib/pp.rb', line 562

def test_pretty_print_inspect
  a = PrettyPrintInspect.new(1)
  assert_equal("<pretty_print:1>", a.inspect)
  a = PrettyPrintInspectWithoutPrettyPrint.new
  assert_raise(RuntimeError) { a.inspect }
end

#test_procObject



569
570
571
572
# File 'lib/pp.rb', line 569

def test_proc
  a = proc {1}
  assert_equal("#{a.inspect}\n", PP.pp(a, ''))
end

#test_to_s_with_ivObject



574
575
576
577
578
579
580
581
582
583
584
585
# File 'lib/pp.rb', line 574

def test_to_s_with_iv
  a = Object.new
  def a.to_s() "aaa" end
  a.instance_eval { @a = nil }
  result = PP.pp(a, '')
  assert_equal("#{a.inspect}\n", result)
  assert_match(/\A#<Object.*>\n\z/m, result)
  a = 1.0
  a.instance_eval { @a = nil }
  result = PP.pp(a, '')
  assert_equal("#{a.inspect}\n", result)
end

#test_to_s_without_ivObject



587
588
589
590
591
592
593
# File 'lib/pp.rb', line 587

def test_to_s_without_iv
  a = Object.new
  def a.to_s() "aaa" end
  result = PP.pp(a, '')
  assert_equal("#{a.inspect}\n", result)
  assert_equal("aaa\n", result)
end