eideticrml 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +55 -0
  3. data/lib/erml.rb +345 -0
  4. data/lib/erml_layout_managers.rb +667 -0
  5. data/lib/erml_rules.rb +104 -0
  6. data/lib/erml_styles.rb +304 -0
  7. data/lib/erml_support.rb +105 -0
  8. data/lib/erml_widget_factories.rb +38 -0
  9. data/lib/erml_widgets.rb +1895 -0
  10. data/samples/test10_rich_text.erml +17 -0
  11. data/samples/test11_table_layout.erml +30 -0
  12. data/samples/test12_shapes.erml +32 -0
  13. data/samples/test13_polygons.erml +28 -0
  14. data/samples/test14_images.erml +19 -0
  15. data/samples/test15_lines.erml +43 -0
  16. data/samples/test16_classes.erml +34 -0
  17. data/samples/test17_rules.erml +24 -0
  18. data/samples/test18_preformatted_text.erml +9 -0
  19. data/samples/test19_erb.erml.erb +26 -0
  20. data/samples/test1_empty_doc.erml +2 -0
  21. data/samples/test20_haml.erml.haml +20 -0
  22. data/samples/test21_shift_widgets.erml +47 -0
  23. data/samples/test22_multipage_flow_layout.erml +40 -0
  24. data/samples/test23_pageno.erml +17 -0
  25. data/samples/test24_headers_footers.erml.erb +37 -0
  26. data/samples/test25_overflow.erml.erb +37 -0
  27. data/samples/test26_columns.erml.erb +42 -0
  28. data/samples/test28_landscape.erml.erb +17 -0
  29. data/samples/test29_pages_up.erml.erb +17 -0
  30. data/samples/test2_empty_page.erml +6 -0
  31. data/samples/test30_encodings.erml.haml +35 -0
  32. data/samples/test3_hello_world.erml +7 -0
  33. data/samples/test4_two_pages.erml +10 -0
  34. data/samples/test5_rounded_rect.erml +10 -0
  35. data/samples/test6_bullets.erml +16 -0
  36. data/samples/test7_flow_layout.erml +20 -0
  37. data/samples/test8_vbox_layout.erml +23 -0
  38. data/samples/test9_hbox_layout.erml +22 -0
  39. data/samples/testimg.jpg +0 -0
  40. data/test/test_erml_layout_managers.rb +106 -0
  41. data/test/test_erml_rules.rb +116 -0
  42. data/test/test_erml_styles.rb +415 -0
  43. data/test/test_erml_support.rb +140 -0
  44. data/test/test_erml_widget_factories.rb +46 -0
  45. data/test/test_erml_widgets.rb +1235 -0
  46. data/test/test_helpers.rb +18 -0
  47. metadata +102 -0
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created by Brent Rowland on 2008-01-16.
4
+ # Copyright (c) 2008 Eidetic Software. All rights reserved.
5
+
6
+ $: << File.dirname(__FILE__) + '/../'
7
+ require "minitest/autorun"
8
+ require 'erml_widgets'
9
+ require 'erml_widget_factories'
10
+
11
+ include EideticRML::Widgets
12
+
13
+ class TestWidget < Widget
14
+ end
15
+
16
+ class FactoryTestCases < Minitest::Test
17
+ def setup
18
+ @wf = WidgetFactory.new
19
+ WidgetFactory.register_factory('test', @wf)
20
+ end
21
+
22
+ def test_register_factory
23
+ assert_equal(@wf, WidgetFactory.class_eval("@@factories['test']"))
24
+ end
25
+
26
+ def test_for_namespace
27
+ assert_equal(@wf, WidgetFactory.for_namespace('test'))
28
+ end
29
+
30
+ def test_register_widget
31
+ @wf.register_widget('test_widget', TestWidget)
32
+ assert_equal(TestWidget, @wf.instance_eval("@klasses['test_widget']"))
33
+ end
34
+
35
+ def test_has_widget?
36
+ @wf.register_widget('test_widget', TestWidget)
37
+ assert(@wf.has_widget?('test_widget'))
38
+ end
39
+
40
+ def test_make_widget
41
+ @wf.register_widget('test_widget', TestWidget)
42
+ w = @wf.make_widget('test_widget', nil)
43
+ refute_nil(w)
44
+ assert(w.is_a?(TestWidget))
45
+ end
46
+ end
@@ -0,0 +1,1235 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created by Brent Rowland on 2008-01-16.
4
+ # Copyright (c) 2008 Eidetic Software. All rights reserved.
5
+
6
+ $: << File.dirname(__FILE__) + '/../'
7
+ require "minitest/autorun"
8
+ require File.join(File.dirname(__FILE__), 'test_helpers')
9
+ require 'erml_widgets'
10
+ require 'erml_styles'
11
+ require 'erml_support'
12
+
13
+ include EideticRML::Widgets
14
+ include EideticRML::Styles
15
+ include EideticRML::Support
16
+
17
+ class StdWidgetFactoryTestCases < Minitest::Test
18
+ def test_for_namespace
19
+ assert_equal(StdWidgetFactory.instance, WidgetFactory.for_namespace('std'))
20
+ end
21
+ end
22
+
23
+ class WidgetTestCases < Minitest::Test
24
+ def setup
25
+ @doc = StdWidgetFactory.instance.make_widget('erml', nil)
26
+ @alt = @doc.styles.add('font', :id => 'alt', :name => 'Times', :size => 10, :style => 'Bold', :encoding => 'CP1252', :color => '0xFFFFFF')
27
+ @blue_dash = @doc.styles.add('pen', :id => 'blue_dash', :color => 'Blue', :width => '4pt', :pattern => 'dashed')
28
+ @dotted = @doc.styles.for_id('dotted')
29
+ @battleship = @doc.styles.add('brush', :id => 'battleship', :color => 'LightSteelBlue')
30
+ @page = StdWidgetFactory.instance.make_widget('page', @doc)
31
+ @widget = Widget.new(@page)
32
+ end
33
+
34
+ def test_initialize
35
+ refute_nil(@widget)
36
+ assert_equal(@page, @widget.parent)
37
+ end
38
+
39
+ def test_align
40
+ assert_nil(@widget.align)
41
+ [:top, :right, :bottom, :left].each do |align|
42
+ @widget.align(align)
43
+ assert_equal(align, @widget.align)
44
+ end
45
+ @widget.align(:bogus)
46
+ assert_equal(:left, @widget.align) # unchanged
47
+ end
48
+
49
+ def test_position
50
+ assert_equal(:static, @widget.position)
51
+
52
+ @widget.position(:relative)
53
+ assert_equal(:relative, @widget.position)
54
+ @widget.position(:absolute)
55
+ assert_equal(:absolute, @widget.position)
56
+
57
+ @widget.position("static")
58
+ assert_equal(:static, @widget.position)
59
+ @widget.position("relative")
60
+ assert_equal(:relative, @widget.position)
61
+ @widget.position("absolute")
62
+ assert_equal(:absolute, @widget.position)
63
+ end
64
+
65
+ def test_tag
66
+ assert_nil(@widget.tag)
67
+ @widget.tag(' !@#$%')
68
+ assert_nil(@widget.tag) # unchanged
69
+ @widget.tag('widget')
70
+ assert_equal('widget', @widget.tag)
71
+ end
72
+
73
+ def test_id
74
+ assert_nil(@widget.id)
75
+ @widget.id(' !@#$%')
76
+ assert_nil(@widget.id) # unchanged
77
+ @widget.id('widget')
78
+ assert_equal('widget', @widget.id)
79
+ end
80
+
81
+ def test_klass
82
+ assert_nil(@widget.klass)
83
+ @widget.klass(' !@#$%')
84
+ assert_nil(@widget.klass) # unchanged
85
+ @widget.klass('foo bar')
86
+ assert_equal('foo bar', @widget.klass)
87
+ end
88
+
89
+ def test_selector_tag
90
+ assert_equal('erml', @doc.selector_tag)
91
+ assert_equal('page', @page.selector_tag)
92
+
93
+ p1 = StdWidgetFactory.instance.make_widget('p', @page)
94
+ assert_equal('p', p1.selector_tag)
95
+ p1.id('id')
96
+ assert_equal('p#id', p1.selector_tag)
97
+ p1.klass('class')
98
+ assert_equal('p#id.class', p1.selector_tag)
99
+
100
+ p2 = StdWidgetFactory.instance.make_widget('p', @page)
101
+ p2.klass('class')
102
+ assert_equal('p.class', p2.selector_tag)
103
+ end
104
+
105
+ def test_path
106
+ assert_equal('erml', @doc.path)
107
+ assert_equal('erml/page', @page.path)
108
+
109
+ p1 = StdWidgetFactory.instance.make_widget('p', @page)
110
+ assert_equal('erml/page/p', p1.path)
111
+ p1.id('id')
112
+ assert_equal('erml/page/p#id', p1.path)
113
+ p1.klass('class')
114
+ assert_equal('erml/page/p#id.class', p1.path)
115
+
116
+ p2 = StdWidgetFactory.instance.make_widget('p', @page)
117
+ p2.klass('class')
118
+ assert_equal('erml/page/p.class', p2.path)
119
+ end
120
+
121
+ def make_div(left, top, width, height)
122
+ div = StdWidgetFactory.instance.make_widget('div', @page)
123
+ div.position(:absolute)
124
+ div.top(top)
125
+ div.left(left)
126
+ div.width(width)
127
+ div.height(height)
128
+ div
129
+ end
130
+
131
+ def test_top
132
+ assert_equal(:static, @widget.position)
133
+
134
+ @widget.top("18")
135
+ assert_equal(18, @widget.top)
136
+ assert_equal(0.25, @widget.top(:in))
137
+ assert_equal(:relative, @widget.position)
138
+
139
+ @widget.height("7in")
140
+ assert_equal(7.25, @widget.bottom(:in))
141
+
142
+ @widget.top("-2in")
143
+ assert_equal(9, @widget.top(:in))
144
+
145
+ div = make_div("1in", "1in", "2in", "2in")
146
+ w = Widget.new(div)
147
+ w.top("0.5in")
148
+ assert_equal(108, w.top)
149
+ assert_equal(1.5, w.top(:in))
150
+ end
151
+
152
+ def test_right
153
+ assert_equal(:static, @widget.position)
154
+
155
+ @widget.right("36")
156
+ assert_equal(36, @widget.right)
157
+ assert_equal(0.5, @widget.right(:in))
158
+ assert_equal(:relative, @widget.position)
159
+
160
+ @widget.right(342)
161
+ @widget.width(1, :in)
162
+ assert_equal(4.75, @widget.right(:in))
163
+ assert_equal(3.75, @widget.left(:in))
164
+
165
+ @widget.right("-1in")
166
+ assert_equal(6.5, @widget.left(:in))
167
+
168
+ div = make_div("1in", "1in", "2in", "2in")
169
+ w = Widget.new(div)
170
+ w.right("-0.5in")
171
+ assert_equal(180, w.right)
172
+ assert_equal(2.5, w.right(:in))
173
+ end
174
+
175
+ def test_bottom
176
+ assert_equal(:static, @widget.position)
177
+
178
+ @widget.bottom("54")
179
+ assert_equal(54, @widget.bottom)
180
+ assert_equal(0.75, @widget.bottom(:in))
181
+ assert_equal(:relative, @widget.position)
182
+
183
+ @widget.height(36)
184
+ assert_equal(18, @widget.top)
185
+
186
+ @widget.bottom("-144")
187
+ @widget.height("72")
188
+ assert_equal(576, @widget.top)
189
+ assert_equal(8, @widget.top(:in))
190
+
191
+ div = make_div("1in", "1in", "2in", "2in")
192
+ w = Widget.new(div)
193
+ w.bottom("-0.5in")
194
+ assert_equal(180, w.bottom)
195
+ assert_equal(2.5, w.bottom(:in))
196
+ end
197
+
198
+ def test_left
199
+ assert_equal(:static, @widget.position)
200
+
201
+ @widget.left("72")
202
+ assert_equal(72, @widget.left)
203
+ assert_equal(1, @widget.left(:in))
204
+ assert_equal(:relative, @widget.position)
205
+
206
+ @widget.width("7in")
207
+ assert_equal(8, @widget.right(:in))
208
+
209
+ @widget.left("-2in")
210
+ assert_equal(6.5, @widget.left(:in))
211
+
212
+ div = make_div("1in", "1in", "2in", "2in")
213
+ w = Widget.new(div)
214
+ w.left("0.5in")
215
+ assert_equal(108, w.left)
216
+ assert_equal(1.5, w.left(:in))
217
+ end
218
+
219
+ def test_units
220
+ assert_equal(:pt, @doc.units)
221
+ assert_equal(:pt, @widget.units) # inherited
222
+ @widget.units(:in)
223
+ assert_equal(:in, @widget.units)
224
+ assert_equal(:pt, @doc.units) # unchanged
225
+ end
226
+
227
+ def assert_font_defaults(f)
228
+ refute_nil(f)
229
+ assert_equal('Helvetica', f.name)
230
+ assert_equal(12, f.size)
231
+ assert_equal('', f.style)
232
+ assert_equal('Type1', f.sub_type)
233
+ assert_equal('WinAnsiEncoding', f.encoding)
234
+ assert_equal(0, f.color)
235
+ end
236
+
237
+ def test_font
238
+ assert_font_defaults(@doc.font)
239
+ assert_font_defaults(@widget.font) # same as parent
240
+ @widget.font('alt')
241
+ assert_equal(@alt, @widget.font)
242
+ assert_font_defaults(@doc.font) # unchanged
243
+ end
244
+
245
+ def test_font_copy
246
+ assert_font_defaults(@doc.font)
247
+ assert_font_defaults(@widget.font) # same as parent
248
+ @widget.font(:copy).size(20)
249
+ assert_equal(20, @widget.font.size)
250
+ refute_equal(@alt, @widget.font)
251
+ assert_font_defaults(@doc.font) # unchanged
252
+ end
253
+
254
+ def test_font_style
255
+ @widget.font_style('Italic')
256
+ assert_equal('Italic', @widget.font.style)
257
+ assert_font_defaults(@doc.font) # unchanged
258
+ end
259
+
260
+ def test_font_color
261
+ @widget.font_color('Orange')
262
+ assert_equal('Orange', @widget.font.color)
263
+ assert_font_defaults(@doc.font) # unchanged
264
+ end
265
+
266
+ def test_font_size
267
+ @widget.font_size(13)
268
+ assert_equal(13, @widget.font.size)
269
+ assert_font_defaults(@doc.font) # unchanged
270
+ end
271
+
272
+ def test_font_weight
273
+ @widget.font_weight('Bold')
274
+ assert_equal('Bold', @widget.font_weight)
275
+ assert_font_defaults(@doc.font) # unchanged
276
+ end
277
+
278
+ def test_width_fixed
279
+ @page.units(:in)
280
+ assert_nil(@widget.width)
281
+ @widget.width('5')
282
+ assert_equal(5, @widget.width(:in))
283
+ assert_equal(360, @widget.width)
284
+ end
285
+
286
+ def test_width_percent
287
+ @page.units(:in)
288
+ assert_nil(@widget.width)
289
+ @widget.width('50%')
290
+ assert_equal(0.5, @widget.width_pct)
291
+ assert_equal(4.25, @widget.width(:in))
292
+ assert_equal(306, @widget.width)
293
+
294
+ w = Widget.new(@widget)
295
+ w.width('50%')
296
+ assert_equal(0.5, w.width_pct)
297
+ assert_equal(2.125, w.width(:in))
298
+ assert_equal(153, w.width)
299
+
300
+ # child with percent width should resize along with parent
301
+ @widget.width('100%')
302
+ assert_equal(0.5, w.width_pct)
303
+ assert_equal(4.25, w.width(:in))
304
+ assert_equal(306, w.width)
305
+ end
306
+
307
+ def test_width_relative
308
+ @page.margin('1in')
309
+ assert_nil(@widget.width)
310
+ @widget.width('-2in')
311
+ assert_equal(4.5, @widget.width(:in))
312
+ assert_equal(324, @widget.width)
313
+ @widget.width('+1in')
314
+ assert_equal(7.5, @widget.width(:in))
315
+ assert_equal(540, @widget.width)
316
+ end
317
+
318
+ def test_height_fixed
319
+ @page.units(:in)
320
+ assert_nil(@widget.height)
321
+ @widget.height('3.5')
322
+ assert_equal(3.5, @widget.height(:in))
323
+ assert_equal(252, @widget.height)
324
+ end
325
+
326
+ def test_height_percent
327
+ @page.units(:in)
328
+ assert_nil(@widget.height)
329
+ @widget.height('50%')
330
+ assert_equal(0.5, @widget.height_pct)
331
+ assert_equal(5.5, @widget.height(:in))
332
+ assert_equal(396, @widget.height)
333
+
334
+ w = Widget.new(@widget)
335
+ w.height('50%')
336
+ assert_equal(0.5, w.height_pct)
337
+ assert_equal(2.75, w.height(:in))
338
+ assert_equal(198, w.height)
339
+
340
+ # child with percent height should resize along with parent
341
+ @widget.height('100%')
342
+ assert_equal(0.5, w.height_pct)
343
+ assert_equal(5.5, w.height(:in))
344
+ assert_equal(396, w.height)
345
+ end
346
+
347
+ def test_height_relative
348
+ @page.margin('1in')
349
+ assert_nil(@widget.height)
350
+ @widget.height('-2in')
351
+ assert_equal(7, @widget.height(:in))
352
+ assert_equal(504, @widget.height)
353
+ @widget.height('+1in')
354
+ assert_equal(10, @widget.height(:in))
355
+ assert_equal(720, @widget.height)
356
+ end
357
+
358
+ def test_max_width_fixed
359
+ @page.units(:in)
360
+ assert_nil(@widget.max_width)
361
+ @widget.max_width('5')
362
+ assert_equal(5, @widget.max_width(:in))
363
+ assert_equal(360, @widget.max_width)
364
+ end
365
+
366
+ def test_max_width_percent
367
+ @page.units(:in)
368
+ assert_nil(@widget.max_width)
369
+ @widget.max_width('50%')
370
+ assert_equal(0.5, @widget.max_width_pct)
371
+ assert_equal(4.25, @widget.max_width(:in))
372
+ assert_equal(306, @widget.max_width)
373
+
374
+ @widget.width('50%')
375
+ w = Widget.new(@widget)
376
+ w.max_width('50%')
377
+ assert_equal(0.5, w.max_width_pct)
378
+ assert_equal(2.125, w.max_width(:in))
379
+ assert_equal(153, w.max_width)
380
+
381
+ # child with percent max_width should resize along with parent
382
+ @widget.width('100%')
383
+ assert_equal(0.5, w.max_width_pct)
384
+ assert_equal(4.25, w.max_width(:in))
385
+ assert_equal(306, w.max_width)
386
+ end
387
+
388
+ def test_max_width_relative
389
+ @page.margin('1in')
390
+ assert_nil(@widget.max_width)
391
+ @widget.max_width('-2in')
392
+ assert_equal(4.5, @widget.max_width(:in))
393
+ assert_equal(324, @widget.max_width)
394
+ @widget.max_width('+1in')
395
+ assert_equal(7.5, @widget.max_width(:in))
396
+ assert_equal(540, @widget.max_width)
397
+ end
398
+
399
+ def test_max_height_fixed
400
+ @page.units(:in)
401
+ assert_nil(@widget.max_height)
402
+ @widget.max_height('3.5')
403
+ assert_equal(3.5, @widget.max_height(:in))
404
+ assert_equal(252, @widget.max_height)
405
+ end
406
+
407
+ def test_max_height_percent
408
+ @page.units(:in)
409
+ assert_nil(@widget.max_height)
410
+ @widget.max_height('50%')
411
+ assert_equal(0.5, @widget.max_height_pct)
412
+ assert_equal(5.5, @widget.max_height(:in))
413
+ assert_equal(396, @widget.max_height)
414
+
415
+ @widget.height('50%')
416
+ w = Widget.new(@widget)
417
+ w.max_height('50%')
418
+ assert_equal(0.5, w.max_height_pct)
419
+ assert_equal(2.75, w.max_height(:in))
420
+ assert_equal(198, w.max_height)
421
+
422
+ # child with percent max_height should resize along with parent
423
+ @widget.height('100%')
424
+ assert_equal(0.5, w.max_height_pct)
425
+ assert_equal(5.5, w.max_height(:in))
426
+ assert_equal(396, w.max_height)
427
+ end
428
+
429
+ def test_max_height_relative
430
+ @page.margin('1in')
431
+ assert_nil(@widget.max_height)
432
+ @widget.max_height('-2in')
433
+ assert_equal(7, @widget.max_height(:in))
434
+ assert_equal(504, @widget.max_height)
435
+ @widget.max_height('+1in')
436
+ assert_equal(10, @widget.max_height(:in))
437
+ assert_equal(720, @widget.max_height)
438
+ end
439
+
440
+ def test_content_top
441
+ @widget.top(50)
442
+ assert_equal(50, @widget.content_top)
443
+ @widget.padding(10)
444
+ assert_equal(60, @widget.content_top)
445
+ @widget.margin(5)
446
+ assert_equal(65, @widget.content_top)
447
+ end
448
+
449
+ def test_content_right
450
+ @widget.right(50)
451
+ assert_equal(50, @widget.content_right)
452
+ @widget.padding(10)
453
+ assert_equal(40, @widget.content_right)
454
+ @widget.margin(5)
455
+ assert_equal(35, @widget.content_right)
456
+ end
457
+
458
+ def test_content_bottom
459
+ @widget.bottom(50)
460
+ assert_equal(50, @widget.content_bottom)
461
+ @widget.padding(10)
462
+ assert_equal(40, @widget.content_bottom)
463
+ @widget.margin(5)
464
+ assert_equal(35, @widget.content_bottom)
465
+ end
466
+
467
+ def test_content_left
468
+ @widget.left(50)
469
+ assert_equal(50, @widget.content_left)
470
+ @widget.padding(10)
471
+ assert_equal(60, @widget.content_left)
472
+ @widget.margin(5)
473
+ assert_equal(65, @widget.content_left)
474
+ end
475
+
476
+ def test_content_width
477
+ assert_equal(0, @widget.content_width)
478
+ @widget.width('36')
479
+ assert_equal(36, @widget.content_width) # same as width unless overridden
480
+ assert_equal(0.5, @widget.content_width(:in)) # in specified units
481
+ @widget.margin([1,2,3,4])
482
+ assert_equal(30, @widget.content_width)
483
+ @widget.padding([4,3,2,1])
484
+ assert_equal(26, @widget.content_width)
485
+ end
486
+
487
+ def test_content_height
488
+ # assert_nil(instance)
489
+ assert_equal(0, @widget.content_height)
490
+ @widget.height('3.5in')
491
+ assert_equal(252, @widget.content_height) # same as height unless overridden
492
+ assert_equal(3.5, @widget.content_height(:in)) # in specified units
493
+ @widget.margin([1,2,3,4])
494
+ assert_equal(248, @widget.content_height)
495
+ @widget.padding([4,3,2,1])
496
+ assert_equal(242, @widget.content_height)
497
+ end
498
+
499
+ def test_border
500
+ assert_nil(@widget.border)
501
+ @widget.border('blue_dash')
502
+ refute_nil(@widget.border)
503
+ assert_equal('blue_dash', @widget.border.id)
504
+ assert_equal('Blue', @widget.border.color)
505
+ assert_equal(4, @widget.border.width)
506
+ assert_equal(:pt, @widget.border.units)
507
+ end
508
+
509
+ def test_border_top
510
+ assert_nil(@widget.border_top)
511
+ @widget.border_top('blue_dash')
512
+ assert_equal(@blue_dash, @widget.border_top)
513
+ @widget.border('dotted')
514
+ assert_equal(@dotted, @widget.border_top)
515
+ end
516
+
517
+ def test_border_right
518
+ assert_nil(@widget.border_right)
519
+ @widget.border_right('blue_dash')
520
+ assert_equal(@blue_dash, @widget.border_right)
521
+ @widget.border('dotted')
522
+ assert_equal(@dotted, @widget.border_right)
523
+ end
524
+
525
+ def test_border_bottom
526
+ assert_nil(@widget.border_bottom)
527
+ @widget.border_bottom('blue_dash')
528
+ assert_equal(@blue_dash, @widget.border_bottom)
529
+ @widget.border('dotted')
530
+ assert_equal(@dotted, @widget.border_bottom)
531
+ end
532
+
533
+ def test_border_left
534
+ assert_nil(@widget.border_left)
535
+ @widget.border_left('blue_dash')
536
+ assert_equal(@blue_dash, @widget.border_left)
537
+ @widget.border('dotted')
538
+ assert_equal(@dotted, @widget.border_left)
539
+ end
540
+
541
+ def test_margin
542
+ assert_equal(0, @widget.margin_top)
543
+ assert_equal(0, @widget.margin_right)
544
+ assert_equal(0, @widget.margin_bottom)
545
+ assert_equal(0, @widget.margin_left)
546
+
547
+ @widget.margin('1in')
548
+ assert_equal(1, @widget.margin_top(:in))
549
+ assert_equal(1, @widget.margin_right(:in))
550
+ assert_equal(1, @widget.margin_bottom(:in))
551
+ assert_equal(1, @widget.margin_left(:in))
552
+
553
+ assert_equal(72, @widget.margin_top)
554
+ assert_equal(72, @widget.margin_right)
555
+ assert_equal(72, @widget.margin_bottom)
556
+ assert_equal(72, @widget.margin_left)
557
+
558
+ @widget.margin('1cm,2cm')
559
+ assert_equal(1, @widget.margin_top(:cm))
560
+ assert_equal(2, @widget.margin_right(:cm))
561
+ assert_equal(1, @widget.margin_bottom(:cm))
562
+ assert_equal(2, @widget.margin_left(:cm))
563
+
564
+ assert_equal(28.35, @widget.margin_top)
565
+ assert_equal(56.7, @widget.margin_right)
566
+ assert_equal(28.35, @widget.margin_bottom)
567
+ assert_equal(56.7, @widget.margin_left)
568
+
569
+ @widget.margin('1in,2cm,3cm,4pt')
570
+ assert_equal(1, @widget.margin_top(:in))
571
+ assert_equal(2, @widget.margin_right(:cm))
572
+ assert_close(3, @widget.margin_bottom(:cm))
573
+ assert_equal(4, @widget.margin_left(:pt))
574
+
575
+ assert_equal(72, @widget.margin_top)
576
+ assert_equal(56.7, @widget.margin_right)
577
+ assert_close(85.05, @widget.margin_bottom)
578
+ assert_equal(4, @widget.margin_left)
579
+ end
580
+
581
+ def test_margin_numeric
582
+ @page.units(:in)
583
+ @widget.margin(1)
584
+ assert_equal([1,1,1,1], @widget.margin(:in))
585
+ assert_equal([72,72,72,72], @widget.margin)
586
+ end
587
+
588
+ def test_padding
589
+ assert_equal(0, @widget.padding_top)
590
+ assert_equal(0, @widget.padding_right)
591
+ assert_equal(0, @widget.padding_bottom)
592
+ assert_equal(0, @widget.padding_left)
593
+
594
+ @widget.padding('1in')
595
+ assert_equal(1, @widget.padding_top(:in))
596
+ assert_equal(1, @widget.padding_right(:in))
597
+ assert_equal(1, @widget.padding_bottom(:in))
598
+ assert_equal(1, @widget.padding_left(:in))
599
+
600
+ assert_equal(72, @widget.padding_top)
601
+ assert_equal(72, @widget.padding_right)
602
+ assert_equal(72, @widget.padding_bottom)
603
+ assert_equal(72, @widget.padding_left)
604
+
605
+ @widget.padding('1cm,2cm')
606
+ assert_equal(1, @widget.padding_top(:cm))
607
+ assert_equal(2, @widget.padding_right(:cm))
608
+ assert_equal(1, @widget.padding_bottom(:cm))
609
+ assert_equal(2, @widget.padding_left(:cm))
610
+
611
+ assert_equal(28.35, @widget.padding_top)
612
+ assert_equal(56.7, @widget.padding_right)
613
+ assert_equal(28.35, @widget.padding_bottom)
614
+ assert_equal(56.7, @widget.padding_left)
615
+
616
+ @widget.padding('1in,2cm,3cm,4pt')
617
+ assert_equal(1, @widget.padding_top(:in))
618
+ assert_equal(2, @widget.padding_right(:cm))
619
+ assert_close(3, @widget.padding_bottom(:cm))
620
+ assert_equal(4, @widget.padding_left(:pt))
621
+
622
+ assert_equal(72, @widget.padding_top)
623
+ assert_equal(56.7, @widget.padding_right)
624
+ assert_close(85.05, @widget.padding_bottom)
625
+ assert_equal(4, @widget.padding_left)
626
+ end
627
+
628
+ def test_padding_numeric
629
+ @page.units(:in)
630
+ @widget.padding(1)
631
+ assert_equal([1,1,1,1], @widget.padding(:in))
632
+ assert_equal([72,72,72,72], @widget.padding)
633
+ end
634
+
635
+ def test_colspan
636
+ assert_equal(1, @widget.colspan)
637
+ @widget.colspan(0)
638
+ assert_equal(1, @widget.colspan) # unchanged
639
+ @widget.colspan(2)
640
+ assert_equal(2, @widget.colspan)
641
+ @widget.colspan('3')
642
+ assert_equal(3, @widget.colspan)
643
+ end
644
+
645
+ def test_rowspan
646
+ assert_equal(1, @widget.rowspan)
647
+ @widget.rowspan(0)
648
+ assert_equal(1, @widget.rowspan) # unchanged
649
+ @widget.rowspan(2)
650
+ assert_equal(2, @widget.rowspan)
651
+ @widget.rowspan('3')
652
+ assert_equal(3, @widget.rowspan)
653
+ end
654
+
655
+ def test_fill
656
+ assert_nil(@widget.fill)
657
+ @widget.fill('battleship')
658
+ refute_nil(@widget.fill)
659
+ assert_equal('battleship', @widget.fill.id)
660
+ assert_equal('LightSteelBlue', @widget.fill.color)
661
+ end
662
+
663
+ def test_rotate
664
+ assert_nil(@widget.rotate)
665
+ @widget.rotate("45")
666
+ assert_equal(45, @widget.rotate)
667
+ end
668
+
669
+ def test_origin_x
670
+ assert_nil(@widget.origin_x)
671
+ @widget.left(15)
672
+ @widget.width(10)
673
+ assert_equal(15, @widget.origin_x)
674
+ @widget.origin_x('center')
675
+ assert_equal(20, @widget.origin_x)
676
+ @widget.origin_x('right')
677
+ assert_equal(25, @widget.origin_x)
678
+ end
679
+
680
+ def test_origin_y
681
+ assert_nil(@widget.origin_y)
682
+ @widget.top(15)
683
+ @widget.height(10)
684
+ assert_equal(15, @widget.origin_y)
685
+ @widget.origin_y('middle')
686
+ assert_equal(20, @widget.origin_y)
687
+ @widget.origin_y('bottom')
688
+ assert_equal(25, @widget.origin_y)
689
+ end
690
+
691
+ def test_printed
692
+ @writer = EideticPDF::DocumentWriter.new
693
+ @writer.open
694
+ assert(!@widget.printed)
695
+ @widget.print(@writer)
696
+ assert(@widget.printed)
697
+ @writer.close
698
+ end
699
+
700
+ def test_display
701
+ assert_equal(:once, @widget.display)
702
+ [:always, :first, :succeeding, :even, :odd, :once].each do |v|
703
+ @widget.display(v)
704
+ assert_equal(v, @widget.display)
705
+ end
706
+ [:always, :first, :succeeding, :even, :odd, :once].each do |v|
707
+ @widget.display(v.to_s)
708
+ assert_equal(v, @widget.display)
709
+ end
710
+ @widget.display('bogus')
711
+ assert_equal(:once, @widget.display) # unchanged
712
+ end
713
+
714
+ def test_widget_for
715
+ w1 = Widget.new(@page)
716
+ w1.id('w1')
717
+ w2 = Widget.new(@page)
718
+ w2.id('w2')
719
+ assert_nil(@widget.send(:widget_for, 'bogus'))
720
+ assert_equal(w1, @widget.send(:widget_for, 'w1'))
721
+ assert_equal(w2, @widget.send(:widget_for, 'w2'))
722
+ end
723
+
724
+ def test_max_content_height
725
+ assert_equal(792, @page.height)
726
+ assert_equal(792, @page.content_height)
727
+ assert_equal(792, @page.max_content_height)
728
+ assert_equal(792, @widget.max_content_height)
729
+
730
+ @page.margin(50)
731
+ @page.padding(50)
732
+ assert_equal(792, @page.height)
733
+ assert_equal(592, @page.content_height)
734
+ assert_equal(592, @page.max_content_height)
735
+ assert_equal(592, @widget.max_content_height)
736
+
737
+ @widget.margin(50)
738
+ @widget.padding(50)
739
+ assert_equal(392, @widget.max_content_height)
740
+ end
741
+
742
+ def test_max_height_avail
743
+ assert_equal(792, @page.max_height_avail)
744
+ assert_equal(792, @widget.max_height_avail)
745
+
746
+ @page.margin(50)
747
+ @page.padding(50)
748
+ assert_equal(592, @widget.max_height_avail)
749
+
750
+ @widget.top(@page.content_top + 100)
751
+ assert_equal(492, @widget.max_height_avail)
752
+ end
753
+
754
+ def test_visible
755
+ b = Bounds.new(1,1,7.5,10)
756
+ assert_equal 0, @widget.visible(b)
757
+ @widget.left 0
758
+ @widget.top 0
759
+ @widget.right 8.5
760
+ @widget.bottom 11
761
+ assert_equal 0, @widget.visible(b)
762
+ @widget.left 1
763
+ @widget.top 1
764
+ @widget.right 7.5
765
+ @widget.bottom 10
766
+ assert_equal 1, @widget.visible(b)
767
+ @widget.left 2
768
+ @widget.top 2
769
+ assert_equal 1, @widget.visible(b)
770
+ @widget.right 6
771
+ @widget.bottom 8
772
+ assert_equal 1, @widget.visible(b)
773
+ @widget.left 0.5
774
+ assert_equal 0, @widget.visible(b)
775
+ end
776
+
777
+ # def test_postpone
778
+ # assert !@widget.disabled
779
+ # assert !@widget.printed
780
+ # @widget.postpone
781
+ # # nothing happens the first time
782
+ # assert !@widget.disabled
783
+ # assert !@widget.printed
784
+ # @widget.postpone
785
+ # # widget is marked disabled (and therefore "printed") after the second postponement
786
+ # assert @widget.disabled
787
+ # assert @widget.printed
788
+ # end
789
+
790
+ def test_right_should_change_width
791
+ @widget.left 1
792
+ @widget.width 4
793
+ assert_equal 5, @widget.right
794
+ @widget.right 8
795
+ assert_equal 7, @widget.width
796
+ end
797
+
798
+ def test_left_should_change_width
799
+ @widget.right 8
800
+ @widget.width 4
801
+ assert_equal 4, @widget.left
802
+ @widget.left 1
803
+ assert_equal 7, @widget.width
804
+ end
805
+
806
+ def test_bottom_should_change_height
807
+ @widget.top 1
808
+ @widget.height 4
809
+ assert_equal 5, @widget.bottom
810
+ @widget.bottom 10
811
+ assert_equal 9, @widget.height
812
+ end
813
+
814
+ def test_top_should_change_height
815
+ @widget.bottom 10
816
+ @widget.height 4
817
+ assert_equal 6, @widget.top
818
+ @widget.top 1
819
+ assert_equal 9, @widget.height
820
+ end
821
+
822
+ def test_width_should_change_right
823
+ @widget.left 1
824
+ @widget.right 5
825
+ assert_equal 4, @widget.width
826
+ @widget.width 7
827
+ assert_equal 8, @widget.right
828
+ end
829
+
830
+ def test_height_should_change_bottom
831
+ @widget.top 1
832
+ @widget.bottom 5
833
+ assert_equal 4, @widget.height
834
+ @widget.height 9
835
+ assert_equal 10, @widget.bottom
836
+ end
837
+
838
+ def test_leaf?
839
+ assert @widget.leaf?
840
+ c = Container.new(@page)
841
+ assert c.leaf?
842
+ w = Widget.new(c)
843
+ assert !c.leaf?
844
+ end
845
+ end
846
+
847
+ class RectangleTestCases < Minitest::Test
848
+ def setup
849
+ page = Page.new(nil, :units => :pt)
850
+ @rect = Rectangle.new(page)
851
+ @rect1 = Rectangle.new(page, :corners => '1')
852
+ @rect2 = Rectangle.new(page, :corners => '1,2')
853
+ @rect3 = Rectangle.new(page, :corners => '1,2,3')
854
+ @rect4 = Rectangle.new(page, :corners => '1,2,3,4')
855
+ @rect8 = Rectangle.new(page, :corners => '1,2,3,4,5,6,7,8')
856
+ end
857
+
858
+ def test_corners
859
+ assert_nil(@rect.corners)
860
+ assert_equal([1], @rect1.corners)
861
+ assert_equal([1,2], @rect2.corners)
862
+ assert_nil(@rect3.corners) # ignores invalid number of corners
863
+ assert_equal([1,2,3,4], @rect4.corners)
864
+ assert_equal([1,2,3,4,5,6,7,8], @rect8.corners)
865
+ end
866
+ end
867
+
868
+ class LabelTestCases < Minitest::Test
869
+ def setup
870
+ @doc = StdWidgetFactory.instance.make_widget('erml', nil)
871
+ @label = StdWidgetFactory.instance.make_widget('label', @doc)
872
+ end
873
+
874
+ def test_make_widget
875
+ refute_nil(@label)
876
+ assert(@label.is_a?(Label))
877
+ end
878
+
879
+ def test_angle
880
+ assert_equal(0, @label.angle)
881
+ @label.angle(90)
882
+ assert_equal(90, @label.angle)
883
+ end
884
+
885
+ def test_text
886
+ assert_equal('', @label.text)
887
+ @label.text("text")
888
+ assert_equal("text", @label.text)
889
+ end
890
+ end
891
+
892
+ class ParagraphTestCases < Minitest::Test
893
+ Lorem = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
894
+
895
+ def setup
896
+ @doc = StdWidgetFactory.instance.make_widget('erml', nil)
897
+ @centered = @doc.styles.add('para', :id => 'centered', :text_align => :center)
898
+ @zapf = @doc.styles.add('font', :id => 'zapf', :name => 'ZapfDingbats', :size => 12)
899
+ @bullet = @doc.styles.add('bullet', :id => 'bstar', :font => 'zapf', :text => "&#x4E;")
900
+ @page = StdWidgetFactory.instance.make_widget('page', @doc)
901
+ @p = StdWidgetFactory.instance.make_widget('p', @page)
902
+ @writer = EideticPDF::DocumentWriter.new
903
+ @writer.open
904
+ end
905
+
906
+ def teardown
907
+ @writer.close
908
+ end
909
+
910
+ def test_make_widget
911
+ assert_kind_of(Paragraph, @p)
912
+ assert_equal(@page, @p.parent)
913
+ assert_equal('p', @p.tag)
914
+ end
915
+
916
+ def test_bullet
917
+ assert_nil(@p.bullet)
918
+ @p.bullet('bstar')
919
+ assert_equal(@bullet, @p.bullet)
920
+ assert_equal(36, @p.bullet.width)
921
+ assert_equal(0.5, @p.bullet.width(:in))
922
+ end
923
+
924
+ def assert_paragraph_defaults(ps)
925
+ assert_equal(:left, ps.text_align)
926
+ assert_nil(ps.bullet)
927
+ end
928
+
929
+ def test_style
930
+ assert_paragraph_defaults(@doc.paragraph_style)
931
+ assert_paragraph_defaults(@p.style)
932
+ assert_equal(:left, @p.text_align)
933
+ @p.style('centered')
934
+ assert_equal(@centered, @p.style)
935
+ assert_equal(:center, @p.text_align)
936
+ assert_paragraph_defaults(@doc.paragraph_style)
937
+ end
938
+
939
+ def test_style_copy
940
+ assert_paragraph_defaults(@doc.paragraph_style)
941
+ assert_paragraph_defaults(@p.style)
942
+ @p.style(:copy).text_align('right')
943
+ refute_equal(@centered, @p.style)
944
+ assert_equal(:right, @p.text_align)
945
+ assert_paragraph_defaults(@doc.paragraph_style)
946
+ end
947
+
948
+ def test_preferred_width
949
+ @page.margin("1in")
950
+ @p.text(Lorem)
951
+ pw = @p.preferred_width(@writer, :in)
952
+ assert(pw <= 8.5, "Width is #{pw}. Should be <= 8.5.")
953
+ assert(pw >= 8.0, "Width is #{pw}. Should be >= 8.0.")
954
+ end
955
+
956
+ def test_preferred_height_small
957
+ @p.text("Hello")
958
+ ph = @p.preferred_height(@writer)
959
+ assert_in_delta(12, ph, 1)
960
+ end
961
+
962
+ def test_preferred_height_large
963
+ @page.margin("1in")
964
+ @p.text(Lorem)
965
+ ph = @p.preferred_height(@writer)
966
+ assert_in_delta(105.45, ph, 1)
967
+ end
968
+
969
+ def test_strikeout
970
+ assert(!@p.strikeout)
971
+ @p.strikeout(true)
972
+ assert(@p.strikeout)
973
+ @p.strikeout(false)
974
+ assert(!@p.strikeout)
975
+ @p.strikeout("true")
976
+ assert(@p.strikeout)
977
+ @p.strikeout("false")
978
+ assert(!@p.strikeout)
979
+ end
980
+
981
+ def test_text
982
+ assert_nil(@p.text)
983
+ # assert_equal('', @p.text)
984
+ @p.text("text")
985
+ assert_equal(["text", @p.font], @p.text.first)
986
+ end
987
+
988
+ def test_underline
989
+ assert(!@p.underline)
990
+ @p.underline(true)
991
+ assert(@p.underline)
992
+ @p.underline(false)
993
+ assert(!@p.underline)
994
+ @p.underline("true")
995
+ assert(@p.underline)
996
+ @p.underline("false")
997
+ assert(!@p.underline)
998
+ end
999
+ end
1000
+
1001
+ class ContainerTestCases < Minitest::Test
1002
+ def setup
1003
+ @doc = StdWidgetFactory.instance.make_widget('erml', nil)
1004
+ @page = StdWidgetFactory.instance.make_widget('page', @doc)
1005
+ @centered = @doc.styles.add('para', :id => 'centered', :text_align => :center)
1006
+ @page.paragraph_style('centered')
1007
+ @div = StdWidgetFactory.instance.make_widget('div', @page)
1008
+ end
1009
+
1010
+ def test_make_widget
1011
+ assert_equal(@page, @div.parent)
1012
+ assert_equal([0, 0, 0, 0], @div.margin)
1013
+ end
1014
+
1015
+ def test_cols
1016
+ assert_nil(@div.cols)
1017
+ @div.cols(0)
1018
+ assert_nil(@div.cols) # unchanged
1019
+ @div.cols(3)
1020
+ assert_equal(3, @div.cols)
1021
+ @div.cols('5')
1022
+ assert_equal(5, @div.cols)
1023
+ end
1024
+
1025
+ def test_order
1026
+ assert_equal(:rows, @div.order)
1027
+ @div.order(:cols)
1028
+ assert_equal(:cols, @div.order)
1029
+ @div.order(:rows)
1030
+ assert_equal(:rows, @div.order)
1031
+ @div.order('cols')
1032
+ assert_equal(:cols, @div.order)
1033
+ @div.order('rows')
1034
+ assert_equal(:rows, @div.order)
1035
+ @div.order('bogus')
1036
+ assert_equal(:rows, @div.order) # unchanged
1037
+ end
1038
+
1039
+ def test_paragraph_style
1040
+ assert_equal(:center, @div.paragraph_style.text_align)
1041
+ end
1042
+
1043
+ def test_rows
1044
+ assert_nil(@div.rows)
1045
+ @div.rows(0)
1046
+ assert_nil(@div.rows) # unchanged
1047
+ @div.rows(3)
1048
+ assert_equal(3, @div.rows)
1049
+ @div.rows('5')
1050
+ assert_equal(5, @div.rows)
1051
+ end
1052
+
1053
+ def test_overflow
1054
+ assert(!@div.overflow)
1055
+ @div.overflow(true)
1056
+ assert(@div.overflow)
1057
+ @div.overflow(false)
1058
+ assert(!@div.overflow)
1059
+ @div.overflow("true")
1060
+ assert(@div.overflow)
1061
+ @div.overflow("false")
1062
+ assert(!@div.overflow)
1063
+ end
1064
+
1065
+ def test_printed
1066
+ assert(!@div.printed)
1067
+ @doc.to_s
1068
+ assert(@div.printed)
1069
+ end
1070
+
1071
+ def test_printed2
1072
+ p = StdWidgetFactory.instance.make_widget('p', @div)
1073
+ p.text "Hello"
1074
+ s = StdWidgetFactory.instance.make_widget('span', p)
1075
+ s.text "World"
1076
+ assert(!@div.printed)
1077
+ assert(!p.printed)
1078
+ @doc.to_s
1079
+ assert(@div.printed)
1080
+ assert(p.printed)
1081
+ end
1082
+
1083
+ def test_source
1084
+ l1 = StdWidgetFactory.instance.make_widget('label', @div)
1085
+ l2 = StdWidgetFactory.instance.make_widget('label', @div)
1086
+ @div.id('d1')
1087
+ d2 = StdWidgetFactory.instance.make_widget('div', @page)
1088
+ d2.source('d1')
1089
+ assert_equal(@div.children, d2.children)
1090
+ end
1091
+ end
1092
+
1093
+ class PageTestCases < Minitest::Test
1094
+ def setup
1095
+ @doc = StdWidgetFactory.instance.make_widget('erml', nil)
1096
+ @doc.units('in')
1097
+ @legalland = @doc.styles.add('page', :id => 'legalland', :orientation => 'landscape', :size => 'legal')
1098
+ @page = StdWidgetFactory.instance.make_widget('page', @doc)
1099
+ end
1100
+
1101
+ def test_make_widget
1102
+ refute_nil(@page)
1103
+ assert(@page.is_a?(Page))
1104
+ assert_equal(@doc, @page.parent)
1105
+ end
1106
+
1107
+ def test_margin
1108
+ assert_equal([0,0,0,0], @doc.margin)
1109
+ assert_equal([0,0,0,0], @page.margin) # inherited
1110
+
1111
+ @doc.margin('1')
1112
+ assert_equal([72,72,72,72], @doc.margin) # in points
1113
+ assert_equal(72, @doc.margin_top)
1114
+ assert_equal(72, @doc.margin_right)
1115
+ assert_equal(72, @doc.margin_bottom)
1116
+ assert_equal(72, @doc.margin_left)
1117
+
1118
+ assert_equal([1,1,1,1], @doc.margin(:in)) # in specified units
1119
+ assert_equal(1, @doc.margin_top(:in))
1120
+ assert_equal(1, @doc.margin_right(:in))
1121
+ assert_equal(1, @doc.margin_bottom(:in))
1122
+ assert_equal(1, @doc.margin_left(:in))
1123
+
1124
+ assert_equal([72,72,72,72], @page.margin) # inherited, in points
1125
+ assert_equal(72, @page.margin_top)
1126
+ assert_equal(72, @page.margin_right)
1127
+ assert_equal(72, @page.margin_bottom)
1128
+ assert_equal(72, @page.margin_left)
1129
+
1130
+ assert_equal([1,1,1,1], @page.margin(:in)) # inherited, in specified units
1131
+ assert_equal(1, @page.margin_top(:in))
1132
+ assert_equal(1, @page.margin_right(:in))
1133
+ assert_equal(1, @page.margin_bottom(:in))
1134
+ assert_equal(1, @page.margin_left(:in))
1135
+
1136
+ @page.margin('2')
1137
+ assert_equal([144,144,144,144], @page.margin) # in points
1138
+ assert_equal([2,2,2,2], @page.margin(:in)) # in specified units
1139
+
1140
+ assert_equal([1,1,1,1], @doc.margin(:in)) # unchanged
1141
+ end
1142
+
1143
+ def test_margin2
1144
+ doc = Document.new
1145
+ page = Page.new(doc, :margin => '1') # initialize margin in constructor
1146
+ assert_equal([1,1,1,1], page.margin)
1147
+ end
1148
+
1149
+ def test_style
1150
+ assert_equal(:portrait, @page.style.orientation)
1151
+ assert_equal(:letter, @page.style.size)
1152
+ @page.style('legalland')
1153
+ assert_equal(:landscape, @page.style.orientation)
1154
+ assert_equal(:legal, @page.style.size)
1155
+ end
1156
+
1157
+ def test_style_copy
1158
+ assert_equal(:portrait, @page.style.orientation)
1159
+ assert_equal(:letter, @page.style.size)
1160
+ default_style = @page.style
1161
+ @page.style(:copy).orientation('landscape')
1162
+ refute_equal(default_style, @page.style)
1163
+ assert_equal(:landscape, @page.style.orientation) # changed
1164
+ assert_equal(:letter, @page.style.size) # unchanged
1165
+ end
1166
+
1167
+ def test_width
1168
+ assert_equal(8.5, @page.width(:in))
1169
+ @page.style('legalland')
1170
+ assert_equal(14, @page.width(:in))
1171
+ end
1172
+
1173
+ def test_height
1174
+ assert_equal(11, @page.height(:in))
1175
+ @page.style('legalland')
1176
+ assert_equal(8.5, @page.height(:in))
1177
+ end
1178
+
1179
+ def test_orientation
1180
+ assert_equal(:portrait, @page.orientation) # default
1181
+ @doc.orientation(:landscape)
1182
+ assert_equal(:landscape, @page.orientation) # inherited
1183
+ @doc.orientation(:portrait)
1184
+ assert_equal(:portrait, @page.orientation) # inherited
1185
+ @page.orientation(:landscape)
1186
+ assert_equal(:landscape, @page.orientation) # overridden
1187
+ @page.orientation(:portrait)
1188
+ assert_equal(:portrait, @page.orientation) # overridden
1189
+ end
1190
+
1191
+ def test_size
1192
+ assert_equal(:letter, @page.size) # default
1193
+ @doc.size(:legal)
1194
+ assert_equal(:legal, @page.size) # inherited
1195
+ @doc.size(:letter)
1196
+ assert_equal(:letter, @page.size) # inherited
1197
+ @page.size(:legal)
1198
+ assert_equal(:legal, @page.size) # overridden
1199
+ @page.size(:letter)
1200
+ assert_equal(:letter, @page.size) # overridden
1201
+ end
1202
+ end
1203
+
1204
+ class DocumentTestCases < Minitest::Test
1205
+ def setup
1206
+ @doc = StdWidgetFactory.instance.make_widget('erml', nil)
1207
+ @doc.units('in')
1208
+ @legalland = @doc.styles.add('page', :id => 'legalland', :orientation => 'landscape', :size => 'legal')
1209
+ end
1210
+
1211
+ def test_make_widget
1212
+ refute_nil(@doc)
1213
+ assert(@doc.is_a?(Document))
1214
+ end
1215
+
1216
+ def test_page_style
1217
+ assert_equal(:portrait, @doc.style.orientation)
1218
+ assert_equal(:letter, @doc.style.size)
1219
+ @doc.style('legalland')
1220
+ assert_equal(:landscape, @doc.style.orientation)
1221
+ assert_equal(:legal, @doc.style.size)
1222
+ end
1223
+
1224
+ def test_width
1225
+ assert_equal(8.5, @doc.width(:in))
1226
+ @doc.style('legalland')
1227
+ assert_equal(14, @doc.width(:in))
1228
+ end
1229
+
1230
+ def test_height
1231
+ assert_equal(11, @doc.height(:in))
1232
+ @doc.style('legalland')
1233
+ assert_equal(8.5, @doc.height(:in))
1234
+ end
1235
+ end