text-reform 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/HACKING +5 -0
- data/History.txt +14 -0
- data/LICENSE +23 -0
- data/Manifest.txt +11 -0
- data/README +49 -36
- data/lib/text/reform.rb +1541 -1541
- data/{tests/tc_text_reform.rb → test/test_text_reform.rb} +448 -451
- metadata +58 -53
- data/Changelog +0 -5
- data/Install +0 -4
- data/Rakefile +0 -116
- data/TODO +0 -5
- data/tests/testall.rb +0 -20
@@ -1,451 +1,448 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
output
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
result
|
130
|
-
result << "
|
131
|
-
result
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
r.
|
149
|
-
assert_equal "Pay bearer:
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
assert_equal
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
assert_equal(" 1.0 \n
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
assert_equal " test
|
213
|
-
assert_equal "
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
assert_equal "
|
221
|
-
r.format("
|
222
|
-
assert_equal "
|
223
|
-
r.format(" ]]]]]]]
|
224
|
-
assert_equal "
|
225
|
-
r.format("
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
assert_equal(" supercalifragilo- \n usexpalidoucious \n", r.format(" [[[[[[[[[[[
|
240
|
-
assert_equal(" supercalifragilo- \n
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
assert_equal(" supercalifrag- \n ilousexpali- \n doucious \n", r.format(" [[[[[[[[[[[
|
265
|
-
assert_equal("
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
assert_equal(" supercalifrag- \n ilousexpali- \n doucious \n", r.format(" [[[[[[[[[[[
|
290
|
-
assert_equal("
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
fmt
|
302
|
-
fmt << " [[[[[[[[[[[[[[[\n"
|
303
|
-
|
304
|
-
fmt
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
s
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
s
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
return
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
''
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
r.
|
403
|
-
|
404
|
-
r.
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
r.
|
410
|
-
r.
|
411
|
-
|
412
|
-
r.
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
r.
|
417
|
-
|
418
|
-
r.
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
result
|
439
|
-
result << "
|
440
|
-
result << "
|
441
|
-
|
442
|
-
result
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
name, score, time))
|
450
|
-
end
|
451
|
-
end
|
1
|
+
require "test/unit"
|
2
|
+
require "text/reform"
|
3
|
+
|
4
|
+
class TestTextReform < Test::Unit::TestCase
|
5
|
+
TEST_PAGINATION_1 = <<-EOS
|
6
|
+
Page 7
|
7
|
+
|
8
|
+
Vestibulum at felis. Praesent turpis
|
9
|
+
velit, elementum eget, porttitor id,
|
10
|
+
bibendum auctor, metus. Ut facilisis
|
11
|
+
commodo quam. Quisque nec urna ultr-
|
12
|
+
icies justo condimentum tristique.
|
13
|
+
Proin eget sem eu neque sollicitudin
|
14
|
+
--------------------------------------------------
|
15
|
+
...8
|
16
|
+
|
17
|
+
|
18
|
+
Page 8
|
19
|
+
|
20
|
+
luctus. Etiam mi dolor, aliquet ege-
|
21
|
+
t, pellentesque ultrices, nonummy e-
|
22
|
+
t, diam. Sed odio enim, ultrices no-
|
23
|
+
n, aliquam vitae, sodales sed, odio.
|
24
|
+
Maecenas id justo. Quisque viverra
|
25
|
+
malesuada neque. Cras auctor ipsum
|
26
|
+
--------------------------------------------------
|
27
|
+
...9
|
28
|
+
|
29
|
+
|
30
|
+
Page 9
|
31
|
+
|
32
|
+
ac ante. Vestibulum consectetuer. N-
|
33
|
+
ullam mi est, pretium at, elementum
|
34
|
+
at, dictum scelerisque, purus. Inte-
|
35
|
+
ger leo velit, adipiscing in, biben-
|
36
|
+
dum nec, euismod sit amet, quam. Sed
|
37
|
+
porttitor lorem vitae neque. Maecen-
|
38
|
+
--------------------------------------------------
|
39
|
+
...10
|
40
|
+
|
41
|
+
|
42
|
+
Page 10
|
43
|
+
|
44
|
+
as sem lorem, aliquet non, vulputate
|
45
|
+
vitae, consequat ornare, elit. Pell-
|
46
|
+
entesque nec lectus quis felis posu-
|
47
|
+
ere pharetra.
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
EOS
|
53
|
+
TEST_PAGINATION_2 = <<-EOS
|
54
|
+
Running head
|
55
|
+
Vestibulum at felis. Praesent turpis
|
56
|
+
velit, elementum eget, porttitor id,
|
57
|
+
bibendum auctor, metus. Ut facilisis
|
58
|
+
commodo quam. Quisque nec urna ultr-
|
59
|
+
icies justo condimentum tristique.
|
60
|
+
Proin eget sem eu neque sollicitudin
|
61
|
+
luctus. Etiam mi dolor, aliquet ege-
|
62
|
+
t, pellentesque ultrices, nonummy e-
|
63
|
+
page 1
|
64
|
+
|
65
|
+
|
66
|
+
Running head
|
67
|
+
t, diam. Sed odio enim, ultrices no-
|
68
|
+
n, aliquam vitae, sodales sed, odio.
|
69
|
+
Maecenas id justo. Quisque viverra
|
70
|
+
malesuada neque. Cras auctor ipsum
|
71
|
+
ac ante. Vestibulum consectetuer. N-
|
72
|
+
ullam mi est, pretium at, elementum
|
73
|
+
at, dictum scelerisque, purus. Inte-
|
74
|
+
ger leo velit, adipiscing in, biben-
|
75
|
+
page 2
|
76
|
+
|
77
|
+
|
78
|
+
Running head
|
79
|
+
dum nec, euismod sit amet, quam. Sed
|
80
|
+
porttitor lorem vitae neque. Maecen-
|
81
|
+
as sem lorem, aliquet non, vulputate
|
82
|
+
vitae, consequat ornare, elit. Pell-
|
83
|
+
entesque nec lectus quis felis posu-
|
84
|
+
ere pharetra.
|
85
|
+
|
86
|
+
|
87
|
+
page 3
|
88
|
+
EOS
|
89
|
+
|
90
|
+
attr_reader :r
|
91
|
+
def setup
|
92
|
+
@r = Text::Reform.new
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_abiglongtext
|
96
|
+
count = 1
|
97
|
+
text = "A big long piece of text to be formatted exquisitely"
|
98
|
+
output = ""
|
99
|
+
output << r.format(" |||| <<<<<<<<<< ", count, text)
|
100
|
+
output << r.format(" ---------------- ",
|
101
|
+
" ^^^^ ]]]]]]]]]]| ", count + 11, text)
|
102
|
+
|
103
|
+
reference = <<-EOS
|
104
|
+
1 A big long
|
105
|
+
----------------
|
106
|
+
12 piece of|
|
107
|
+
text to be|
|
108
|
+
formatted|
|
109
|
+
exquisite-|
|
110
|
+
ly|
|
111
|
+
EOS
|
112
|
+
|
113
|
+
assert_equal reference, output
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_formular
|
117
|
+
name = 'John Doe'
|
118
|
+
rank = 'high'
|
119
|
+
serial_number = '314159'
|
120
|
+
|
121
|
+
report = ''
|
122
|
+
report << r.format('Name Rank Serial Number',
|
123
|
+
'==== ==== =============',
|
124
|
+
'<<<<<<<<<<<<< ^^^^ <<<<<<<<<<<<<',
|
125
|
+
name, rank, serial_number)
|
126
|
+
|
127
|
+
result = ''
|
128
|
+
result << "Name Rank Serial Number\n"
|
129
|
+
result << "==== ==== =============\n"
|
130
|
+
result << "John Doe high 314159 \n"
|
131
|
+
assert_equal result, report
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_trim
|
135
|
+
r.trim = false
|
136
|
+
assert_equal 11, r.format("[[[[[[[[[[", "short").length
|
137
|
+
|
138
|
+
r.trim = true
|
139
|
+
assert_equal 6, r.format("[[[[[[[[[[[", "short").length
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_filler
|
143
|
+
r.filler = '*'
|
144
|
+
assert_equal "Pay bearer: *******$123.4*******\n", r.format("Pay bearer: ^^^^^^^^^^^^^^^^^^^^", '$123.4')
|
145
|
+
|
146
|
+
r.filler= '-->'
|
147
|
+
assert_equal "Pay bearer: -->-->-$123.4-->-->-\n", r.format("Pay bearer: ^^^^^^^^^^^^^^^^^^^^", '$123.4')
|
148
|
+
assert_equal "Pay bearer: -->-->-$12.4-->-->--\n", r.format("Pay bearer: ^^^^^^^^^^^^^^^^^^^^", '$12.4')
|
149
|
+
assert_equal "Pay bearer: -->-->--$1.4-->-->--\n", r.format("Pay bearer: ^^^^^^^^^^^^^^^^^^^^", '$1.4')
|
150
|
+
|
151
|
+
r.filler = {
|
152
|
+
:left => 'l',
|
153
|
+
:right => 'r'
|
154
|
+
}
|
155
|
+
assert_equal "Pay bearer: lllllll$123.4rrrrrrr\n", r.format("Pay bearer: ^^^^^^^^^^^^^^^^^^^^", '$123.4')
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_data_format
|
159
|
+
# String form
|
160
|
+
s1 = r.format "]]]].[[", "1234\n123"
|
161
|
+
|
162
|
+
# Array form
|
163
|
+
s2 = r.format "]]]].[[", [ 1234, 123 ]
|
164
|
+
|
165
|
+
# Array with another type
|
166
|
+
s3 = r.format "]]]].[[", [ 1234.0, 123.0 ]
|
167
|
+
|
168
|
+
assert_equal "1234.0 \n 123.0 \n", s1
|
169
|
+
assert_equal s1, s2
|
170
|
+
assert_equal s2, s3
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_multiline_numbers
|
174
|
+
assert_equal "1 \n2 \n3 \n", r.format("[[[[[[", (1..3).to_a.map { |el| el.to_s })
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_wrong_number_of_data_args
|
178
|
+
assert_nothing_raised do
|
179
|
+
r.format("]]]]]]]] ]]]]]]]]", 'a single data item')
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_whitespace
|
184
|
+
assert_equal("EG> h e\t l lo \nEG> world \n",
|
185
|
+
r.format("EG> [[[[[[[[[[[[[[[[[[[[[",
|
186
|
+
"h e\t l lo\nworld\t\t\t\t\t"))
|
187
|
+
|
188
|
+
r.squeeze = true
|
189
|
+
assert_equal("EG> h e l lo \nEG> world \n",
|
190
|
+
r.format("EG> [[[[[[[[[[[[[[[[[[[[[",
|
191
|
+
"h e\t l lo\nworld\t\t\t\t\t"))
|
192
|
+
|
193
|
+
r.fill = true
|
194
|
+
assert_equal("EG> h e l lo world \n",
|
195
|
+
r.format("EG> [[[[[[[[[[[[[[[[[[[[[",
|
196
|
+
"h \n e\t l\n lo\nworld\t\n\t\t\t\t"))
|
197
|
+
r.squeeze = false
|
198
|
+
r.fill = false
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_format_numbers
|
202
|
+
numbers = [ 1, 1.2, 1.23, 1.234, 1.2345, "1.2345" ]
|
203
|
+
|
204
|
+
assert_equal(" 1.0 \n 1.2 \n 1.23 \n 1.234 \n 1.234 \n 1.234 \n",
|
205
|
+
r.format(" ]]].[[[ ", numbers))
|
206
|
+
assert_equal(" 1.0 \n", r.format(" >>>.<<< ", numbers))
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_basic_formatting_tests
|
210
|
+
assert_equal " test \n", r.format(" <<<<<<<<<<<<<<<<<< ", 'test')
|
211
|
+
assert_equal " test \n", r.format(" >>>>>>>>>>>>>>>>>> ", 'test')
|
212
|
+
assert_equal " this is a test \n", r.format(" <<<<<<<<<>>>>>>>>> ", 'this is a test')
|
213
|
+
assert_equal " test \n", r.format(" ^^^^^^^^^^^^^^^^^^ ", 'test')
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_multi_formatting_tests
|
217
|
+
text = "A big long piece of text to be formatted exquisitely"
|
218
|
+
assert_equal " A big long piece \n of text to be for- \n matted exquisitely \n",
|
219
|
+
r.format(" [[[[[[[[[[[[[[[[[[ ", text.dup)
|
220
|
+
assert_equal " A big long piece \n of text to be for- \n matted exquisitely \n",
|
221
|
+
r.format(" ]]]]]]]]]]]]]]]]]] ", text.dup)
|
222
|
+
assert_equal " A big long piece \n of text to be for- \n matted exquisitely \n",
|
223
|
+
r.format(" [[[[[[[[[[[]]]]]]] ", text.dup)
|
224
|
+
assert_equal " A big long piece \n of text to be for- \n matted exquisitely \n",
|
225
|
+
r.format(" |||||||||||||||||| ", text.dup)
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_array_argument
|
229
|
+
assert_equal " a lotta words come \n", r.format(" <<<<<<<<<<<<<<<<<< ", %w{ a lotta words come here in an array }.join(' '))
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_break_at
|
233
|
+
text = "supercalifragilousexpalidoucious"
|
234
|
+
|
235
|
+
@r.break = Text::Reform.break_at('-')
|
236
|
+
|
237
|
+
assert_equal(" supercalifragilo- \n usexpalidoucious \n", r.format(" [[[[[[[[[[[[[[[[[ ", text.dup))
|
238
|
+
assert_equal(" supercalifragilo- \n usexpalidoucious \n", r.format(" ]]]]]]]]]]]]]]]]] ", text.dup))
|
239
|
+
assert_equal(" supercalifragilo- \n usexpalidoucious \n", r.format(" [[[[[[[[[[[]]]]]] ", text.dup))
|
240
|
+
assert_equal(" supercalifragilo- \n usexpalidoucious \n", r.format(" ||||||||||||||||| ", text.dup))
|
241
|
+
end
|
242
|
+
|
243
|
+
def test_break_tex
|
244
|
+
begin
|
245
|
+
require 'tex/hyphen'
|
246
|
+
hy = TeX::Hyphen.new
|
247
|
+
rescue LoadError
|
248
|
+
begin
|
249
|
+
require 'rubygems'
|
250
|
+
require 'tex/hyphen'
|
251
|
+
hy = TeX::Hyphen.new
|
252
|
+
rescue LoadError
|
253
|
+
print 'S'
|
254
|
+
return true
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
text = "supercalifragilousexpalidoucious"
|
259
|
+
|
260
|
+
@r.break = Text::Reform.break_hyphenator(hy)
|
261
|
+
|
262
|
+
assert_equal(" supercalifrag- \n ilousexpali- \n doucious \n", r.format(" [[[[[[[[[[[[[[[[[ ", text.dup))
|
263
|
+
assert_equal(" supercalifrag- \n ilousexpali- \n doucious \n", r.format(" ]]]]]]]]]]]]]]]]] ", text.dup))
|
264
|
+
assert_equal(" supercalifrag- \n ilousexpali- \n doucious \n", r.format(" [[[[[[[[[[[]]]]]] ", text.dup))
|
265
|
+
assert_equal(" supercalifrag- \n ilousexpali- \n doucious \n", r.format(" ||||||||||||||||| ", text.dup))
|
266
|
+
end
|
267
|
+
|
268
|
+
def test_break_texthyphen
|
269
|
+
begin
|
270
|
+
require 'text/hyphen'
|
271
|
+
hy = Text::Hyphen.new
|
272
|
+
rescue LoadError
|
273
|
+
begin
|
274
|
+
require 'rubygems'
|
275
|
+
require 'text/hyphen'
|
276
|
+
hy = Text::Hyphen.new
|
277
|
+
rescue LoadError
|
278
|
+
print 'S'
|
279
|
+
return true
|
280
|
+
end
|
281
|
+
end
|
282
|
+
text = "supercalifragilousexpalidoucious"
|
283
|
+
|
284
|
+
hy = Text::Hyphen.new
|
285
|
+
@r.break = Text::Reform.break_hyphenator(hy)
|
286
|
+
|
287
|
+
assert_equal(" supercalifrag- \n ilousexpali- \n doucious \n", r.format(" [[[[[[[[[[[[[[[[[ ", text.dup))
|
288
|
+
assert_equal(" supercalifrag- \n ilousexpali- \n doucious \n", r.format(" ]]]]]]]]]]]]]]]]] ", text.dup))
|
289
|
+
assert_equal(" supercalifrag- \n ilousexpali- \n doucious \n", r.format(" [[[[[[[[[[[]]]]]] ", text.dup))
|
290
|
+
assert_equal(" supercalifrag- \n ilousexpali- \n doucious \n", r.format(" ||||||||||||||||| ", text.dup))
|
291
|
+
end
|
292
|
+
|
293
|
+
def test_interleave
|
294
|
+
passes = %w{ pass_1 pass_2 pass_3 }
|
295
|
+
fails = %w{ fail_1 fail_2 fail_3 }
|
296
|
+
|
297
|
+
r.interleave = true
|
298
|
+
|
299
|
+
fmt = "Passed:\n"
|
300
|
+
fmt << " [[[[[[[[[[[[[[[\n"
|
301
|
+
fmt << "Failed:\n"
|
302
|
+
fmt << " [[[[[[[[[[[[[[[\n"
|
303
|
+
|
304
|
+
str = r.format(fmt, passes, fails)
|
305
|
+
|
306
|
+
assert_equal "Passed:\n pass_1 \n pass_2 \n pass_3 \nFailed:\n fail_1 \n fail_2 \n fail_3 \n", str
|
307
|
+
end
|
308
|
+
|
309
|
+
def test_hyphenate_small
|
310
|
+
data = 'split'
|
311
|
+
s = r.format('~', data)
|
312
|
+
|
313
|
+
assert_equal "s\np\nl\ni\nt\n", s
|
314
|
+
assert_equal 0, data.length
|
315
|
+
|
316
|
+
data = 'split'
|
317
|
+
r.min_break = 1
|
318
|
+
s = r.format('~', data)
|
319
|
+
|
320
|
+
assert_equal "s-\np-\nl-\ni-\nt\n", s
|
321
|
+
assert_equal 0, data.length
|
322
|
+
end
|
323
|
+
|
324
|
+
class WrapAndSlop
|
325
|
+
def break str, initial, total
|
326
|
+
if initial==total
|
327
|
+
str =~ /\A(\s*\S*)(.*)/
|
328
|
+
return $1, $2
|
329
|
+
else
|
330
|
+
return '', str
|
331
|
+
end
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
def test_wrap_and_slop
|
336
|
+
r.break = Text::Reform.break_wrap
|
337
|
+
data = 'a looooooong word that should be wrapped and slopped'
|
338
|
+
assert_equal("a \nlooooooong\nword that\nshould be\nwrapped \nand \nslopped \n",
|
339
|
+
r.format('[[[[[[[[[', data))
|
340
|
+
|
341
|
+
r.break = WrapAndSlop.new
|
342
|
+
|
343
|
+
data = 'a looooooong word that should be wrapped and slopped'
|
344
|
+
assert_equal("a \nlooooooong\nword that\nshould be\nwrapped \nand \nslopped \n",
|
345
|
+
r.format('[[[[[[[[[', data))
|
346
|
+
end
|
347
|
+
|
348
|
+
def test_break_at_doku
|
349
|
+
r.break= Text::Reform.break_at('-')
|
350
|
+
s = r.format("[[[[[[[[[[[[[[", "The Newton-Raphson methodology")
|
351
|
+
|
352
|
+
assert_equal("The Newton- \nRaphson \nmethodology \n", s)
|
353
|
+
|
354
|
+
r.break= Text::Reform.break_with('-')
|
355
|
+
s = r.format("[[[[[[[[[[[[[[", "The Newton-Raphson methodology")
|
356
|
+
|
357
|
+
assert_equal("The Newton-Ra-\nphson methodo-\nlogy \n", s)
|
358
|
+
end
|
359
|
+
|
360
|
+
def test_number_formatting
|
361
|
+
s= r.format('(]]]]].[[)', %w{1 1.0 1.001 1.009 123.456 1234567 one two})
|
362
|
+
|
363
|
+
assert_equal("( 1.0 )\n( 1.0 )\n( 1.00)\n( 1.01)\n( 123.46)\n(#####.##)\n(?????.??)\n(?????.??)\n", s)
|
364
|
+
end
|
365
|
+
|
366
|
+
def test_num_all_places
|
367
|
+
r.numeric = Text::Reform::NUMBERS_ALL_PLACES
|
368
|
+
s = r.format('(]]]]].[[)', %w{1 1.0})
|
369
|
+
assert_equal("( 1.00)\n( 1.00)\n", s)
|
370
|
+
end
|
371
|
+
|
372
|
+
def test_skip_nan
|
373
|
+
r.numeric = Text::Reform::NUMBERS_SKIP_NAN
|
374
|
+
s= r.format('(]]]]].[[)', %w{1 two three 4})
|
375
|
+
assert_equal("( 1.0 )\n( 4.0 )\n", s)
|
376
|
+
end
|
377
|
+
|
378
|
+
def test_array
|
379
|
+
nvalues = [1, 10, 100, 1000]
|
380
|
+
svalues = %w{ 1 10 100 1000 }
|
381
|
+
|
382
|
+
assert_equal("( 1.0 )\n( 10.0 )\n( 100.0 )\n(1000.0 )\n", r.format("(]]]].[[)", nvalues))
|
383
|
+
assert_equal("( 1.0 )\n( 10.0 )\n( 100.0 )\n(1000.0 )\n", r.format("(]]]].[[)", svalues))
|
384
|
+
end
|
385
|
+
|
386
|
+
def test_pagination
|
387
|
+
small = Text::Reform.new
|
388
|
+
template = '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[['
|
389
|
+
data = <<DOLOR
|
390
|
+
Vestibulum at felis. Praesent turpis velit, elementum eget, porttitor id, bibendum auctor, metus. Ut facilisis commodo quam. Quisque nec urna ultricies justo condimentum tristique. Proin eget sem eu neque sollicitudin luctus. Etiam mi dolor, aliquet eget, pellentesque ultrices, nonummy et, diam. Sed odio enim, ultrices non, aliquam vitae, sodales sed, odio. Maecenas id justo. Quisque viverra malesuada neque. Cras auctor ipsum ac ante. Vestibulum consectetuer. Nullam mi est, pretium at, elementum at, dictum scelerisque, purus. Integer leo velit, adipiscing in, bibendum nec, euismod sit amet, quam. Sed porttitor lorem vitae neque. Maecenas sem lorem, aliquet non, vulputate vitae, consequat ornare, elit. Pellentesque nec lectus quis felis posuere pharetra.
|
391
|
+
DOLOR
|
392
|
+
r.header = lambda do |page| "Page #{page}\n\n" end
|
393
|
+
r.footer = lambda do |page, last|
|
394
|
+
if last
|
395
|
+
''
|
396
|
+
else
|
397
|
+
('-'*50 + "\n" + small.format('>'*50, "...#{page+1}"))
|
398
|
+
end
|
399
|
+
end
|
400
|
+
r.page_feed = "\n\n"
|
401
|
+
r.page_len = 10
|
402
|
+
r.page_num = 7
|
403
|
+
|
404
|
+
s = r.format(template, data.dup)
|
405
|
+
assert_equal(TEST_PAGINATION_1, s)
|
406
|
+
|
407
|
+
r.page_num = 1
|
408
|
+
r.header = { :right => 'Running head' }
|
409
|
+
r.footer = { :centre => lambda { |page| "page #{page}" } }
|
410
|
+
r.page_len = 10
|
411
|
+
|
412
|
+
assert_equal(TEST_PAGINATION_2, r.format(template, data.dup))
|
413
|
+
|
414
|
+
r.page_num = 1
|
415
|
+
r.header = { :right => 'Running head' }
|
416
|
+
r.footer = lambda do |page| { :center => "page #{page}" } end
|
417
|
+
|
418
|
+
assert_equal(TEST_PAGINATION_2, r.format(template, data.dup))
|
419
|
+
end
|
420
|
+
|
421
|
+
def test_page_width
|
422
|
+
r.page_width = 30
|
423
|
+
r.header = { :right => 'test' }
|
424
|
+
text = 'text'
|
425
|
+
|
426
|
+
assert_equal " test\ntext \n",
|
427
|
+
r.format( '[[[[[[[[[[[[[[[[[[[[[[[[[[[', text )
|
428
|
+
end
|
429
|
+
|
430
|
+
def test_cols
|
431
|
+
name = %w{Tom Dick Harry}
|
432
|
+
score = %w{ 88 54 99}
|
433
|
+
time = %w{ 15 13 18}
|
434
|
+
|
435
|
+
result = "-------------------------------\n"
|
436
|
+
result << "Name Score Time\n"
|
437
|
+
result << "-------------------------------\n"
|
438
|
+
result << "Tom 88 15 \n"
|
439
|
+
result << "Dick 54 13 \n"
|
440
|
+
result << "Harry 99 18 \n"
|
441
|
+
|
442
|
+
assert_equal(result, r.format('-------------------------------',
|
443
|
+
'Name Score Time',
|
444
|
+
'-------------------------------',
|
445
|
+
'[[[[[[[[[[[[[[ ||||| ||||',
|
446
|
+
name, score, time))
|
447
|
+
end
|
448
|
+
end
|