thinreports 0.8.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CONTRIBUTING.md +2 -0
  3. data/.travis.yml +3 -3
  4. data/CHANGELOG.md +98 -1
  5. data/README.md +0 -9
  6. data/Rakefile +1 -2
  7. data/examples/character_spacing/character_spacing.tlf +293 -1
  8. data/examples/dynamic_image/dynamic_image.tlf +661 -1
  9. data/examples/dynamic_style/dynamic_style.rb +4 -4
  10. data/examples/dynamic_style/dynamic_style.tlf +1835 -1
  11. data/examples/dynamic_style/dynamic_style_in_list.tlf +344 -1
  12. data/examples/eudc/eudc.tlf +180 -1
  13. data/examples/hidden_shapes/hidden_shapes.tlf +449 -1
  14. data/examples/list_events/list_events.rb +1 -28
  15. data/examples/list_events/list_events.tlf +361 -0
  16. data/examples/list_manual_generation/list_manual_generation.tlf +132 -1
  17. data/examples/list_page_number/list_page_number.tlf +254 -1
  18. data/examples/page_number/page_number.tlf +215 -1
  19. data/examples/palleted_png/palleted_png.rb +2 -0
  20. data/examples/palleted_png/palleted_png.tlf +47 -1
  21. data/examples/password_setting/password_setting.tlf +45 -1
  22. data/examples/report_callbacks/report_callbacks.rb +1 -18
  23. data/examples/report_callbacks/report_callbacks.tlf +147 -1
  24. data/examples/single_line_tblock/single_line_tblock.tlf +170 -1
  25. data/examples/tblock_overflow/tblock_overflow.tlf +538 -1
  26. data/examples/tblock_styles/font_size.tlf +383 -1
  27. data/examples/tblock_styles/tblock_styles.tlf +889 -1
  28. data/examples/text_align/text_align.tlf +241 -1
  29. data/examples/typeB_page_size/B4_ISO.tlf +45 -1
  30. data/examples/typeB_page_size/B4_JIS.tlf +45 -1
  31. data/examples/word_wrap/word_wrap.tlf +297 -1
  32. data/lib/thinreports.rb +0 -1
  33. data/lib/thinreports/config.rb +3 -0
  34. data/lib/thinreports/core/errors.rb +0 -3
  35. data/lib/thinreports/core/format/base.rb +4 -4
  36. data/lib/thinreports/core/shape.rb +1 -9
  37. data/lib/thinreports/core/shape/basic.rb +3 -3
  38. data/lib/thinreports/core/shape/basic/block_format.rb +1 -1
  39. data/lib/thinreports/core/shape/basic/format.rb +2 -14
  40. data/lib/thinreports/core/shape/basic/internal.rb +2 -2
  41. data/lib/thinreports/core/shape/image_block.rb +3 -3
  42. data/lib/thinreports/core/shape/image_block/format.rb +0 -2
  43. data/lib/thinreports/core/shape/image_block/internal.rb +1 -1
  44. data/lib/thinreports/core/shape/list.rb +3 -7
  45. data/lib/thinreports/core/shape/list/format.rb +37 -24
  46. data/lib/thinreports/core/shape/list/manager.rb +1 -36
  47. data/lib/thinreports/core/shape/list/page.rb +0 -15
  48. data/lib/thinreports/core/shape/list/page_state.rb +1 -1
  49. data/lib/thinreports/core/shape/list/section_format.rb +14 -12
  50. data/lib/thinreports/core/shape/list/section_internal.rb +4 -7
  51. data/lib/thinreports/core/shape/manager/format.rb +0 -2
  52. data/lib/thinreports/core/shape/manager/internal.rb +1 -1
  53. data/lib/thinreports/core/shape/page_number.rb +1 -1
  54. data/lib/thinreports/core/shape/page_number/format.rb +9 -6
  55. data/lib/thinreports/core/shape/page_number/interface.rb +1 -1
  56. data/lib/thinreports/core/shape/page_number/internal.rb +2 -6
  57. data/lib/thinreports/core/shape/style/base.rb +11 -13
  58. data/lib/thinreports/core/shape/style/basic.rb +4 -4
  59. data/lib/thinreports/core/shape/style/graphic.rb +4 -10
  60. data/lib/thinreports/core/shape/style/text.rb +36 -69
  61. data/lib/thinreports/core/shape/text.rb +3 -3
  62. data/lib/thinreports/core/shape/text/format.rb +3 -13
  63. data/lib/thinreports/core/shape/text/internal.rb +2 -2
  64. data/lib/thinreports/core/shape/text_block.rb +3 -3
  65. data/lib/thinreports/core/shape/text_block/format.rb +9 -6
  66. data/lib/thinreports/core/shape/text_block/interface.rb +7 -7
  67. data/lib/thinreports/core/shape/text_block/internal.rb +1 -1
  68. data/lib/thinreports/generator/pdf.rb +0 -1
  69. data/lib/thinreports/generator/pdf/document.rb +2 -2
  70. data/lib/thinreports/generator/pdf/document/draw_shape.rb +25 -51
  71. data/lib/thinreports/generator/pdf/document/draw_template_items.rb +66 -0
  72. data/lib/thinreports/generator/pdf/document/font.rb +3 -8
  73. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +97 -77
  74. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +18 -13
  75. data/lib/thinreports/generator/pdf/document/graphics/image.rb +17 -12
  76. data/lib/thinreports/generator/pdf/document/page.rb +1 -1
  77. data/lib/thinreports/generator/pdf/drawer/list.rb +5 -1
  78. data/lib/thinreports/generator/pdf/drawer/list_section.rb +1 -4
  79. data/lib/thinreports/generator/pdf/drawer/page.rb +9 -9
  80. data/lib/thinreports/layout.rb +3 -3
  81. data/lib/thinreports/layout/base.rb +0 -16
  82. data/lib/thinreports/layout/format.rb +38 -57
  83. data/lib/thinreports/layout/legacy_schema.rb +354 -0
  84. data/lib/thinreports/layout/version.rb +1 -1
  85. data/lib/thinreports/report.rb +0 -1
  86. data/lib/thinreports/report/base.rb +3 -17
  87. data/lib/thinreports/report/internal.rb +13 -55
  88. data/lib/thinreports/report/page.rb +1 -1
  89. data/lib/thinreports/version.rb +1 -1
  90. data/test/data/legacy_layout/all-items.tlf +1 -0
  91. data/test/schema_helper.rb +121 -0
  92. data/test/test_helper.rb +13 -50
  93. data/test/unit/core/format/test_base.rb +35 -31
  94. data/test/unit/core/shape/base/test_internal.rb +1 -1
  95. data/test/unit/core/shape/basic/test_block_format.rb +23 -0
  96. data/test/unit/core/shape/basic/{test_basic_interface.rb → test_block_interface.rb} +1 -1
  97. data/test/unit/core/shape/basic/{test_basic_internal.rb → test_block_internal.rb} +4 -7
  98. data/test/unit/core/shape/basic/test_format.rb +25 -47
  99. data/test/unit/core/shape/basic/test_interface.rb +5 -5
  100. data/test/unit/core/shape/basic/test_internal.rb +6 -11
  101. data/test/unit/core/shape/image_block/test_interface.rb +5 -5
  102. data/test/unit/core/shape/image_block/test_internal.rb +2 -2
  103. data/test/unit/core/shape/list/test_format.rb +86 -44
  104. data/test/unit/core/shape/list/test_manager.rb +10 -65
  105. data/test/unit/core/shape/list/test_page.rb +10 -61
  106. data/test/unit/core/shape/list/test_page_state.rb +1 -1
  107. data/test/unit/core/shape/list/test_section_format.rb +19 -28
  108. data/test/unit/core/shape/list/test_section_interface.rb +14 -6
  109. data/test/unit/core/shape/list/test_section_internal.rb +17 -23
  110. data/test/unit/core/shape/manager/test_format.rb +1 -1
  111. data/test/unit/core/shape/manager/test_internal.rb +59 -98
  112. data/test/unit/core/shape/manager/test_target.rb +21 -30
  113. data/test/unit/core/shape/page_number/test_format.rb +34 -52
  114. data/test/unit/core/shape/page_number/test_interface.rb +1 -1
  115. data/test/unit/core/shape/page_number/test_internal.rb +2 -2
  116. data/test/unit/core/shape/styles/test_base.rb +16 -41
  117. data/test/unit/core/shape/styles/test_basic.rb +7 -7
  118. data/test/unit/core/shape/styles/test_graphic.rb +27 -32
  119. data/test/unit/core/shape/styles/test_text.rb +68 -311
  120. data/test/unit/core/shape/text/test_format.rb +30 -59
  121. data/test/unit/core/shape/text/test_internal.rb +5 -5
  122. data/test/unit/core/shape/text_block/formatter/test_datetime.rb +13 -13
  123. data/test/unit/core/shape/text_block/test_format.rb +145 -146
  124. data/test/unit/core/shape/text_block/test_interface.rb +9 -9
  125. data/test/unit/core/shape/text_block/test_internal.rb +9 -9
  126. data/test/unit/core/test_shape.rb +19 -31
  127. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +112 -122
  128. data/test/unit/generator/pdf/document/graphics/test_basic.rb +45 -0
  129. data/test/unit/generator/pdf/document/graphics/test_image.rb +5 -5
  130. data/test/unit/generator/pdf/document/test_font.rb +4 -10
  131. data/test/unit/generator/pdf/document/test_page.rb +13 -11
  132. data/test/unit/generator/pdf/document/test_parse_color.rb +5 -5
  133. data/test/unit/generator/test_base.rb +5 -5
  134. data/test/unit/generator/test_configuration.rb +4 -8
  135. data/test/unit/generator/test_pdf.rb +3 -2
  136. data/test/unit/layout/test_base.rb +16 -22
  137. data/test/unit/layout/test_format.rb +66 -86
  138. data/test/unit/layout/test_legacy_schema.rb +587 -0
  139. data/test/unit/layout/test_version.rb +20 -20
  140. data/test/unit/report/test_base.rb +32 -45
  141. data/test/unit/report/test_internal.rb +43 -99
  142. data/test/unit/test_config.rb +4 -2
  143. data/test/unit/test_layout.rb +1 -1
  144. metadata +20 -48
  145. data/examples/list_events/list_events_0_7_7.tlf +0 -1
  146. data/examples/list_events/list_events_0_8.tlf +0 -1
  147. data/lib/thinreports/core/events.rb +0 -69
  148. data/lib/thinreports/core/format/builder.rb +0 -62
  149. data/lib/thinreports/core/shape/list/configuration.rb +0 -54
  150. data/lib/thinreports/core/shape/list/events.rb +0 -47
  151. data/lib/thinreports/core/shape/list/store.rb +0 -33
  152. data/lib/thinreports/generator/pdf/configuration.rb +0 -33
  153. data/lib/thinreports/generator/pdf/document/parse_svg.rb +0 -104
  154. data/lib/thinreports/layout/configuration.rb +0 -29
  155. data/test/data/layout_block.tlf +0 -1
  156. data/test/data/layout_list.tlf +0 -1
  157. data/test/data/layout_list_noheader.tlf +0 -1
  158. data/test/data/layout_text1.tlf +0 -1
  159. data/test/data/layout_text2.tlf +0 -1
  160. data/test/unit/core/format/test_builder.rb +0 -109
  161. data/test/unit/core/shape/basic/test_basic_format.rb +0 -30
  162. data/test/unit/core/shape/image_block/test_format.rb +0 -58
  163. data/test/unit/core/shape/list/test_configuration.rb +0 -69
  164. data/test/unit/core/shape/list/test_events.rb +0 -36
  165. data/test/unit/core/shape/list/test_store.rb +0 -41
  166. data/test/unit/core/test_events.rb +0 -93
  167. data/test/unit/generator/pdf/document/test_draw_shape.rb +0 -44
  168. data/test/unit/generator/pdf/test_configuration.rb +0 -31
  169. data/test/unit/layout/test_configuration.rb +0 -21
  170. data/test/unit/report/test_events.rb +0 -22
