Class: WadlerExample

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

Overview

:nodoc:

Defined Under Namespace

Classes: Tree

Instance Method Summary collapse

Instance Method Details

#hello(width) ⇒ Object



394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'lib/prettyprint.rb', line 394

def hello(width)
  PrettyPrint.format('', width) {|hello|
    hello.group {
      hello.group {
        hello.group {
          hello.group {
            hello.text 'hello'
            hello.breakable; hello.text 'a'
          }
          hello.breakable; hello.text 'b'
        }
        hello.breakable; hello.text 'c'
      }
      hello.breakable; hello.text 'd'
    }
  }
end

#setupObject



385
386
387
388
389
390
391
392
# File 'lib/prettyprint.rb', line 385

def setup
  @tree = Tree.new("aaaa", Tree.new("bbbbb", Tree.new("ccc"),
                                             Tree.new("dd")),
                           Tree.new("eee"),
                           Tree.new("ffff", Tree.new("gg"),
                                            Tree.new("hhh"),
                                            Tree.new("ii")))
end

#test_hello_00_06Object



412
413
414
415
416
417
418
419
420
421
422
# File 'lib/prettyprint.rb', line 412

def test_hello_00_06
  expected = <<'End'.chomp
hello
a
b
c
d
End
  assert_equal(expected, hello(0))
  assert_equal(expected, hello(6))
end

#test_hello_07_08Object



424
425
426
427
428
429
430
431
432
433
# File 'lib/prettyprint.rb', line 424

def test_hello_07_08
  expected = <<'End'.chomp
hello a
b
c
d
End
  assert_equal(expected, hello(7))
  assert_equal(expected, hello(8))
end

#test_hello_09_10Object



435
436
437
438
439
440
441
442
443
# File 'lib/prettyprint.rb', line 435

def test_hello_09_10
  expected = <<'End'.chomp
hello a b
c
d
End
  out = hello(9); assert_equal(expected, out)
  out = hello(10); assert_equal(expected, out)
end

#test_hello_11_12Object



445
446
447
448
449
450
451
452
# File 'lib/prettyprint.rb', line 445

def test_hello_11_12
  expected = <<'End'.chomp
hello a b c
d
End
  assert_equal(expected, hello(11))
  assert_equal(expected, hello(12))
end

#test_hello_13Object



454
455
456
457
458
459
# File 'lib/prettyprint.rb', line 454

def test_hello_13
  expected = <<'End'.chomp
hello a b c d
End
  assert_equal(expected, hello(13))
end

#test_tree_00_19Object



465
466
467
468
469
470
471
472
473
474
475
476
# File 'lib/prettyprint.rb', line 465

def test_tree_00_19
  expected = <<'End'.chomp
aaaa[bbbbb[ccc,
       dd],
 eee,
 ffff[gg,
      hhh,
      ii]]
End
  assert_equal(expected, tree(0))
  assert_equal(expected, tree(19))
end

#test_tree_20_22Object



478
479
480
481
482
483
484
485
486
487
488
# File 'lib/prettyprint.rb', line 478

def test_tree_20_22
  expected = <<'End'.chomp
aaaa[bbbbb[ccc, dd],
 eee,
 ffff[gg,
      hhh,
      ii]]
End
  assert_equal(expected, tree(20))
  assert_equal(expected, tree(22))
end

#test_tree_23_43Object



490
491
492
493
494
495
496
497
498
# File 'lib/prettyprint.rb', line 490

def test_tree_23_43
  expected = <<'End'.chomp
aaaa[bbbbb[ccc, dd],
 eee,
 ffff[gg, hhh, ii]]
End
  assert_equal(expected, tree(23))
  assert_equal(expected, tree(43))
end

#test_tree_44Object



500
501
502
503
504
# File 'lib/prettyprint.rb', line 500

def test_tree_44
  assert_equal(<<'End'.chomp, tree(44))
aaaa[bbbbb[ccc, dd], eee, ffff[gg, hhh, ii]]
End
end

#test_tree_alt_00_18Object



510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
# File 'lib/prettyprint.rb', line 510

def test_tree_alt_00_18
  expected = <<'End'.chomp
aaaa[
  bbbbb[
ccc,
dd
  ],
  eee,
  ffff[
gg,
hhh,
ii
  ]
]
End
  assert_equal(expected, tree_alt(0))
  assert_equal(expected, tree_alt(18))
end

#test_tree_alt_19_20Object



529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
# File 'lib/prettyprint.rb', line 529

def test_tree_alt_19_20
  expected = <<'End'.chomp
aaaa[
  bbbbb[ ccc, dd ],
  eee,
  ffff[
gg,
hhh,
ii
  ]
]
End
  assert_equal(expected, tree_alt(19))
  assert_equal(expected, tree_alt(20))
end

#test_tree_alt_20_49Object



545
546
547
548
549
550
551
552
553
554
555
# File 'lib/prettyprint.rb', line 545

def test_tree_alt_20_49
  expected = <<'End'.chomp
aaaa[
  bbbbb[ ccc, dd ],
  eee,
  ffff[ gg, hhh, ii ]
]
End
  assert_equal(expected, tree_alt(21))
  assert_equal(expected, tree_alt(49))
end

#test_tree_alt_50Object



557
558
559
560
561
562
# File 'lib/prettyprint.rb', line 557

def test_tree_alt_50
  expected = <<'End'.chomp
aaaa[ bbbbb[ ccc, dd ], eee, ffff[ gg, hhh, ii ] ]
End
  assert_equal(expected, tree_alt(50))
end

#tree(width) ⇒ Object



461
462
463
# File 'lib/prettyprint.rb', line 461

def tree(width)
  PrettyPrint.format('', width) {|q| @tree.show(q)}
end

#tree_alt(width) ⇒ Object



506
507
508
# File 'lib/prettyprint.rb', line 506

def tree_alt(width)
  PrettyPrint.format('', width) {|q| @tree.altshow(q)}
end