formatr 1.10.0 → 1.10.1
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.
- data/lib/formatr.rb +18 -15
- data/test/test_formatr.rb +205 -199
- metadata +2 -2
data/lib/formatr.rb
CHANGED
@@ -13,17 +13,17 @@
|
|
13
13
|
# PURPOSE.
|
14
14
|
#
|
15
15
|
# = To Test this code:
|
16
|
-
# Currently (1.10) the gem checking is broken since it tried to write out
|
17
|
-
# files to places where only root has permissions. You should be able
|
18
|
-
# to run the tests in the /test/ directory if you copy them somewhere else.
|
19
|
-
# I'm working on a fix.
|
20
16
|
#
|
21
|
-
# Try
|
17
|
+
# Try ./test/test_formatr.rb with no arguments. If nothing is amiss you should
|
22
18
|
# see OK (??/?? tests ?? asserts). This tests the format output
|
23
|
-
# against perl output (which is in the test directory
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
19
|
+
# against perl output (which is in the test directory). You can test
|
20
|
+
# against your perl installation by removing a comment in the
|
21
|
+
# constructor of FormatTester to set @hasPerl. That's how the
|
22
|
+
# test files were generated. I removed the dynamic generation
|
23
|
+
# due to issues with testing the gem.
|
24
|
+
# If you would like to see the format output try
|
25
|
+
# ./test/test_formatr.rb -- --keep which will place the test's output in the file
|
26
|
+
# format-output*.txt
|
27
27
|
#
|
28
28
|
# = Usage
|
29
29
|
# Class FormatR::Format in module FormatR provides perl like formats for ruby.
|
@@ -32,7 +32,7 @@
|
|
32
32
|
# values.
|
33
33
|
#
|
34
34
|
# For example:
|
35
|
-
# require "
|
35
|
+
# require "formatr"
|
36
36
|
# include FormatR
|
37
37
|
#
|
38
38
|
# top_ex = <<DOT
|
@@ -75,7 +75,7 @@
|
|
75
75
|
# 5) On the way home 17.50
|
76
76
|
#
|
77
77
|
#
|
78
|
-
# More examples are found in
|
78
|
+
# More examples are found in test_formatr.rb
|
79
79
|
#
|
80
80
|
# = Supported Format Fields
|
81
81
|
#
|
@@ -120,7 +120,7 @@
|
|
120
120
|
# @##.#E### with the value 123.4567E200 produces 1.2E+202 since
|
121
121
|
# there is only one hash after the decimal point.
|
122
122
|
#
|
123
|
-
# * More examples of using the scientific formats can be found in
|
123
|
+
# * More examples of using the scientific formats can be found in test_formatr.rb
|
124
124
|
#
|
125
125
|
#
|
126
126
|
# = Reading in output printed by formats, FormatR::FormatReader
|
@@ -206,7 +206,12 @@
|
|
206
206
|
#
|
207
207
|
#
|
208
208
|
# = Changes:
|
209
|
-
#
|
209
|
+
# ==1.10.1
|
210
|
+
# * Got testing working with gem install -t
|
211
|
+
# * fixed some documentation bugs due to the name change format.rb to
|
212
|
+
# formatr.rb
|
213
|
+
#
|
214
|
+
## ==1.10.0
|
210
215
|
# * Moved from sourceforge to rubyforge and released as a gem.
|
211
216
|
# * Changed filename from format.rb to formatr.rb.
|
212
217
|
# * Checked with the most recent version of 1.9 and everything
|
@@ -380,8 +385,6 @@
|
|
380
385
|
#
|
381
386
|
#
|
382
387
|
# =To Do/Think about:
|
383
|
-
# * Fix gem check -t formatr so that it works without write access to the test
|
384
|
-
# directory.
|
385
388
|
#
|
386
389
|
# * Have a format that chops lines that are too long to fit in the specified space
|
387
390
|
#
|
data/test/test_formatr.rb
CHANGED
@@ -112,21 +112,24 @@ $test_5.push("string")
|
|
112
112
|
|
113
113
|
class FormatTester < Test::Unit::TestCase
|
114
114
|
@@keep = false
|
115
|
+
@@file_number = 0
|
116
|
+
|
115
117
|
|
116
118
|
def initialize (a)
|
117
119
|
super(a)
|
118
|
-
hasPerl = `/usr/bin/env perl -h`
|
119
|
-
|
120
|
+
#hasPerl = `/usr/bin/env perl -h`
|
121
|
+
#@hasPerl = ((hasPerl == "") ? false : true)
|
122
|
+
# As a gem it's hard to get the path right, this is more robust
|
123
|
+
@hasPerl = false
|
120
124
|
end
|
121
125
|
|
122
126
|
def FormatTester.setKeep (keep)
|
123
127
|
@@keep = keep
|
124
128
|
end
|
125
129
|
|
126
|
-
def getPerlToCompare (
|
127
|
-
program, arguments = perl.split(' ', 2)
|
130
|
+
def getPerlToCompare (program, arguments)
|
128
131
|
if (@hasPerl)
|
129
|
-
io = IO.popen(
|
132
|
+
io = IO.popen("#{program} #{arguments}")
|
130
133
|
else #use cached values
|
131
134
|
io = File.open("./test/" + arguments)
|
132
135
|
end
|
@@ -135,27 +138,35 @@ class FormatTester < Test::Unit::TestCase
|
|
135
138
|
perl_output.collect! {|x| x.chomp()}
|
136
139
|
end
|
137
140
|
|
138
|
-
|
139
|
-
|
141
|
+
|
142
|
+
|
143
|
+
#
|
144
|
+
def compareOutput (file, perl, tail)
|
145
|
+
program, arguments = perl.split(' ', 2)
|
146
|
+
perl_output = getPerlToCompare(program, arguments)
|
140
147
|
tail.each {|i| perl_output.push(i.chomp())} if (tail)
|
141
|
-
|
142
|
-
|
143
|
-
lines.
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
148
|
+
lines = file.readlines
|
149
|
+
lines.each_index do |i|
|
150
|
+
line = lines[i].chomp!()
|
151
|
+
if (!(line === (perl_output[i])))
|
152
|
+
perl_name = "perl".ljust(infile.length)
|
153
|
+
raise "testing error between \n" +
|
154
|
+
"#{infile}>#{line}<\n#{perl_name}>#{perl_output[i]}<"
|
155
|
+
end
|
156
|
+
end
|
157
|
+
if (lines.size != perl_output.size)
|
158
|
+
raise "testing error between formatR output #{lines.size()} and " +
|
159
|
+
"#{perl} #{perl_output.size()}, not the same size"
|
160
|
+
else
|
161
|
+
if (@@keep)
|
162
|
+
filename = "format-output-#{@@file_number}-#{arguments}.txt"
|
163
|
+
@@file_number+= 1
|
164
|
+
puts "keeping #{filename}"
|
165
|
+
File.open(filename, File::CREAT | File::WRONLY | File::TRUNC) do |file|
|
166
|
+
lines.each{ |i| file.puts(i)}
|
149
167
|
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
168
|
end
|
158
|
-
|
169
|
+
end
|
159
170
|
true
|
160
171
|
end
|
161
172
|
|
@@ -168,14 +179,14 @@ class FormatTester < Test::Unit::TestCase
|
|
168
179
|
fmt1 = Format.new($f)
|
169
180
|
fmt1.setTop($top)
|
170
181
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
assert(compareOutput(
|
182
|
+
file = StringIO.new
|
183
|
+
fmt1.io = file
|
184
|
+
13.times do
|
185
|
+
fmt1.printFormatWithBinding(binding)
|
186
|
+
end
|
187
|
+
|
188
|
+
file.rewind
|
189
|
+
assert(compareOutput(file, "./format_test.pl 1", nil))
|
179
190
|
end
|
180
191
|
|
181
192
|
|
@@ -187,50 +198,49 @@ class FormatTester < Test::Unit::TestCase
|
|
187
198
|
uid = 124.135791357;
|
188
199
|
|
189
200
|
fmt = Format.new($from_perl)
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
201
|
+
file = StringIO.new
|
202
|
+
|
203
|
+
gid = -13
|
204
|
+
home = "/home/rubel/"
|
205
|
+
fmt.io = file
|
206
|
+
fmt.setTop($top)
|
207
|
+
20.times do
|
208
|
+
fmt.printFormat(binding)
|
209
|
+
end
|
210
|
+
|
199
211
|
raise "line numbering is broken #{fmt.pageNumber()}" unless (3 == fmt.pageNumber())
|
200
|
-
assert(compareOutput(
|
212
|
+
assert(compareOutput(file.rewind, "./format_test.pl 2", nil))
|
201
213
|
end
|
202
214
|
|
203
215
|
|
204
216
|
def test_recursive_exceptions
|
205
217
|
fmt = Format.new($from_perl)
|
206
|
-
assert_raises(FormatException, "Should have thrown an exception")
|
207
|
-
#assert_exception(FormatException, "Should have thrown an exception") {
|
218
|
+
assert_raises(FormatException, "Should have thrown an exception") do
|
208
219
|
fmt.setTop(fmt)
|
209
|
-
|
220
|
+
end
|
210
221
|
end
|
211
222
|
|
212
223
|
|
213
224
|
def test_bad_format_exception
|
214
|
-
assert_raises(FormatException, "Malformed format slipped through")
|
225
|
+
assert_raises(FormatException, "Malformed format slipped through") do
|
215
226
|
badFormat = Format.new($bad_format)
|
216
|
-
|
227
|
+
end
|
217
228
|
end
|
218
229
|
|
219
|
-
def helper_test_three (body_fmt,
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
}
|
230
|
+
def helper_test_three (body_fmt, file)
|
231
|
+
body_fmt.io = file
|
232
|
+
month = "Sep"
|
233
|
+
day = 18
|
234
|
+
year = 2001
|
235
|
+
num = 1
|
236
|
+
body_fmt.setPageLength(11)
|
237
|
+
["Market", "Home", "Eating Roast Beef",
|
238
|
+
"Having None", "On the way home"].each do |location|
|
239
|
+
toe_size = (num * 3.5)
|
240
|
+
body_fmt.printFormat(binding)
|
241
|
+
num += 1
|
242
|
+
end
|
243
|
+
assert(1 == body_fmt.pageNumber())
|
234
244
|
end
|
235
245
|
|
236
246
|
#test setting top and middle formats at once and page numbers
|
@@ -238,15 +248,15 @@ class FormatTester < Test::Unit::TestCase
|
|
238
248
|
0.upto(1) do |x|
|
239
249
|
body_fmt = Format.new($top_ex, $ex)
|
240
250
|
body_fmt.useHash( x == 0 )
|
241
|
-
|
242
|
-
|
243
|
-
|
251
|
+
file = StringIO.new
|
252
|
+
helper_test_three(body_fmt, file)
|
253
|
+
file.rewind
|
254
|
+
assert(compareOutput(file, "./format_test.pl 3", nil))
|
244
255
|
end
|
245
256
|
end
|
246
257
|
|
247
258
|
|
248
|
-
def helper_test_four (body_fmt,
|
249
|
-
File.open(file_name, File::CREAT | File::WRONLY | File::TRUNC) { |file|
|
259
|
+
def helper_test_four (body_fmt, file)
|
250
260
|
body_fmt.io = file
|
251
261
|
month = "Sep"
|
252
262
|
day = 18
|
@@ -254,39 +264,38 @@ class FormatTester < Test::Unit::TestCase
|
|
254
264
|
10.times do
|
255
265
|
num = 1
|
256
266
|
["Market", "Home", "Eating Roast Beef",
|
257
|
-
"Having None", "On the way home"].each
|
267
|
+
"Having None", "On the way home"].each do |location|
|
258
268
|
toe_size = (num * 3.5)
|
259
269
|
body_fmt.printFormat(binding)
|
260
270
|
num += 1
|
261
|
-
|
271
|
+
end
|
262
272
|
end
|
263
|
-
|
264
|
-
assert(compareOutput(
|
265
|
-
"./format_test.pl 4", nil))
|
273
|
+
file.rewind
|
274
|
+
assert(compareOutput(file, "./format_test.pl 4", nil))
|
266
275
|
end
|
267
276
|
|
268
|
-
def helper_hash_test_four (body_fmt,
|
277
|
+
def helper_hash_test_four (body_fmt, file)
|
269
278
|
h = Hash.new
|
270
279
|
h["month"] = "Sep"
|
271
280
|
h['day'] = 18
|
272
281
|
h['year'] = 2001
|
273
|
-
|
282
|
+
file = StringIO.new
|
274
283
|
body_fmt.io = file
|
275
284
|
10.times do
|
276
285
|
num = 1
|
277
286
|
h["num"] = num
|
278
287
|
["Market", "Home", "Eating Roast Beef",
|
279
|
-
"Having None", "On the way home"].each
|
288
|
+
"Having None", "On the way home"].each do |location|
|
280
289
|
h["location"] = location
|
281
290
|
h["toe_size"] = (num * 3.5)
|
282
291
|
body_fmt.printFormatWithHash(h)
|
283
292
|
num += 1
|
284
293
|
h["num"] = num
|
285
|
-
|
294
|
+
end
|
286
295
|
end
|
287
|
-
|
288
|
-
|
289
|
-
|
296
|
+
|
297
|
+
file.rewind
|
298
|
+
assert(compareOutput(file, "./format_test.pl 4", nil))
|
290
299
|
end
|
291
300
|
|
292
301
|
|
@@ -300,10 +309,11 @@ class FormatTester < Test::Unit::TestCase
|
|
300
309
|
body_fmt.setTop($top_ex)
|
301
310
|
body_fmt.setBottom(bottom_fmt)
|
302
311
|
body_fmt.setPageLength(10)
|
312
|
+
file = StringIO.new
|
303
313
|
if (x <2)
|
304
|
-
helper_test_four(body_fmt,
|
314
|
+
helper_test_four(body_fmt, file)
|
305
315
|
else
|
306
|
-
helper_hash_test_four(body_fmt,
|
316
|
+
helper_hash_test_four(body_fmt, file)
|
307
317
|
end
|
308
318
|
end
|
309
319
|
end
|
@@ -312,9 +322,7 @@ class FormatTester < Test::Unit::TestCase
|
|
312
322
|
#test the finishPage methods and setting all three formats at once,
|
313
323
|
#top, bottom, and middle.
|
314
324
|
|
315
|
-
def helper_test_five (body_fmt,
|
316
|
-
File.open(file_name,
|
317
|
-
File::CREAT | File::WRONLY | File::TRUNC) { |file|
|
325
|
+
def helper_test_five (body_fmt, file)
|
318
326
|
body_fmt.io = file
|
319
327
|
month = "Sep"
|
320
328
|
day = 19
|
@@ -323,15 +331,15 @@ class FormatTester < Test::Unit::TestCase
|
|
323
331
|
10.times do
|
324
332
|
count += 1
|
325
333
|
num = 1
|
326
|
-
["Market", "Home", "Eating Roast Beef",
|
334
|
+
["Market", "Home", "Eating Roast Beef",
|
335
|
+
"Having None", "On the way home"].each do |location|
|
327
336
|
toe_size = 1
|
328
337
|
body_fmt.printFormat(binding)
|
329
338
|
num += 1
|
330
|
-
|
339
|
+
end
|
331
340
|
body_fmt.finishPageWithFF(binding) unless (count == 10)
|
332
341
|
end
|
333
342
|
body_fmt.finishPageWithoutFF(binding)
|
334
|
-
}
|
335
343
|
end
|
336
344
|
|
337
345
|
def test_five
|
@@ -339,23 +347,22 @@ class FormatTester < Test::Unit::TestCase
|
|
339
347
|
body_fmt = Format.new($top_ex, $ex, $bot_ex)
|
340
348
|
body_fmt.useHash(x == 0)
|
341
349
|
body_fmt.setPageLength(20)
|
342
|
-
|
343
|
-
|
350
|
+
file = StringIO.new
|
351
|
+
helper_test_five(body_fmt, file)
|
352
|
+
file.rewind
|
353
|
+
assert(compareOutput(file,
|
344
354
|
"./format_test.pl 5", nil))
|
345
355
|
end
|
346
356
|
end
|
347
357
|
|
348
358
|
|
349
|
-
def helper_test_six (body_fmt,
|
350
|
-
File.open(file_name,
|
351
|
-
File::CREAT | File::WRONLY | File::TRUNC) { |file|
|
359
|
+
def helper_test_six (body_fmt, file)
|
352
360
|
body_fmt.io = file
|
353
361
|
long = "01234567890abcde fg h i jklmn12345678901234567890123456.789"
|
354
362
|
num = 123.456
|
355
363
|
short = '123.456'
|
356
364
|
body_fmt.printFormat(binding)
|
357
365
|
raise "page numbering not working " unless (1 == body_fmt.pageNumber())
|
358
|
-
}
|
359
366
|
end
|
360
367
|
|
361
368
|
def test_six
|
@@ -364,38 +371,37 @@ class FormatTester < Test::Unit::TestCase
|
|
364
371
|
hat_format = Format.new($hat_ex)
|
365
372
|
hat_format.setTop(hat_top)
|
366
373
|
hat_format.useHash(x == 1)
|
367
|
-
|
368
|
-
|
369
|
-
|
374
|
+
file = StringIO.new
|
375
|
+
helper_test_six(hat_format, file)
|
376
|
+
|
377
|
+
file.rewind
|
378
|
+
assert(compareOutput(file, "./format_test.pl 6", nil))
|
370
379
|
end
|
371
380
|
end
|
372
381
|
|
373
382
|
|
374
|
-
def helper_test_seven (body_fmt,
|
375
|
-
File.open(file_name,
|
376
|
-
File::CREAT | File::WRONLY | File::TRUNC) { |file|
|
383
|
+
def helper_test_seven (body_fmt, file)
|
377
384
|
body_fmt.io = file
|
378
385
|
blank = ""
|
379
386
|
non_blank = " "
|
380
387
|
string = "abcdefghijklmn"
|
381
388
|
body_fmt.printFormat(binding)
|
382
|
-
|
389
|
+
|
383
390
|
end
|
384
391
|
|
385
392
|
def test_seven
|
386
|
-
puts "test 7"
|
387
393
|
0.upto(1) do |x|
|
394
|
+
file = StringIO.new
|
388
395
|
tilde_format = Format.new($test_5)
|
389
|
-
helper_test_seven(tilde_format,
|
390
|
-
|
396
|
+
helper_test_seven(tilde_format, file)
|
397
|
+
|
398
|
+
file.rewind
|
399
|
+
assert(compareOutput(file,
|
391
400
|
"./format_test.pl 7", nil))
|
392
401
|
end
|
393
|
-
puts "test 7 end"
|
394
402
|
end
|
395
403
|
|
396
|
-
def helper_test_eight (body_fmt,
|
397
|
-
File.open(file_name,
|
398
|
-
File::CREAT | File::WRONLY | File::TRUNC) { |file|
|
404
|
+
def helper_test_eight (body_fmt, file)
|
399
405
|
body_fmt.io = file
|
400
406
|
blank = ""
|
401
407
|
non_blank = " "
|
@@ -403,50 +409,50 @@ class FormatTester < Test::Unit::TestCase
|
|
403
409
|
|
404
410
|
body_fmt.printFormat(binding)
|
405
411
|
body_fmt.finishPageWithoutFF(binding)
|
406
|
-
}
|
407
412
|
end
|
408
413
|
|
409
414
|
def test_eight
|
410
415
|
#Problems when formats don't fit on a single page!
|
411
416
|
0.upto(1) do |x|
|
417
|
+
file = StringIO.new
|
412
418
|
tilde_format = Format.new($test_5)
|
413
419
|
tilde_format.setPageLength(10)
|
414
420
|
tilde_format.useHash(x == 0)
|
415
|
-
helper_test_eight(tilde_format,
|
416
|
-
|
421
|
+
helper_test_eight(tilde_format, file)
|
422
|
+
|
423
|
+
file.rewind
|
424
|
+
assert(compareOutput(file,
|
417
425
|
"./format_test.pl 8", nil))
|
418
426
|
end
|
419
427
|
end
|
420
428
|
|
421
429
|
|
422
|
-
def helper_test_empty_top_bottom (body_fmt,
|
423
|
-
File.open(file_name,
|
424
|
-
File::CREAT | File::WRONLY | File::TRUNC) { |file|
|
430
|
+
def helper_test_empty_top_bottom (body_fmt, file)
|
425
431
|
body_fmt.io = file
|
426
432
|
blank = ""
|
427
433
|
non_blank = " "
|
428
434
|
string = ("a"*100) + "b"
|
429
435
|
body_fmt.printFormat(binding)
|
430
436
|
body_fmt.finishPageWithoutFF(binding)
|
431
|
-
}
|
432
437
|
end
|
433
438
|
|
434
439
|
#can we pass in an emptry string as a top and nil as a bottom?
|
435
440
|
def test_empty_top_bottom
|
436
441
|
0.upto(1) do |x|
|
442
|
+
file = StringIO.new
|
437
443
|
#Problems when formats don't fit on a single page!
|
438
444
|
tilde_format = Format.new("",$test_5, nil)
|
439
445
|
tilde_format.useHash(x == 0)
|
440
446
|
tilde_format.setPageLength(10)
|
441
|
-
helper_test_empty_top_bottom(tilde_format,
|
442
|
-
|
447
|
+
helper_test_empty_top_bottom(tilde_format, file)
|
448
|
+
|
449
|
+
file.rewind
|
450
|
+
assert(compareOutput(file,
|
443
451
|
"./format_test.pl 8", nil))
|
444
452
|
end
|
445
453
|
end
|
446
454
|
|
447
|
-
def helper_test_scientific (body_fmt,
|
448
|
-
File.open(file_name,
|
449
|
-
File::CREAT | File::WRONLY | File::TRUNC) { |file|
|
455
|
+
def helper_test_scientific (body_fmt, file)
|
450
456
|
body_fmt.io = file
|
451
457
|
int = 12
|
452
458
|
exp = 1.234e-14
|
@@ -454,7 +460,6 @@ class FormatTester < Test::Unit::TestCase
|
|
454
460
|
big = 123.4567E200
|
455
461
|
little = 12.34e-20
|
456
462
|
body_fmt.printFormat(binding)
|
457
|
-
}
|
458
463
|
end
|
459
464
|
|
460
465
|
def test_scientific
|
@@ -480,34 +485,34 @@ class FormatTester < Test::Unit::TestCase
|
|
480
485
|
f.push("7 int @.G## @.E##")
|
481
486
|
f.push("int, int")
|
482
487
|
0.upto(1) do |x|
|
488
|
+
file = StringIO.new
|
483
489
|
exp_format = Format.new("", f, nil)
|
484
490
|
exp_format.useHash(x == 0)
|
485
|
-
helper_test_scientific(exp_format,
|
486
|
-
|
491
|
+
helper_test_scientific(exp_format, file)
|
492
|
+
|
493
|
+
file.rewind
|
494
|
+
assert(compareOutput(file,
|
487
495
|
"./format_test.pl 10", nil))
|
488
496
|
end
|
489
497
|
end
|
490
498
|
|
491
|
-
def helper_test_eleven (body_fmt,
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
}
|
498
|
-
assert(compareOutput(file_name,
|
499
|
+
def helper_test_eleven (body_fmt, file)
|
500
|
+
body_fmt.io = file
|
501
|
+
one = 1
|
502
|
+
body_fmt.printFormat(binding)
|
503
|
+
file.rewind
|
504
|
+
assert(compareOutput(file,
|
499
505
|
"./format_test.pl 11", nil))
|
500
506
|
end
|
501
507
|
|
502
|
-
def helper_hash_test_eleven (body_fmt,
|
508
|
+
def helper_hash_test_eleven (body_fmt, file)
|
503
509
|
h = Hash.new
|
504
510
|
h['one'] = 1
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
assert(compareOutput(file_name,
|
511
|
+
body_fmt.io = file
|
512
|
+
body_fmt.printFormatWithHash( h )
|
513
|
+
|
514
|
+
file.rewind
|
515
|
+
assert(compareOutput(file,
|
511
516
|
"./format_test.pl 11", nil))
|
512
517
|
end
|
513
518
|
|
@@ -518,26 +523,27 @@ class FormatTester < Test::Unit::TestCase
|
|
518
523
|
f.push( '@@@ @@@' )
|
519
524
|
f.push( 'one,one,one,one,one,one')
|
520
525
|
0.upto(1) do |x|
|
526
|
+
file = StringIO.new
|
521
527
|
format = Format.new(f)
|
522
|
-
helper_test_eleven(format,
|
528
|
+
helper_test_eleven(format, file)
|
523
529
|
|
524
530
|
end
|
531
|
+
file = StringIO.new
|
525
532
|
format = Format.new(f)
|
526
|
-
helper_hash_test_eleven(format,
|
533
|
+
helper_hash_test_eleven(format, file)
|
527
534
|
|
528
535
|
end
|
529
536
|
|
530
|
-
def helper_test_twelve (body_fmt,
|
537
|
+
def helper_test_twelve (body_fmt, file)
|
531
538
|
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
539
|
body_fmt.io = file
|
535
540
|
body_fmt.printFormat(binding)
|
536
|
-
|
541
|
+
|
542
|
+
file.rewind
|
537
543
|
output = []
|
538
|
-
|
539
|
-
|
540
|
-
|
544
|
+
|
545
|
+
output = file.readlines()
|
546
|
+
|
541
547
|
|
542
548
|
reader = FormatReader.new(body_fmt)
|
543
549
|
res = reader.readFormat(output)
|
@@ -548,13 +554,14 @@ class FormatTester < Test::Unit::TestCase
|
|
548
554
|
assert(res['var_three'] == var_three.to_s)
|
549
555
|
assert(res['var_four'] == var_four)
|
550
556
|
# we need to compare last since compare may delete the file when its done
|
551
|
-
|
557
|
+
|
558
|
+
file.rewind
|
559
|
+
assert(compareOutput(file,
|
552
560
|
"./format_test.pl 12", nil))
|
553
561
|
end
|
554
562
|
|
555
563
|
# try out reading in variables
|
556
564
|
def test_twelve
|
557
|
-
puts "test 12"
|
558
565
|
f = []
|
559
566
|
f.push( '<?xml version="1.0"?>' )
|
560
567
|
f.push( '@@@ Paul @@@ }Rubel @< @|| @#.#' )
|
@@ -568,11 +575,12 @@ class FormatTester < Test::Unit::TestCase
|
|
568
575
|
pictures = format.getPictureLines
|
569
576
|
assert(pictures.size == 3)
|
570
577
|
|
571
|
-
|
578
|
+
file = StringIO.new
|
579
|
+
helper_test_twelve(format, file)
|
572
580
|
end
|
573
581
|
end
|
574
582
|
|
575
|
-
def helper_test_thirteen (body_fmt,
|
583
|
+
def helper_test_thirteen (body_fmt, file)
|
576
584
|
one = "FIVE SIX"
|
577
585
|
val1 = one.clone
|
578
586
|
two = "ONE TWO"
|
@@ -580,17 +588,16 @@ class FormatTester < Test::Unit::TestCase
|
|
580
588
|
val3 = "Yay"
|
581
589
|
var_exp = 3.44e10
|
582
590
|
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
body_fmt.printFormat(binding)
|
587
|
-
}
|
591
|
+
body_fmt.io = file
|
592
|
+
body_fmt.printFormat(binding)
|
593
|
+
|
588
594
|
|
589
595
|
#save the output for later
|
596
|
+
file.rewind
|
590
597
|
output = []
|
591
|
-
|
592
|
-
|
593
|
-
|
598
|
+
|
599
|
+
output = file.readlines()
|
600
|
+
|
594
601
|
|
595
602
|
reader = FormatReader.new(body_fmt)
|
596
603
|
res = reader.readFormat(output)
|
@@ -599,13 +606,10 @@ class FormatTester < Test::Unit::TestCase
|
|
599
606
|
assert(res['val2'] == two)
|
600
607
|
assert(res['val3'] == val3)
|
601
608
|
assert(res['var_exp'] == var_exp)
|
602
|
-
puts "tested 13 in #{file_name}"
|
603
|
-
File.delete(file_name) unless (@@keep)
|
604
609
|
end
|
605
610
|
|
606
611
|
# See if we can handle repeat lines in with regular ones
|
607
612
|
def test_thirteen
|
608
|
-
puts "test 13"
|
609
613
|
f = []
|
610
614
|
f.push( '<?xml version="1.0"?>' )
|
611
615
|
f.push( '~~^<<< TEST1' )
|
@@ -619,13 +623,14 @@ class FormatTester < Test::Unit::TestCase
|
|
619
623
|
|
620
624
|
format = Format.new(f)
|
621
625
|
0.upto(1) do |x|
|
626
|
+
file = StringIO.new
|
622
627
|
format.useHash(x == 0)
|
623
|
-
helper_test_thirteen(format,
|
628
|
+
helper_test_thirteen(format, file)
|
624
629
|
end
|
625
630
|
|
626
631
|
end
|
627
632
|
|
628
|
-
def helper_test_fourteen (body_fmt,
|
633
|
+
def helper_test_fourteen (body_fmt, file)
|
629
634
|
one = "FIVE"
|
630
635
|
val1 = one.clone
|
631
636
|
two = "ONE"
|
@@ -634,19 +639,17 @@ class FormatTester < Test::Unit::TestCase
|
|
634
639
|
var_exp = 3.44e10
|
635
640
|
change = ["Yip", "Yie", "Yoo"]
|
636
641
|
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
3.times do |i|
|
642
|
+
body_fmt.io = file
|
643
|
+
|
644
|
+
3.times do |i|
|
642
645
|
val2 = change[i].clone
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
+
body_fmt.printFormat(binding)
|
647
|
+
end
|
648
|
+
|
649
|
+
#save the output for later
|
650
|
+
file.rewind
|
651
|
+
output = file.readlines
|
646
652
|
|
647
|
-
#save the output for later
|
648
|
-
output = IO.readlines(file_name)
|
649
|
-
File.delete(file_name) unless (@@keep)
|
650
653
|
reader = FormatReader.new(body_fmt)
|
651
654
|
loops = 0
|
652
655
|
reader.readFormat(output) do |vals|
|
@@ -663,7 +666,6 @@ class FormatTester < Test::Unit::TestCase
|
|
663
666
|
|
664
667
|
# See if we can handle repeat lines in with regular ones
|
665
668
|
def test_fourteen
|
666
|
-
puts "test 14"
|
667
669
|
f = []
|
668
670
|
f.push( '<?xml version="1.0"?>' )
|
669
671
|
f.push( '@<<< TEST1' )
|
@@ -678,13 +680,13 @@ class FormatTester < Test::Unit::TestCase
|
|
678
680
|
format = Format.new(f)
|
679
681
|
0.upto(1) do |x|
|
680
682
|
format.useHash(x == 0)
|
681
|
-
|
683
|
+
file = StringIO.new
|
684
|
+
helper_test_fourteen(format, file)
|
682
685
|
end
|
683
686
|
end
|
684
687
|
|
685
688
|
# See if we can handle repeat lines in with regular ones
|
686
689
|
def test_fifteen
|
687
|
-
puts "test 15"
|
688
690
|
f = []
|
689
691
|
f.push('@>>>>>>>>>>>>>> ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<')
|
690
692
|
f.push('author, quote')
|
@@ -696,26 +698,26 @@ class FormatTester < Test::Unit::TestCase
|
|
696
698
|
authors = []
|
697
699
|
quotes = []
|
698
700
|
format = Format.new(f)
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
701
|
+
file = StringIO.new
|
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 " +
|
713
|
+
"branch if the result is negative?"
|
714
|
+
quotes[1] = quote
|
715
|
+
format.printFormat(binding)
|
716
|
+
|
717
|
+
file.rewind
|
716
718
|
|
717
719
|
#save the output for later
|
718
|
-
output =
|
720
|
+
output = file.readlines
|
719
721
|
|
720
722
|
reader = FormatReader.new(format)
|
721
723
|
loops = 0
|
@@ -724,7 +726,9 @@ class FormatTester < Test::Unit::TestCase
|
|
724
726
|
assert(vals["quote"] = quotes[loops])
|
725
727
|
loops += 1
|
726
728
|
end
|
727
|
-
|
729
|
+
|
730
|
+
file.rewind
|
731
|
+
assert(compareOutput(file,
|
728
732
|
"./format_test.pl 15", nil))
|
729
733
|
|
730
734
|
end
|
@@ -732,7 +736,8 @@ class FormatTester < Test::Unit::TestCase
|
|
732
736
|
# show that page numbers are fixed on the top and bottom
|
733
737
|
def test_page_numbers
|
734
738
|
#Problems when formats don't fit on a single page!
|
735
|
-
|
739
|
+
file = StringIO.new
|
740
|
+
|
736
741
|
top = "---- Top --- Page Number @<<<----\n$page_number\n"
|
737
742
|
bottom = "---- Bot --- Page Number @<<<----\n$page_number\n \n"
|
738
743
|
page_num_format = Format.new(top,$ex, bottom)
|
@@ -749,9 +754,10 @@ class FormatTester < Test::Unit::TestCase
|
|
749
754
|
num = page_num_format.pageNumber()
|
750
755
|
toe_size = page_num_format.pageNumber()
|
751
756
|
end
|
752
|
-
|
753
|
-
|
754
|
-
|
757
|
+
|
758
|
+
file.rewind
|
759
|
+
assert(compareOutput(file,
|
760
|
+
"./format_test.pl 13", nil)) end
|
755
761
|
|
756
762
|
|
757
763
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: formatr
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.10.
|
7
|
-
date: 2008-
|
6
|
+
version: 1.10.1
|
7
|
+
date: 2008-02-12 00:00:00 -05:00
|
8
8
|
summary: A library to read and write Perl-like formats
|
9
9
|
require_paths:
|
10
10
|
- lib
|