@@ -9,27 +9,14 @@ class Thinreports::Core::Shape::List::TestPage < Minitest::Test
9
9
  List = Thinreports::Core::Shape::List
10
10
 
11
11
  def create_report(&block)
12
- new_report('layout_list.tlf', &block)
13
- end
14
-
15
- def create_report_for_checking_dispatched_event(event)
16
- @target_event = event
17
- @is_dispatched = false
18
-
19
- create_report do |r|
20
- r.layout.config.list(:list) do |list|
21
- list.events.on(event) { @is_dispatched = true }
22
- end
23
- end
24
- end
25
-
26
- def assert_dispatched_event
27
- assert @is_dispatched, "The :#{@target_event} event was not dispatched."
12
+ report = Thinreports::Report.new layout: layout_file.path
13
+ block.call(report) if block_given?
14
+ report
28
15
  end
29
16
 
30
17
  def test_on_page_finalize_callback
31
18
  report = create_report
32
- list = report.list(:list)
19
+ list = report.list
33
20
 
34
21
  counter = 0
35
22
  callback = -> { counter += 1 }
@@ -39,13 +26,13 @@ class Thinreports::Core::Shape::List::TestPage < Minitest::Test
39
26
  5.times { list.add_row }
40
27
  assert_equal 1, counter
