formatr 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (18) hide show
  1. data/lib/formatr.rb +1462 -0
  2. data/test/1 +55 -0
  3. data/test/10 +7 -0
  4. data/test/11 +2 -0
  5. data/test/12 +3 -0
  6. data/test/13 +290 -0
  7. data/test/14 +5 -0
  8. data/test/15 +8 -0
  9. data/test/2 +129 -0
  10. data/test/3 +9 -0
  11. data/test/4 +100 -0
  12. data/test/5 +200 -0
  13. data/test/6 +6 -0
  14. data/test/7 +6 -0
  15. data/test/8 +40 -0
  16. data/test/format_test.pl +377 -0
  17. data/test/test_formatr.rb +761 -0
  18. metadata +62 -0
@@ -0,0 +1,761 @@
1
+ #!/usr/bin/env ruby
2
+ # This is a test for FormatR it uses perl and compares output from perl and ruby
3
+ # If you want to keep the output to look at pass in -keep or --keep
4
+
5
+ $VERBOSE = true
6
+
7
+ require 'test/unit'
8
+
9
+ require "formatr"
10
+ include FormatR
11
+
12
+ $page_number = -1
13
+
14
+ ## These formats are defined before the class as the formatting gets
15
+ ## tricky in the face of indentation using the here documents. You can get around
16
+ ## this by passing in an array of strings as shown in $test_5 below.
17
+
18
+ #test 1
19
+ # Uses numbers, comments, center, left and right alignment along
20
+ # with numbers.
21
+ $f = <<DOT
22
+ @###.# @##########.### @##.###| @.### @##.. .
23
+ #comment
24
+ num, num, snum, snum, snum
25
+ 1234567 1234567.890 -12.340| -12.3 -12.. .
26
+ left|@<<<<| right|@>>>>| |center|@||||| | num|@##.#|
27
+ twenty_two, twenty_two, twenty_two, snum
28
+ left|22 | right| 22| |center| 22 | num|-12.3|
29
+ DOT
30
+
31
+ #test 1,2
32
+ # This format is just a header with no variables.
33
+ $top = <<DOT
34
+ Passwd File
35
+ Name Name Login Office Uid Gid Home
36
+ ------------------------------------------------------
37
+ DOT
38
+
39
+ #test 2
40
+ # Tests left, right, numbers, and formats that aren't picture,
41
+ # vars, picture, vars,...
42
+ $from_perl = <<FROM_PERL
43
+ Foo @<<<< @>>>> @<<<< @>>>>> @##.##### @# @.### @##.#.
44
+ name, name, login, office, uid, uid, gid, gid,
45
+ safdsdfsdfsdf
46
+ sdfsdfsdfdfs
47
+ bar @<<<< @>>>> @<<<< @>>>>> @|||||+ +@#####+ @<<<<
48
+ name, name, login, office, uid, gid, home
49
+ baz ^<<<* *^<<<* ^<< @<_^_<< @||| ^#.## ^##.###
50
+ name, name, name,login, login, home, uid, uid
51
+ \@#\@#
52
+ uid,uid
53
+ FROM_PERL
54
+
55
+ #test assertions
56
+ $bad_format = <<DOT
57
+ @<<< @>>
58
+ name,
59
+ DOT
60
+
61
+ #tests 3,4,5
62
+ ## New test for # and <, perl test #2
63
+ $top_ex = <<DOT
64
+ Piggy Locations for @<< @#, @###
65
+ month, day, year
66
+
67
+ Number: location toe size
68
+ -------------------------------------------
69
+ DOT
70
+
71
+ #tests 3,4,5
72
+ # This tests ~ feature
73
+ $ex = <<DOT
74
+ @) ~ @<<<<<<<<<<<<<<<< @#.##
75
+ num, location, toe_size
76
+ DOT
77
+
78
+ # a bottom format:
79
+ $bot_ex = <<BOT
80
+ -------------------------------------------
81
+ BOT
82
+
83
+ #test 6
84
+ ## Examples of ^
85
+ $hat_ex = <<BOT
86
+ Format that uses the hat
87
+ @|| ^<< ^||
88
+ long, long, long
89
+ ^|||| @<<<< ^|||| ^###.## ^###.## ^###.#
90
+ long, long, long, num, num, num
91
+ Run out of chars!
92
+ ^|||| ^<<<< ^|||| --
93
+ short, short,short
94
+ ^<<<*^<<<<*^<<<<<<<<<<<<<
95
+ long, long, long
96
+ BOT
97
+
98
+ #test 6
99
+ # an empty top format
100
+ $empty_top = <<TOP
101
+ TOP
102
+
103
+ #tests 7,8
104
+ # Format created by pushing strings onto an array.
105
+ $test_5 = ["~ non_blank: @<<<|"]
106
+ $test_5.push("non_blank")
107
+ $test_5.push("~ blank unless $blank holds something, which it doesn\'t @<<<")
108
+ $test_5.push("blank")
109
+ $test_5.push(" ~~repeat: ^<<.")
110
+ $test_5.push("string")
111
+
112
+
113
+ class FormatTester < Test::Unit::TestCase
114
+ @@keep = false
115
+
116
+ def initialize (a)
117
+ super(a)
118
+ hasPerl = `/usr/bin/env perl -h`
119
+ @hasPerl = ((hasPerl == "") ? false : true)
120
+ end
121
+
122
+ def FormatTester.setKeep (keep)
123
+ @@keep = keep
124
+ end
125
+
126
+ def getPerlToCompare (perl)
127
+ program, arguments = perl.split(' ', 2)
128
+ if (@hasPerl)
129
+ io = IO.popen(perl)
130
+ else #use cached values
131
+ io = File.open("./test/" + arguments)
132
+ end
133
+ perl_output = io.readlines()
134
+ io.close()
135
+ perl_output.collect! {|x| x.chomp()}
136
+ end
137
+
138
+ def compareOutput (infile, perl, tail)
139
+ perl_output = getPerlToCompare(perl)
140
+ tail.each {|i| perl_output.push(i.chomp())} if (tail)
141
+ File.open("#{infile}"){|file|
142
+ lines = file.readlines
143
+ lines.each_index {|i|
144
+ line = lines[i].chomp!()
145
+ if (!(line === (perl_output[i])))
146
+ perl_name = "perl".ljust(infile.length)
147
+ raise "testing error between \n" +
148
+ "#{infile}>#{line}<\n#{perl_name}>#{perl_output[i]}<"
149
+ end
150
+ }
151
+ if (lines.size != perl_output.size)
152
+ raise "testing error between #{infile} #{lines.size()} and " +
153
+ "#{perl} #{perl_output.size()}, not the same size"
154
+ else
155
+ puts "keeping #{infile}" if @@keep
156
+ File.delete(infile) unless (@@keep)
157
+ end
158
+ }
159
+ true
160
+ end
161
+
162
+ #test $f format
163
+ def one
164
+ twenty_two = '22'
165
+ num = 1234567.89012455
166
+ snum = -12.34
167
+
168
+ fmt1 = Format.new($f)
169
+ fmt1.setTop($top)
170
+
171
+ File.open("format_testfile1", File::CREAT | File::WRONLY | File::TRUNC) { |file|
172
+ fmt1.io = file
173
+ 13.times do
174
+ fmt1.printFormatWithBinding(binding)
175
+ end
176
+ }
177
+
178
+ assert(compareOutput("format_testfile1", "./format_test.pl 1", nil))
179
+ end
180
+
181
+
182
+ #test $top and $from_perl
183
+ def two
184
+ name = "Paul Rubel"
185
+ login ="rubel@crhc.uiuc.edu"
186
+ office = "6/301"
187
+ uid = 124.135791357;
188
+
189
+ fmt = Format.new($from_perl)
190
+ File.open("format_testfile2", File::CREAT | File::WRONLY | File::TRUNC) { |file|
191
+ gid = -13
192
+ home = "/home/rubel/"
193
+ fmt.io = file
194
+ fmt.setTop($top)
195
+ 20.times do
196
+ fmt.printFormat(binding)
197
+ end
198
+ }
199
+ raise "line numbering is broken #{fmt.pageNumber()}" unless (3 == fmt.pageNumber())
200
+ assert(compareOutput("format_testfile2", "./format_test.pl 2", nil))
201
+ end
202
+
203
+
204
+ def test_recursive_exceptions
205
+ fmt = Format.new($from_perl)
206
+ assert_raises(FormatException, "Should have thrown an exception") {
207
+ #assert_exception(FormatException, "Should have thrown an exception") {
208
+ fmt.setTop(fmt)
209
+ }
210
+ end
211
+
212
+
213
+ def test_bad_format_exception
214
+ assert_raises(FormatException, "Malformed format slipped through") {
215
+ badFormat = Format.new($bad_format)
216
+ }
217
+ end
218
+
219
+ def helper_test_three (body_fmt, file_name)
220
+ File.open(file_name, File::CREAT | File::WRONLY | File::TRUNC) { |file|
221
+ body_fmt.io = file
222
+ month = "Sep"
223
+ day = 18
224
+ year = 2001
225
+ num = 1
226
+ body_fmt.setPageLength(11)
227
+ ["Market", "Home", "Eating Roast Beef", "Having None", "On the way home"].each {|location|
228
+ toe_size = (num * 3.5)
229
+ body_fmt.printFormat(binding)
230
+ num += 1
231
+ }
232
+ assert(1 == body_fmt.pageNumber())
233
+ }
234
+ end
235
+
236
+ #test setting top and middle formats at once and page numbers
237
+ def test_three
238
+ 0.upto(1) do |x|
239
+ body_fmt = Format.new($top_ex, $ex)
240
+ body_fmt.useHash( x == 0 )
241
+ helper_test_three(body_fmt, "format_testfile3-#{x}")
242
+ assert(compareOutput("format_testfile3-#{x}",
243
+ "./format_test.pl 3", nil))
244
+ end
245
+ end
246
+
247
+
248
+ def helper_test_four (body_fmt, file_name)
249
+ File.open(file_name, File::CREAT | File::WRONLY | File::TRUNC) { |file|
250
+ body_fmt.io = file
251
+ month = "Sep"
252
+ day = 18
253
+ year = 2001
254
+ 10.times do
255
+ num = 1
256
+ ["Market", "Home", "Eating Roast Beef",
257
+ "Having None", "On the way home"].each {|location|
258
+ toe_size = (num * 3.5)
259
+ body_fmt.printFormat(binding)
260
+ num += 1
261
+ }
262
+ end
263
+ }
264
+ assert(compareOutput(file_name,
265
+ "./format_test.pl 4", nil))
266
+ end
267
+
268
+ def helper_hash_test_four (body_fmt, file_name)
269
+ h = Hash.new
270
+ h["month"] = "Sep"
271
+ h['day'] = 18
272
+ h['year'] = 2001
273
+ File.open(file_name, File::CREAT | File::WRONLY | File::TRUNC) { |file|
274
+ body_fmt.io = file
275
+ 10.times do
276
+ num = 1
277
+ h["num"] = num
278
+ ["Market", "Home", "Eating Roast Beef",
279
+ "Having None", "On the way home"].each {|location|
280
+ h["location"] = location
281
+ h["toe_size"] = (num * 3.5)
282
+ body_fmt.printFormatWithHash(h)
283
+ num += 1
284
+ h["num"] = num
285
+ }
286
+ end
287
+ }
288
+ assert(compareOutput(file_name,
289
+ "./format_test.pl 4", nil))
290
+ end
291
+
292
+
293
+ # test the end of page bottom w/out calling end of pagefinishPage methods
294
+ def test_four
295
+ 0.upto(2) do |x|
296
+ top_fmt = Format.new($top_ex)
297
+ body_fmt = Format.new($ex)
298
+ bottom_fmt = Format.new($bot_ex)
299
+ body_fmt.useHash(x == 0)
300
+ body_fmt.setTop($top_ex)
301
+ body_fmt.setBottom(bottom_fmt)
302
+ body_fmt.setPageLength(10)
303
+ if (x <2)
304
+ helper_test_four(body_fmt, "format_testfile4-#{x}")
305
+ else
306
+ helper_hash_test_four(body_fmt, "format_testfile4-#{x}")
307
+ end
308
+ end
309
+ end
310
+
311
+
312
+ #test the finishPage methods and setting all three formats at once,
313
+ #top, bottom, and middle.
314
+
315
+ def helper_test_five (body_fmt, file_name)
316
+ File.open(file_name,
317
+ File::CREAT | File::WRONLY | File::TRUNC) { |file|
318
+ body_fmt.io = file
319
+ month = "Sep"
320
+ day = 19
321
+ year = 2001
322
+ count = 0
323
+ 10.times do
324
+ count += 1
325
+ num = 1
326
+ ["Market", "Home", "Eating Roast Beef", "Having None", "On the way home"].each {|location|
327
+ toe_size = 1
328
+ body_fmt.printFormat(binding)
329
+ num += 1
330
+ }
331
+ body_fmt.finishPageWithFF(binding) unless (count == 10)
332
+ end
333
+ body_fmt.finishPageWithoutFF(binding)
334
+ }
335
+ end
336
+
337
+ def test_five
338
+ 0.upto(1) do |x|
339
+ body_fmt = Format.new($top_ex, $ex, $bot_ex)
340
+ body_fmt.useHash(x == 0)
341
+ body_fmt.setPageLength(20)
342
+ helper_test_five(body_fmt, "format_testfile5-#{x}")
343
+ assert(compareOutput("format_testfile5-#{x}",
344
+ "./format_test.pl 5", nil))
345
+ end
346
+ end
347
+
348
+
349
+ def helper_test_six (body_fmt, file_name)
350
+ File.open(file_name,
351
+ File::CREAT | File::WRONLY | File::TRUNC) { |file|
352
+ body_fmt.io = file
353
+ long = "01234567890abcde fg h i jklmn12345678901234567890123456.789"
354
+ num = 123.456
355
+ short = '123.456'
356
+ body_fmt.printFormat(binding)
357
+ raise "page numbering not working " unless (1 == body_fmt.pageNumber())
358
+ }
359
+ end
360
+
361
+ def test_six
362
+ 0.upto(1) do |x|
363
+ hat_top = Format.new($empty_top)
364
+ hat_format = Format.new($hat_ex)
365
+ hat_format.setTop(hat_top)
366
+ hat_format.useHash(x == 1)
367
+ helper_test_six(hat_format, "format_testfile6-#{x}")
368
+ assert(compareOutput("format_testfile6-#{x}",
369
+ "./format_test.pl 6", nil))
370
+ end
371
+ end
372
+
373
+
374
+ def helper_test_seven (body_fmt, file_name)
375
+ File.open(file_name,
376
+ File::CREAT | File::WRONLY | File::TRUNC) { |file|
377
+ body_fmt.io = file
378
+ blank = ""
379
+ non_blank = " "
380
+ string = "abcdefghijklmn"
381
+ body_fmt.printFormat(binding)
382
+ }
383
+ end
384
+
385
+ def test_seven
386
+ puts "test 7"
387
+ 0.upto(1) do |x|
388
+ tilde_format = Format.new($test_5)
389
+ helper_test_seven(tilde_format, "format_testfile7-#{x}")
390
+ assert(compareOutput("format_testfile7-#{x}",
391
+ "./format_test.pl 7", nil))
392
+ end
393
+ puts "test 7 end"
394
+ end
395
+
396
+ def helper_test_eight (body_fmt, file_name)
397
+ File.open(file_name,
398
+ File::CREAT | File::WRONLY | File::TRUNC) { |file|
399
+ body_fmt.io = file
400
+ blank = ""
401
+ non_blank = " "
402
+ string =("a"*100) + "b"
403
+
404
+ body_fmt.printFormat(binding)
405
+ body_fmt.finishPageWithoutFF(binding)
406
+ }
407
+ end
408
+
409
+ def test_eight
410
+ #Problems when formats don't fit on a single page!
411
+ 0.upto(1) do |x|
412
+ tilde_format = Format.new($test_5)
413
+ tilde_format.setPageLength(10)
414
+ tilde_format.useHash(x == 0)
415
+ helper_test_eight(tilde_format, "format_testfile8-#{x}")
416
+ assert(compareOutput("format_testfile8-#{x}",
417
+ "./format_test.pl 8", nil))
418
+ end
419
+ end
420
+
421
+
422
+ def helper_test_empty_top_bottom (body_fmt, file_name)
423
+ File.open(file_name,
424
+ File::CREAT | File::WRONLY | File::TRUNC) { |file|
425
+ body_fmt.io = file
426
+ blank = ""
427
+ non_blank = " "
428
+ string = ("a"*100) + "b"
429
+ body_fmt.printFormat(binding)
430
+ body_fmt.finishPageWithoutFF(binding)
431
+ }
432
+ end
433
+
434
+ #can we pass in an emptry string as a top and nil as a bottom?
435
+ def test_empty_top_bottom
436
+ 0.upto(1) do |x|
437
+ #Problems when formats don't fit on a single page!
438
+ tilde_format = Format.new("",$test_5, nil)
439
+ tilde_format.useHash(x == 0)
440
+ tilde_format.setPageLength(10)
441
+ helper_test_empty_top_bottom(tilde_format, "format_testfile9-#{x}")
442
+ assert(compareOutput("format_testfile9-#{x}",
443
+ "./format_test.pl 8", nil))
444
+ end
445
+ end
446
+
447
+ def helper_test_scientific (body_fmt, file_name)
448
+ File.open(file_name,
449
+ File::CREAT | File::WRONLY | File::TRUNC) { |file|
450
+ body_fmt.io = file
451
+ int = 12
452
+ exp = 1.234e-14
453
+ mid = 123.4567E23
454
+ big = 123.4567E200
455
+ little = 12.34e-20
456
+ body_fmt.printFormat(binding)
457
+ }
458
+ end
459
+
460
+ def test_scientific
461
+ f = [];
462
+ f.push("1 @.##G### @.##e###")
463
+ f.push("exp, exp")
464
+
465
+ f.push("2 @##.###g### @##.#E###")
466
+ f.push("big, big")
467
+
468
+ f.push("3 @.#G## @.#e##")
469
+ f.push("little, little")
470
+
471
+ f.push("4 @E##")
472
+ f.push("mid")
473
+
474
+ f.push("5 @.#E## @e##")
475
+ f.push("little, mid")
476
+
477
+ f.push("6 int @.#g## @.#e##")
478
+ f.push("int, int")
479
+
480
+ f.push("7 int @.G## @.E##")
481
+ f.push("int, int")
482
+ 0.upto(1) do |x|
483
+ exp_format = Format.new("", f, nil)
484
+ exp_format.useHash(x == 0)
485
+ helper_test_scientific(exp_format, "format_testfile10-#{x}")
486
+ assert(compareOutput("format_testfile10-#{x}",
487
+ "./format_test.pl 10", nil))
488
+ end
489
+ end
490
+
491
+ def helper_test_eleven (body_fmt, file_name)
492
+ File.open(file_name,
493
+ File::CREAT | File::WRONLY | File::TRUNC) { |file|
494
+ body_fmt.io = file
495
+ one = 1
496
+ body_fmt.printFormat(binding)
497
+ }
498
+ assert(compareOutput(file_name,
499
+ "./format_test.pl 11", nil))
500
+ end
501
+
502
+ def helper_hash_test_eleven (body_fmt, file_name)
503
+ h = Hash.new
504
+ h['one'] = 1
505
+ File.open(file_name,
506
+ File::CREAT | File::WRONLY | File::TRUNC) { |file|
507
+ body_fmt.io = file
508
+ body_fmt.printFormatWithHash( h )
509
+ }
510
+ assert(compareOutput(file_name,
511
+ "./format_test.pl 11", nil))
512
+ end
513
+
514
+ def test_eleven
515
+ #Problems when formats don't fit on a single page!
516
+ f = []
517
+ f.push( '<?xml version="1.0"?>' )
518
+ f.push( '@@@ @@@' )
519
+ f.push( 'one,one,one,one,one,one')
520
+ 0.upto(1) do |x|
521
+ format = Format.new(f)
522
+ helper_test_eleven(format, "format_testfile11-#{x}")
523
+
524
+ end
525
+ format = Format.new(f)
526
+ helper_hash_test_eleven(format, "format_testfile11-2")
527
+
528
+ end
529
+
530
+ def helper_test_twelve (body_fmt, file_name)
531
+ var_one, var_two, var_three, var_four = 1, 2, 3, 4.3
532
+ File.open(file_name,
533
+ File::CREAT | File::WRONLY | File::TRUNC) { |file|
534
+ body_fmt.io = file
535
+ body_fmt.printFormat(binding)
536
+ }
537
+ output = []
538
+ File.open( file_name ){ |file|
539
+ output = file.readlines()
540
+ }
541
+
542
+ reader = FormatReader.new(body_fmt)
543
+ res = reader.readFormat(output)
544
+
545
+ #since we're keying on just @ we can't tell class without the binding
546
+ assert(res['var_one'] == var_one.to_s)
547
+ assert(res['var_two'] == var_two.to_s)
548
+ assert(res['var_three'] == var_three.to_s)
549
+ assert(res['var_four'] == var_four)
550
+ # we need to compare last since compare may delete the file when its done
551
+ assert(compareOutput(file_name,
552
+ "./format_test.pl 12", nil))
553
+ end
554
+
555
+ # try out reading in variables
556
+ def test_twelve
557
+ puts "test 12"
558
+ f = []
559
+ f.push( '<?xml version="1.0"?>' )
560
+ f.push( '@@@ Paul @@@ }Rubel @< @|| @#.#' )
561
+ f.push( 'var_one,var_one,var_one,var_one,var_one,var_one,' +
562
+ ' var_two, var_three, var_four')
563
+ f.push( '@<<< @<<<')
564
+ f.push( 'var_one,var_one')
565
+ 0.upto(1) do |x|
566
+ format = Format.new(f)
567
+ format.useHash(x == 0)
568
+ pictures = format.getPictureLines
569
+ assert(pictures.size == 3)
570
+
571
+ helper_test_twelve(format, "format_testfile12-#{x}")
572
+ end
573
+ end
574
+
575
+ def helper_test_thirteen (body_fmt, file_name)
576
+ one = "FIVE SIX"
577
+ val1 = one.clone
578
+ two = "ONE TWO"
579
+ val2 = two.clone
580
+ val3 = "Yay"
581
+ var_exp = 3.44e10
582
+
583
+ File.open(file_name,
584
+ File::CREAT | File::WRONLY | File::TRUNC) { |file|
585
+ body_fmt.io = file
586
+ body_fmt.printFormat(binding)
587
+ }
588
+
589
+ #save the output for later
590
+ output = []
591
+ File.open( file_name ){ |file|
592
+ output = file.readlines()
593
+ }
594
+
595
+ reader = FormatReader.new(body_fmt)
596
+ res = reader.readFormat(output)
597
+ #since we're keying on just @ we can't tell class without the binding
598
+ assert(res['val1'] == one)
599
+ assert(res['val2'] == two)
600
+ assert(res['val3'] == val3)
601
+ assert(res['var_exp'] == var_exp)
602
+ puts "tested 13 in #{file_name}"
603
+ File.delete(file_name) unless (@@keep)
604
+ end
605
+
606
+ # See if we can handle repeat lines in with regular ones
607
+ def test_thirteen
608
+ puts "test 13"
609
+ f = []
610
+ f.push( '<?xml version="1.0"?>' )
611
+ f.push( '~~^<<< TEST1' )
612
+ f.push( 'val1' )
613
+ f.push( '~~^<< TEST2' )
614
+ f.push( 'val2' )
615
+ f.push( '@<< @<<' )
616
+ f.push('val3, val3')
617
+ f.push('@##.##e##')
618
+ f.push('var_exp')
619
+
620
+ format = Format.new(f)
621
+ 0.upto(1) do |x|
622
+ format.useHash(x == 0)
623
+ helper_test_thirteen(format, "format_testfile13-#{x}")
624
+ end
625
+
626
+ end
627
+
628
+ def helper_test_fourteen (body_fmt, file_name)
629
+ one = "FIVE"
630
+ val1 = one.clone
631
+ two = "ONE"
632
+ val2 = two.clone
633
+ val3 = "Yay"
634
+ var_exp = 3.44e10
635
+ change = ["Yip", "Yie", "Yoo"]
636
+
637
+ File.open(file_name,
638
+ File::CREAT | File::WRONLY | File::TRUNC) { |file|
639
+ body_fmt.io = file
640
+
641
+ 3.times do |i|
642
+ val2 = change[i].clone
643
+ body_fmt.printFormat(binding)
644
+ end
645
+ }
646
+
647
+ #save the output for later
648
+ output = IO.readlines(file_name)
649
+ File.delete(file_name) unless (@@keep)
650
+ reader = FormatReader.new(body_fmt)
651
+ loops = 0
652
+ reader.readFormat(output) do |vals|
653
+ #since we're keying on just @ we can't tell class without the binding
654
+ assert(vals['val1'] == one)
655
+ assert(vals['val2'] == change[loops])
656
+ assert(vals['val3'] == val3)
657
+ assert(vals['var_exp'] == var_exp)
658
+ loops += 1
659
+ end
660
+ assert(loops = 3)
661
+ end
662
+
663
+
664
+ # See if we can handle repeat lines in with regular ones
665
+ def test_fourteen
666
+ puts "test 14"
667
+ f = []
668
+ f.push( '<?xml version="1.0"?>' )
669
+ f.push( '@<<< TEST1' )
670
+ f.push( 'val1' )
671
+ f.push( '@<< TEST2' )
672
+ f.push( 'val2' )
673
+ f.push( '@<< @<<' )
674
+ f.push('val3, val3')
675
+ f.push('@##.##e##')
676
+ f.push('var_exp')
677
+
678
+ format = Format.new(f)
679
+ 0.upto(1) do |x|
680
+ format.useHash(x == 0)
681
+ helper_test_fourteen(format, "format_testfile14-#{x}")
682
+ end
683
+ end
684
+
685
+ # See if we can handle repeat lines in with regular ones
686
+ def test_fifteen
687
+ puts "test 15"
688
+ f = []
689
+ f.push('@>>>>>>>>>>>>>> ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<')
690
+ f.push('author, quote')
691
+ f.push('~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<')
692
+ f.push('quote')
693
+
694
+
695
+
696
+ authors = []
697
+ quotes = []
698
+ format = Format.new(f)
699
+ file_name = "format_testfile15"
700
+ File.open(file_name,
701
+ File::CREAT | File::WRONLY | File::TRUNC) do |file|
702
+ format.io = file
703
+ author = "Robert Frost"
704
+ authors[0] = author
705
+ quote = "Whose woods these are I think I know His house is" +
706
+ " by the village, though ... But I have promises to keep " +
707
+ "And miles to go before I sleep."
708
+ quotes[0] = quote
709
+ format.printFormat(binding)
710
+ author = "Bill"
711
+ authors[1] = author
712
+ quote = "Shall I compare thee to a Summer's day and branch if the result is negative?"
713
+ quotes[1] = quote
714
+ format.printFormat(binding)
715
+ end
716
+
717
+ #save the output for later
718
+ output = IO.readlines(file_name)
719
+
720
+ reader = FormatReader.new(format)
721
+ loops = 0
722
+ reader.readFormat(output) do |vals|
723
+ assert(vals["author"] = authors[loops])
724
+ assert(vals["quote"] = quotes[loops])
725
+ loops += 1
726
+ end
727
+ assert(compareOutput(file_name,
728
+ "./format_test.pl 15", nil))
729
+
730
+ end
731
+
732
+ # show that page numbers are fixed on the top and bottom
733
+ def test_page_numbers
734
+ #Problems when formats don't fit on a single page!
735
+ File.open("format_testfile14", File::CREAT | File::WRONLY | File::TRUNC) { |file|
736
+ top = "---- Top --- Page Number @<<<----\n$page_number\n"
737
+ bottom = "---- Bot --- Page Number @<<<----\n$page_number\n \n"
738
+ page_num_format = Format.new(top,$ex, bottom)
739
+ page_num_format.io = file
740
+ page_num_format.setPageLength(10)
741
+ location = "Who Knows"
742
+ 203.times do
743
+ $page_number = page_num_format.pageNumber()
744
+ num = page_num_format.pageNumber()
745
+ toe_size = page_num_format.pageNumber() * 1.0
746
+ page_num_format.printFormat(binding)
747
+
748
+ $page_number = page_num_format.pageNumber()
749
+ num = page_num_format.pageNumber()
750
+ toe_size = page_num_format.pageNumber()
751
+ end
752
+ }
753
+ assert(compareOutput("format_testfile14", "./format_test.pl 13", nil))
754
+ end
755
+
756
+
757
+ end
758
+
759
+ keep = (ARGV.include?("-keep") || ARGV.include?("--keep"))
760
+ FormatTester.setKeep(keep)
761
+