41
28
 
42
- report.generate
29
+ report.finalize
43
30
  assert_equal 2, counter
44
31
  end
45
32
 
46
33
  def test_on_page_footer_insert_callback
47
34
  report = create_report
48
- list = report.list(:list)
35
+ list = report.list
49
36
 
50
37
  tester = 0
51
38
  callback = -> footer {
@@ -60,13 +47,13 @@ class Thinreports::Core::Shape::List::TestPage < Minitest::Test
60
47
  5.times { list.add_row }
61
48
  assert_equal 1, tester
62
49
 
63
- report.generate
50
+ report.finalize
64
51
  assert_equal 2, tester
65
52
  end
66
53
 
67
54
  def test_on_footer_insert_callback
68
55
  report = create_report
69
- list = report.list(:list)
56
+ list = report.list
70
57
 
71
58
  tester = 0
72
59
  callback = -> footer {
@@ -81,50 +68,12 @@ class Thinreports::Core::Shape::List::TestPage < Minitest::Test
81
68
  5.times { list.add_row }
82
69
  assert_equal 0, tester
83
70
 
84
- report.generate
85
- assert_equal 1, tester
86
- end
87
-
88
- def test_page_finalize_event_should_be_dispatched_when_page_break_is_called
89
- report = create_report_for_checking_dispatched_event :page_finalize
90
- report.start_new_page do
91
- list(:list).page_break
92
- end
93
-
94
- assert_dispatched_event
95
- end
96
-
97
- def test_page_finalize_event_should_be_dispatched_when_list_was_overflowed
98
- report = create_report_for_checking_dispatched_event :page_finalize
99
- report.start_new_page do
100
- 6.times { list(:list).add_row }
101
- end
102
-
103
- assert_dispatched_event
104
- end
105
-
106
- def test_page_finalize_event_should_be_dispatched_when_a_new_page_is_created
107
- report = create_report_for_checking_dispatched_event :page_finalize
108
- report.start_new_page do
109
- list(:list).add_row
110
- end
111
- report.start_new_page
112
-
113
- assert_dispatched_event
114
- end
115
-
116
- def test_page_finalize_event_should_be_dispatched_when_report_is_finalized
117
- report = create_report_for_checking_dispatched_event :page_finalize
118
- report.start_new_page do
119
- list(:list).add_row
120
- end
121
71
  report.finalize
122
-
123
- assert_dispatched_event
72
+ assert_equal 1, tester
124
73
  end
125
74
 
126
75
  def test_copy_should_properly_work_when_list_has_not_header
127
- report = new_report('layout_list_noheader.tlf')
76
+ report = Thinreports::Report.new layout: layout_file(schema: LIST_NO_HEADER_SCHEMA_JSON).path
128
77
 
129
78
  10.times { report.list.add_row }
130
79
  rescue => e
@@ -20,7 +20,7 @@ class Thinreports::Core::Shape::List::TestPageState < Minitest::Test
20
20
  end
21
21
 
22
22
  def test_type_of?
23
- assert_equal @state.type_of?(:list), true
23
+ assert_equal @state.type_of?('list'), true
24
24
  end
25
25
 
26
26
  def test_finalized!
@@ -5,41 +5,32 @@ require 'test_helper'
5
5
  class Thinreports::Core::Shape::List::TestSectionFormat < Minitest::Test
6
6
  include Thinreports::TestHelper
7
7
 
8
- TEST_LIST_SECTION_FORMAT = {
9
- "height" => 47.7,
10
- "translate" => {"x" => 0, "y" => -64.2},
11
- "svg" => {
12
- "tag" => "g",
13
- "content" => "<!---SHAPE{\"type\":\"s-tblock\",\"id\":\"t1\"}SHAPE--->" +
14
- "<!---SHAPE{\"type\":\"s-rect\",\"id\":\"r1\"}SHAPE--->" +
15
- "<!---SHAPE{\"type\":\"s-tblock\",\"id\":\"t2\"}SHAPE--->"
16
- }
8
+ LIST_SECTION_FORMAT = {
9
+ 'enabled' => true,
10
+ 'height' => 47.7,
11
+ 'translate' => { 'x' => 0, 'y' => -64.2 },
12
+ 'items' => [
13
+ { 'type' => 'rect', 'id' => '' },
14
+ { 'type' => 'text-block', 'id' => 'text_block' }
15
+ ]
17
16
  }
18
17
 
19
18
  Shape = Thinreports::Core::Shape
19
+ List = Thinreports::Core::Shape::List
20
20
 
21
- def test_build
22
- shape_format = stub(id: 'mock')
21
+ def test_attribute_readers
22
+ format = List::SectionFormat.new(LIST_SECTION_FORMAT)
23
23
 
24
- Shape::TextBlock::Format.expects(:build).returns(shape_format).times(2)
25
- Shape::Basic::Format.expects(:build).returns(shape_format).times(1)
26
-
27
- begin
28
- build_format
29
- rescue => e
30
- flunk exception_details(e, 'Building failed.')
31
- end
24
+ assert_equal 47.7, format.height
25
+ assert_equal 0, format.relative_left
26
+ assert_equal(-64.2, format.relative_top)
27
+ assert_equal true, format.display?
32
28
  end
33
29
 
34
- def test_config_readers
35
- format = Shape::List::SectionFormat.new(TEST_LIST_SECTION_FORMAT)
36
-
37
- assert_equal format.height, 47.7
38
- assert_equal format.relative_left, 0
39
- assert_equal format.relative_top, -64.2
40
- end
30
+ def test_initialize_items
31
+ format = List::SectionFormat.new(LIST_SECTION_FORMAT)
41
32
 
42
- def build_format
43
- Shape::List::SectionFormat.build(TEST_LIST_SECTION_FORMAT.dup)
33
+ assert_equal 1, format.shapes.count
34
+ assert_instance_of Shape::TextBlock::Format, format.shapes[:text_block]
44
35
  end
45
36
  end
@@ -5,19 +5,27 @@ require 'test_helper'
5
5
  class Thinreports::Core::Shape::List::TestSectionInterface < Minitest::Test
6
6
  include Thinreports::TestHelper
7
7
 
8
+ BASIC_SECTION_SCHEMA = {
9
+ 'height' => 1.0,
10
+ 'enabled' => true,
11
+ 'items' => []
12
+ }
13
+
8
14
  # Alias
9
15
  List = Thinreports::Core::Shape::List
10
16
 
11
17
  def setup
12
- @report = new_report 'layout_text1'
18
+ @report = Thinreports::Report.new layout: layout_file.path
13
19
  end
14
20
 
15
- def create_interface(format_config = {})
21
+ def create_interface(extra_section_schema = {})
16
22
  parent = @report.start_new_page
17
23
 
18
- List::SectionInterface.new parent,
19
- List::SectionFormat.new(format_config),
20
- :section
24
+ List::SectionInterface.new(
25
+ parent,
26
+ List::SectionFormat.new(BASIC_SECTION_SCHEMA.merge(extra_section_schema)),
27
+ :section
28
+ )
21
29
  end
22
30
 
23
31
  def test_internal_should_return_instance_of_SectionInternal
@@ -58,7 +66,7 @@ class Thinreports::Core::Shape::List::TestSectionInterface < Minitest::Test
58
66
  new_parent = @report.start_new_page
59
67
 
60
68
  %w( foo bar hoge ).each do |id|
61
- list.manager.format.shapes[id.to_sym] = tblock::Format.new('type' => 's-tblock', 'id' => id)
69
+ list.manager.format.shapes[id.to_sym] = tblock::Format.new('type' => 'text-block', 'id' => id)
62
70
  list.item(id).value(10)
63
71
  end
64
72
 
@@ -5,13 +5,22 @@ require 'test_helper'
5
5
  class Thinreports::Core::Shape::List::TestSectionInternal < Minitest::Test
6
6
  include Thinreports::TestHelper
7
7
 
8
+ BASIC_SECTION_SCHEMA = {
9
+ 'height' => 1.0,
10
+ 'enabled' => true,
11
+ 'items' => []
12
+ }
13
+
8
14
  # Alias
9
15
  List = Thinreports::Core::Shape::List
10
16
 
11
- def create_internal(format_config = {})
12
- report = new_report 'layout_text1'
17
+ def create_internal(extra_section_schema = {})
18
+ report = Thinreports::Report.new layout: layout_file.path
13
19
 
14
- List::SectionInternal.new report, List::SectionFormat.new(format_config)
20
+ List::SectionInternal.new(
21
+ report,
22
+ List::SectionFormat.new(BASIC_SECTION_SCHEMA.merge(extra_section_schema))
23
+ )
15
24
  end
16
25
 
17
26
  def test_height_should_operate_as_delegator_of_format
@@ -24,16 +33,6 @@ class Thinreports::Core::Shape::List::TestSectionInternal < Minitest::Test
24
33
  assert_same list.relative_left, list.format.relative_left
25
34
  end
26
35
 
27
- def test_relative_top_should_operate_as_delegator_of_format
28
- list = create_internal('translate' => {'y' => 10})
29
- assert_same list.relative_top, list.format.relative_top
30
- end
31
-
32
- def test_svg_tag_should_operate_as_delegator_of_format
33
- list = create_internal('svg' => {'tag' => 'g'})
34
- assert_same list.svg_tag, list.format.svg_tag
35
- end
36
-
37
36
  def test_move_top_to_should_properly_set_value_to_states_as_relative_top
38
37
  list = create_internal
39
38
  list.move_top_to(200)
@@ -41,16 +40,11 @@ class Thinreports::Core::Shape::List::TestSectionInternal < Minitest::Test
41
40
  assert_equal list.states[:relative_top], 200
42
41
  end
43
42
 
44
- def test_relative_position_should_return_Array_included_coordinates
45
- list = create_internal('translate' => {'x' => 100, 'y' => 200})
46
-
47
- assert_equal list.relative_position, [100, 200]
48
- end
49
-
50
- def test_Y_coordinate_which_relative_position_returns_should_be_calculated_position_with_relative_top_of_states
51
- list = create_internal('translate' => {'x' => 100, 'y' => 100})
52
- list.move_top_to(50)
43
+ def test_relative_top
44
+ list = create_internal('translate' => { 'y' => 100 })
45
+ assert_equal 0, list.relative_top
53
46
 
54
- assert_equal list.relative_position.last, 150
47
+ list.move_top_to 50
48
+ assert_equal 50, list.relative_top
55
49
  end
56
50
  end
@@ -27,7 +27,7 @@ class Thinreports::Core::Shape::Manager::TestFormat < Minitest::Test
27
27
  def test_find_shape_should_return_format_of_shape_when_shape_is_found
28
28
  format = TestFormat.new({}) do |f|
29
29
  f.shapes[:foo] = Thinreports::Core::Shape::TextBlock::Format.new('id' => 'foo',
30
- 'type' => 's-tblock')
30
+ 'type' => 'text-block')
31
31
  end
32
32
  assert_equal format.find_shape(:foo).id, 'foo'
33
33
  end
@@ -4,168 +4,129 @@ require 'test_helper'
4
4
 
5
5
  class Thinreports::Core::Shape::Manager::TestInternal < Minitest::Test
6
6
  include Thinreports::TestHelper
7
-
7
+
8
8
  # Alias
9
9
  Shape = Thinreports::Core::Shape
10
-
10
+
11
11
  def create_shape_format(type, id, other_config = {})
12
12
  Shape::Format(type).new({'id' => id,
13
13
  'type' => type,
14
- 'display' => 'true'}.merge(other_config))
14
+ 'display' => true}.merge(other_config))
15
15
  end
16
-
16
+
17
17
  def create_internal(&block)
18
- report = new_report('layout_text1.tlf')
18
+ report = Thinreports::Report.new layout: layout_file.path
19
19
  format = report.layout.format
20
-
21
- # Add to default dummy shapes.
22
- format.shapes[:t1] = create_shape_format('s-tblock', 't1', 'value' => '')
23
- format.shapes[:t2] = create_shape_format('s-tblock', 't2', 'value' => '')
24
- format.shapes[:ls] = create_shape_format('s-list', 'ls')
25
-
20
+
26
21
  block.call(format) if block_given?
27
-
22
+
28
23
  report.start_new_page.manager
29
24
  end
30
-
25
+
31
26
  def test_find_format_should_return_format_with_the_specified_Symbol_id
32
- assert_equal create_internal.find_format(:t1).id, 't1'
27
+ assert_equal create_internal.find_format(:text_block).id, 'text_block'
33
28
  end
34
-
29
+
35
30
  def test_find_format_should_return_format_with_the_specified_String_id
36
- assert_equal create_internal.find_format('t2').id, 't2'
31
+ assert_equal create_internal.find_format('text_block').id, 'text_block'
37
32
  end
38
-
33
+
39
34
  def test_find_format_should_return_nil_when_format_with_specified_id_is_not_found
40
35
  assert_nil create_internal.find_format(:unknown)
41
36
  end
42
-
37
+
43
38
  def test_find_item_should_return_shape_with_the_specified_id
44
- assert_instance_of Shape::TextBlock::Interface, create_internal.find_item(:t1)
39
+ assert_instance_of Shape::TextBlock::Interface, create_internal.find_item(:text_block)
45
40
  end
46
-
41
+
47
42
  def test_find_item_should_return_shape_in_shapes_registry_when_the_specified_shape_exists_in_registry
48
43
  internal = create_internal
49
- internal.find_item(:t1)
50
-
51
- assert_same internal.find_item(:t1), internal.shapes[:t1]
44
+ internal.find_item(:text_block)
45
+
46
+ assert_same internal.find_item(:text_block), internal.shapes[:text_block]
52
47
  end
53
-
48
+
54
49
  def test_find_item_should_return_shape_when_passing_in_the_specified_only_filter
55
50
  internal = create_internal
56
- assert_equal internal.find_item(:t1, only: 's-tblock').id, 't1'
51
+ assert_equal internal.find_item(:text_block, only: 'text-block').id, 'text_block'
57
52
  end
58
-
53
+
59
54
  def test_find_item_should_return_nil_when_not_passing_in_the_specified_only_filter
60
55
  internal = create_internal
61
- assert_nil internal.find_item(:t1, only: 's-list')
56
+ assert_nil internal.find_item(:text_block, only: 'list')
62
57
  end
63
-
58
+
64
59
  def test_find_item_should_return_shape_when_passing_in_the_specified_except_filter
65
60
  internal = create_internal
66
- assert_equal internal.find_item(:ls, except: 's-tblock').id, 'ls'
61
+ assert_equal internal.find_item(:default, except: 'text-block').id, 'default'
67
62
  end
68
-
63
+
69
64
  def test_find_item_should_return_shape_when_not_passing_in_the_specified_except_filter
70
65
  internal = create_internal
71
- assert_nil internal.find_item(:ls, except: 's-list')
66
+ assert_nil internal.find_item(:default, except: 'list')
72
67
  end
73
-
68
+
74
69
  def test_final_shape_should_return_nil_when_shape_is_not_found
75
70
  internal = create_internal
76
71
  assert_nil internal.final_shape(:unknown)
77
72
  end
78
-
73
+
79
74
  def test_final_shape_should_return_nil_when_shape_is_stored_in_shapes_and_hidden
80
75
  internal = create_internal
81
- internal.find_item(:t1).hide
82
-
83
- assert_nil internal.final_shape(:t1)
84
- end
85
-
86
- def test_final_shape_should_return_shape_when_shape_is_stored_in_shapes_and_not_Block
87
- internal = create_internal do |f|
88
- f.shapes[:rect] = create_shape_format('s-rect', 'rect')
89
- end
90
- internal.find_item(:rect)
91
-
92
- assert_equal internal.final_shape(:rect).id, 'rect'
76
+ internal.find_item(:text_block).hide
77
+
78
+ assert_nil internal.final_shape(:text_block)
93
79
  end
94
-
80
+
95
81
  def test_final_shape_should_return_shape_when_shape_is_stored_in_shapes_and_TextBlock_with_value
96
82
  internal = create_internal
97
- internal.find_item(:t1).value('value')
98
-
99
- assert_equal internal.final_shape(:t1).id, 't1'
83
+ internal.find_item(:text_block).value('value')
84
+
85
+ assert_equal internal.final_shape(:text_block).id, 'text_block'
100
86
  end
101
-
87
+
102
88
  def test_final_shape_should_return_nil_when_shape_is_stored_in_shapes_and_TextBlock_with_no_value
103
89
  internal = create_internal
104
- internal.find_item(:t2)
105
-
106
- assert_nil internal.final_shape(:t2)
90
+ internal.find_item(:text_block)
91
+
92
+ assert_nil internal.final_shape(:text_block)
107
93
  end
108
-
94
+
109
95
  def test_final_shape_should_return_shape_when_shape_is_stored_in_shapes_and_ImageBlock_with_src
110
- internal = create_internal do |f|
111
- f.shapes[:iblock] = create_shape_format('s-iblock', 'iblock')
112
- end
113
- internal.find_item(:iblock).src('/path/to/image.png')
114
-
115
- assert_equal internal.final_shape(:iblock).id, 'iblock'
96
+ internal = create_internal
97
+ internal.find_item(:image_block).src('/path/to/image.png')
98
+
99
+ assert_equal internal.final_shape(:image_block).id, 'image_block'
116
100
  end
117
-
101
+
118
102
  def test_final_shape_should_return_nil_when_shape_is_stored_in_shapes_and_ImageBlock_with_no_src
119
- internal = create_internal do |f|
120
- f.shapes[:iblock] = create_shape_format('s-iblock', 'iblock')
121
- end
122
-
123
- assert_nil internal.final_shape(:iblock)
103
+ internal = create_internal
104
+ assert_nil internal.final_shape(:image_block)
124
105
  end
125
-
106
+
126
107
  def test_final_shape_should_return_nil_when_shape_isnot_stored_in_shapes_and_hidden
127
- internal = create_internal do |f|
128
- f.shapes[:t3] = create_shape_format('s-tblock', 't3', 'display' => 'false')
129
- end
130
-
131
- assert_nil internal.final_shape(:t3)
108
+ assert_nil create_internal.final_shape(:text_block_hidden)
132
109
  end
133
-
110
+
134
111
  def test_final_shape_should_return_shape_when_shape_isnot_stored_in_shapes_and_not_Block
135
- internal = create_internal do |f|
136
- f.shapes[:rect] = create_shape_format('s-rect', 'rect')
137
- end
138
-
139
- assert_equal internal.final_shape(:rect).id, 'rect'
112
+ assert_equal create_internal.final_shape(:rect_with_id).id, 'rect_with_id'
140
113
  end
141
-
114
+
142
115
  def test_final_shape_should_return_nil_when_shape_isnot_stored_in_shapes_and_ImageBlock
143
116
  internal = create_internal do |f|
144
- f.shapes[:iblock] = create_shape_format('s-iblock', 'iblock')
117
+ f.shapes[:iblock] = create_shape_format('image-block', 'iblock')
145
118
  end
146
-
119
+
147
120
  assert_nil internal.final_shape(:iblock)
148
121
  end
149
-
150
- def test_final_shape_should_return_shape_when_shape_isnot_stored_in_shapes_and_TextBlock_with_value
151
- internal = create_internal do |f|
152
- f.shapes[:t3] = create_shape_format('s-tblock', 't3', 'value' => 'default value')
153
- end
154
-
155
- assert_equal internal.final_shape(:t3).id, 't3'
156
- end
157
-
122
+
158
123
  def test_final_shape_should_return_shape_when_shape_isnot_stored_in_shapes_and_TextBlock_with_reference
159
- internal = create_internal do |f|
160
- f.shapes[:t3] = create_shape_format('s-tblock', 't3', 'ref-id' => 't1')
161
- end
162
-
163
- assert_equal internal.final_shape(:t3).id, 't3'
124
+ assert_equal create_internal.final_shape(:text_block_referenced).id, 'text_block_referenced'
164
125
  end
165
-
126
+
166
127
  def test_final_shape_should_return_nil_when_shape_isnot_stored_in_shapes_and_TextBlock_with_no_value_no_reference
167
128
  internal = create_internal
168
-
129
+
169
130
  assert_nil internal.final_shape(:t1)
170
131
  end
171
- end
132
+ end