thinreports 0.10.2 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CONTRIBUTING.md +2 -2
  3. data/.github/dependabot.yml +11 -0
  4. data/.github/workflows/test.yml +50 -0
  5. data/.gitignore +1 -0
  6. data/CHANGELOG.md +43 -0
  7. data/Gemfile +2 -1
  8. data/{MIT-LICENSE → LICENSE.txt} +2 -0
  9. data/README.md +70 -56
  10. data/Rakefile +12 -25
  11. data/gemfiles/prawn-2.2.gemfile +5 -0
  12. data/gemfiles/prawn-2.3.gemfile +5 -0
  13. data/gemfiles/prawn-2.4.gemfile +5 -0
  14. data/lib/thinreports/core/shape/basic/format.rb +5 -0
  15. data/lib/thinreports/core/shape/image_block.rb +1 -1
  16. data/lib/thinreports/core/shape/list.rb +1 -1
  17. data/lib/thinreports/core/shape/page_number.rb +1 -1
  18. data/lib/thinreports/core/shape/stack_view/format.rb +27 -0
  19. data/lib/thinreports/core/shape/stack_view/interface.rb +17 -0
  20. data/lib/thinreports/core/shape/stack_view/internal.rb +22 -0
  21. data/lib/thinreports/core/shape/stack_view/row_format.rb +39 -0
  22. data/lib/thinreports/core/shape/stack_view.rb +17 -0
  23. data/lib/thinreports/core/shape/style/basic.rb +4 -1
  24. data/lib/thinreports/core/shape/text.rb +1 -1
  25. data/lib/thinreports/core/shape/text_block/formatter/number.rb +6 -1
  26. data/lib/thinreports/core/shape/text_block/internal.rb +0 -2
  27. data/lib/thinreports/core/shape/text_block.rb +1 -1
  28. data/lib/thinreports/core/shape.rb +2 -0
  29. data/lib/thinreports/generate.rb +11 -0
  30. data/lib/thinreports/generator/pdf/document/draw_shape.rb +31 -10
  31. data/lib/thinreports/generator/pdf/document/draw_template_items.rb +1 -1
  32. data/lib/thinreports/generator/pdf/document/graphics/image.rb +19 -1
  33. data/lib/thinreports/generator/pdf/document/graphics/text.rb +10 -5
  34. data/lib/thinreports/generator/pdf/document/page.rb +12 -0
  35. data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +7 -7
  36. data/lib/thinreports/layout/base.rb +1 -1
  37. data/lib/thinreports/layout/legacy_schema.rb +1 -0
  38. data/lib/thinreports/layout/version.rb +1 -1
  39. data/lib/thinreports/report/internal.rb +2 -0
  40. data/lib/thinreports/report.rb +2 -2
  41. data/lib/thinreports/section_report/build.rb +32 -0
  42. data/lib/thinreports/section_report/builder/item_builder.rb +49 -0
  43. data/lib/thinreports/section_report/builder/report_builder.rb +82 -0
  44. data/lib/thinreports/section_report/builder/report_data.rb +13 -0
  45. data/lib/thinreports/section_report/builder/stack_view_builder.rb +53 -0
  46. data/lib/thinreports/section_report/builder/stack_view_data.rb +11 -0
  47. data/lib/thinreports/section_report/generate.rb +26 -0
  48. data/lib/thinreports/section_report/pdf/render.rb +23 -0
  49. data/lib/thinreports/section_report/pdf/renderer/draw_item.rb +68 -0
  50. data/lib/thinreports/section_report/pdf/renderer/group_renderer.rb +57 -0
  51. data/lib/thinreports/section_report/pdf/renderer/section_height.rb +100 -0
  52. data/lib/thinreports/section_report/pdf/renderer/section_renderer.rb +39 -0
  53. data/lib/thinreports/section_report/pdf/renderer/stack_view_renderer.rb +55 -0
  54. data/lib/thinreports/section_report/pdf/renderer/stack_view_row_renderer.rb +38 -0
  55. data/lib/thinreports/section_report/schema/loader.rb +28 -0
  56. data/lib/thinreports/section_report/schema/parser.rb +52 -0
  57. data/lib/thinreports/section_report/schema/report.rb +30 -0
  58. data/lib/thinreports/section_report/schema/section.rb +47 -0
  59. data/lib/thinreports/version.rb +1 -1
  60. data/lib/thinreports.rb +5 -0
  61. data/thinreports.gemspec +11 -10
  62. metadata +48 -150
  63. data/.travis.yml +0 -16
  64. data/examples/character_spacing/character_spacing.rb +0 -8
  65. data/examples/character_spacing/character_spacing.tlf +0 -293
  66. data/examples/dynamic_image/dynamic_image.rb +0 -31
  67. data/examples/dynamic_image/dynamic_image.tlf +0 -661
  68. data/examples/dynamic_image/img200x100.png +0 -0
  69. data/examples/dynamic_image/img50x50.png +0 -0
  70. data/examples/dynamic_style/dynamic_style.rb +0 -150
  71. data/examples/dynamic_style/dynamic_style.tlf +0 -1835
  72. data/examples/dynamic_style/dynamic_style_in_list.tlf +0 -344
  73. data/examples/dynamic_style/image.png +0 -0
  74. data/examples/eudc/eudc.rb +0 -20
  75. data/examples/eudc/eudc.tlf +0 -180
  76. data/examples/eudc/eudc.ttf +0 -0
  77. data/examples/helper.rb +0 -50
  78. data/examples/hidden_shapes/hidden_shapes.rb +0 -9
  79. data/examples/hidden_shapes/hidden_shapes.tlf +0 -449
  80. data/examples/list_events/list_events.rb +0 -32
  81. data/examples/list_events/list_events.tlf +0 -361
  82. data/examples/list_manual_generation/list_manual_generation.rb +0 -22
  83. data/examples/list_manual_generation/list_manual_generation.tlf +0 -132
  84. data/examples/list_page_number/list_page_number.rb +0 -17
  85. data/examples/list_page_number/list_page_number.tlf +0 -254
  86. data/examples/page_number/page_number.rb +0 -33
  87. data/examples/page_number/page_number.tlf +0 -215
  88. data/examples/palleted_png/palleted_png.png +0 -0
  89. data/examples/palleted_png/palleted_png.rb +0 -9
  90. data/examples/palleted_png/palleted_png.tlf +0 -47
  91. data/examples/password_setting/password_setting.rb +0 -10
  92. data/examples/password_setting/password_setting.tlf +0 -45
  93. data/examples/report_callbacks/report_callbacks.rb +0 -14
  94. data/examples/report_callbacks/report_callbacks.tlf +0 -147
  95. data/examples/single_line_tblock/single_line_tblock.rb +0 -13
  96. data/examples/single_line_tblock/single_line_tblock.tlf +0 -170
  97. data/examples/tblock_overflow/tblock_overflow.rb +0 -20
  98. data/examples/tblock_overflow/tblock_overflow.tlf +0 -538
  99. data/examples/tblock_styles/font_size.tlf +0 -383
  100. data/examples/tblock_styles/tblock_styles.rb +0 -43
  101. data/examples/tblock_styles/tblock_styles.tlf +0 -889
  102. data/examples/text_align/text_align.rb +0 -8
  103. data/examples/text_align/text_align.tlf +0 -241
  104. data/examples/typeB_page_size/B4_ISO.tlf +0 -45
  105. data/examples/typeB_page_size/B4_JIS.tlf +0 -45
  106. data/examples/typeB_page_size/typeB_page_size.rb +0 -17
  107. data/examples/word_wrap/word_wrap.rb +0 -26
  108. data/examples/word_wrap/word_wrap.tlf +0 -297
  109. data/test/data/font.ttf +0 -0
  110. data/test/data/image_normal.jpg +0 -0
  111. data/test/data/image_normal.png +0 -0
  112. data/test/data/image_normal_jpg_noext +0 -0
  113. data/test/data/image_normal_png_noext +0 -0
  114. data/test/data/image_pallete_based.png +0 -0
  115. data/test/data/legacy_layout/all-items.tlf +0 -1
  116. data/test/schema_helper.rb +0 -122
  117. data/test/test_helper.rb +0 -48
  118. data/test/tmp/.gitkeep +0 -0
  119. data/test/unit/core/format/test_base.rb +0 -152
  120. data/test/unit/core/shape/base/test_internal.rb +0 -87
  121. data/test/unit/core/shape/basic/test_block_format.rb +0 -23
  122. data/test/unit/core/shape/basic/test_block_interface.rb +0 -29
  123. data/test/unit/core/shape/basic/test_block_internal.rb +0 -55
  124. data/test/unit/core/shape/basic/test_format.rb +0 -37
  125. data/test/unit/core/shape/basic/test_interface.rb +0 -108
  126. data/test/unit/core/shape/basic/test_internal.rb +0 -55
  127. data/test/unit/core/shape/image_block/test_interface.rb +0 -24
  128. data/test/unit/core/shape/image_block/test_internal.rb +0 -31
  129. data/test/unit/core/shape/list/test_format.rb +0 -111
  130. data/test/unit/core/shape/list/test_manager.rb +0 -67
  131. data/test/unit/core/shape/list/test_page.rb +0 -156
  132. data/test/unit/core/shape/list/test_page_state.rb +0 -31
  133. data/test/unit/core/shape/list/test_section_format.rb +0 -36
  134. data/test/unit/core/shape/list/test_section_interface.rb +0 -75
  135. data/test/unit/core/shape/list/test_section_internal.rb +0 -50
  136. data/test/unit/core/shape/manager/test_format.rb +0 -38
  137. data/test/unit/core/shape/manager/test_internal.rb +0 -132
  138. data/test/unit/core/shape/manager/test_target.rb +0 -140
  139. data/test/unit/core/shape/page_number/test_format.rb +0 -55
  140. data/test/unit/core/shape/page_number/test_interface.rb +0 -33
  141. data/test/unit/core/shape/page_number/test_internal.rb +0 -81
  142. data/test/unit/core/shape/styles/test_base.rb +0 -191
  143. data/test/unit/core/shape/styles/test_basic.rb +0 -24
  144. data/test/unit/core/shape/styles/test_graphic.rb +0 -50
  145. data/test/unit/core/shape/styles/test_text.rb +0 -97
  146. data/test/unit/core/shape/text/test_format.rb +0 -44
  147. data/test/unit/core/shape/text/test_internal.rb +0 -20
  148. data/test/unit/core/shape/text_block/formatter/test_basic.rb +0 -24
  149. data/test/unit/core/shape/text_block/formatter/test_datetime.rb +0 -49
  150. data/test/unit/core/shape/text_block/formatter/test_number.rb +0 -76
  151. data/test/unit/core/shape/text_block/formatter/test_padding.rb +0 -77
  152. data/test/unit/core/shape/text_block/test_format.rb +0 -169
  153. data/test/unit/core/shape/text_block/test_formatter.rb +0 -28
  154. data/test/unit/core/shape/text_block/test_interface.rb +0 -63
  155. data/test/unit/core/shape/text_block/test_internal.rb +0 -128
  156. data/test/unit/core/test_shape.rb +0 -52
  157. data/test/unit/core/test_utils.rb +0 -68
  158. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +0 -135
  159. data/test/unit/generator/pdf/document/graphics/test_basic.rb +0 -46
  160. data/test/unit/generator/pdf/document/graphics/test_image.rb +0 -46
  161. data/test/unit/generator/pdf/document/graphics/test_text.rb +0 -171
  162. data/test/unit/generator/pdf/document/test_font.rb +0 -110
  163. data/test/unit/generator/pdf/document/test_graphics.rb +0 -42
  164. data/test/unit/generator/pdf/document/test_page.rb +0 -122
  165. data/test/unit/generator/pdf/document/test_parse_color.rb +0 -30
  166. data/test/unit/generator/pdf/prawn_ext/test_calc_image_dimensions.rb +0 -41
  167. data/test/unit/generator/pdf/prawn_ext/test_width_of.rb +0 -22
  168. data/test/unit/generator/pdf/test_document.rb +0 -22
  169. data/test/unit/generator/test_pdf.rb +0 -26
  170. data/test/unit/layout/test_base.rb +0 -41
  171. data/test/unit/layout/test_format.rb +0 -100
  172. data/test/unit/layout/test_legacy_schema.rb +0 -574
  173. data/test/unit/layout/test_version.rb +0 -26
  174. data/test/unit/report/test_base.rb +0 -248
  175. data/test/unit/report/test_internal.rb +0 -206
  176. data/test/unit/test_config.rb +0 -36
  177. data/test/unit/test_layout.rb +0 -12
  178. data/test/unit/test_report.rb +0 -18
@@ -1,169 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Core::Shape::TextBlock::TestFormat < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- TEXT_BLOCK_FORMAT = {
9
- 'id' => 'text_block',
10
- 'reference-id' => 'referenced_text_block',
11
- 'type' => 'text-block',
12
- 'display' => true,
13
- 'multiple-line' => false,
14
- 'x' => 100.0,
15
- 'y' => 200.0,
16
- 'width' => 300.0,
17
- 'height' => 400.0,
18
- 'value' => 'default value',
19
- 'format' => {
20
- 'base' => 'Price: {value}',
21
- 'type' => 'number',
22
- 'number' => {
23
- 'delimiter' => ',',
24
- 'precision' => 1
25
- }
26
- },
27
- 'description' => 'Description for item',
28
- 'style' => {
29
- 'word-wrap' => 'break-word',
30
- 'overflow' => 'truncate',
31
- 'text-align' => 'right',
32
- 'vertical-align' => 'middle',
33
- 'color' => '#000000',
34
- 'font-size' => 12,
35
- 'font-family' => ['Helvetica'],
36
- 'font-style' => ['bold', 'italic', 'linethrough', 'underline'],
37
- 'letter-spacing' => 'normal',
38
- 'line-height' => 30,
39
- 'line-height-ratio' => 1.5
40
- }
41
- }
42
-
43
- TextBlock = Thinreports::Core::Shape::TextBlock
44
-
45
- def test_attribute_readers
46
- format = TextBlock::Format.new(TEXT_BLOCK_FORMAT)
47
-
48
- assert_equal 'referenced_text_block', format.ref_id
49
- assert_equal 'middle', format.valign
50
- assert_equal 'truncate', format.overflow
51
- assert_equal 30, format.line_height
52
- assert_equal false, format.multiple?
53
- assert_equal 'Price: {value}', format.format_base
54
- assert_equal 'number', format.format_type
55
- end
56
-
57
- def test_has_reference?
58
- format_has_reference = TextBlock::Format.new(TEXT_BLOCK_FORMAT.merge('reference-id' => 'other'))
59
- assert_equal true, format_has_reference.has_reference?
60
-
61
- format_has_no_reference = TextBlock::Format.new(TEXT_BLOCK_FORMAT.merge('reference-id' => ''))
62
- assert_equal false, format_has_no_reference.has_reference?
63
- end
64
-
65
- def test_has_format?
66
- format_has_text_format = TextBlock::Format.new(TEXT_BLOCK_FORMAT.merge(
67
- 'format' => { 'type' => 'datetime' }
68
- ))
69
- assert_equal true, format_has_text_format.has_format?
70
-
71
- format_has_no_text_format = TextBlock::Format.new(TEXT_BLOCK_FORMAT.merge(
72
- 'format' => { 'type' => '' }
73
- ))
74
- assert_equal false, format_has_no_text_format.has_format?
75
- end
76
-
77
- def test_number_format_attribute_readers
78
- format = TextBlock::Format.new(TEXT_BLOCK_FORMAT.merge(
79
- 'format' => {
80
- 'type' => 'number',
81
- 'number' => {
82
- 'delimiter' => ',',
83
- 'precision' => 1
84
- }
85
- }
86
- ))
87
- assert_equal ',', format.format_number_delimiter
88
- assert_equal 1, format.format_number_precision
89
- end
90
-
91
- def test_datetime_format_attribute_readers
92
- format = TextBlock::Format.new(TEXT_BLOCK_FORMAT.merge(
93
- 'format' => {
94
- 'type' => 'datetime',
95
- 'datetime' => {
96
- 'format' => '%Y-%m-%d'
97
- }
98
- }
99
- ))
100
- assert_equal '%Y-%m-%d', format.format_datetime_format
101
- end
102
-
103
- def test_padding_format_attribute_readers
104
- format = TextBlock::Format.new(TEXT_BLOCK_FORMAT.merge(
105
- 'format' => {
106
- 'type' => 'padding',
107
- 'padding' => {
108
- 'char' => '0',
109
- 'length' => 10,
110
- 'direction' => 'L'
111
- }
112
- }
113
- ))
114
- assert_equal '0', format.format_padding_char
115
- assert_equal 'L', format.format_padding_dir
116
- end
117
-
118
- def test_format_padding_length
119
- format = TextBlock::Format.new(TEXT_BLOCK_FORMAT.merge(
120
- 'format' => {
121
- 'type' => 'padding',
122
- 'padding' => {
123
- 'char' => '0',
124
- 'length' => 10,
125
- 'direction' => 'L'
126
- }
127
- }
128
- ))
129
- assert_equal 10, format.format_padding_length
130
-
131
- format = TextBlock::Format.new(TEXT_BLOCK_FORMAT.merge(
132
- 'format' => {
133
- 'type' => 'padding',
134
- 'padding' => {
135
- 'char' => '0',
136
- 'length' => '',
137
- 'direction' => 'L'
138
- }
139
- }
140
- ))
141
- assert_equal 0, format.format_padding_length
142
- end
143
-
144
- def test_format_padding_rdir?
145
- format_direction_left = TextBlock::Format.new(TEXT_BLOCK_FORMAT.merge(
146
- 'format' => {
147
- 'type' => 'padding',
148
- 'padding' => {
149
- 'char' => '0',
150
- 'length' => 10,
151
- 'direction' => 'L'
152
- }
153
- }
154
- ))
155
- assert_equal false, format_direction_left.format_padding_rdir?
156
-
157
- format_direction_right = TextBlock::Format.new(TEXT_BLOCK_FORMAT.merge(
158
- 'format' => {
159
- 'type' => 'padding',
160
- 'padding' => {
161
- 'char' => '0',
162
- 'length' => 10,
163
- 'direction' => 'R'
164
- }
165
- }
166
- ))
167
- assert_equal true, format_direction_right.format_padding_rdir?
168
- end
169
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Core::Shape::TextBlock::TestFormatter < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- # Alias
9
- Formatter = Thinreports::Core::Shape::TextBlock::Formatter
10
-
11
- def test_initialize_formatter_by_type
12
- assert_instance_of Formatter::Basic,
13
- Formatter.setup( stub(format_type: '') )
14
-
15
- assert_instance_of Formatter::Number,
16
- Formatter.setup( stub(format_type: 'number') )
17
-
18
- assert_instance_of Formatter::Datetime,
19
- Formatter.setup( stub(format_type: 'datetime') )
20
-
21
- assert_instance_of Formatter::Padding,
22
- Formatter.setup( stub(format_type: 'padding') )
23
-
24
- assert_raises Thinreports::Errors::UnknownFormatterType do
25
- Formatter.setup( stub(format_type: 'unknown') )
26
- end
27
- end
28
- end
@@ -1,63 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Core::Shape::TextBlock::TestInterface < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- # Alias
9
- TextBlock = Thinreports::Core::Shape::TextBlock
10
-
11
- def create_interface(format_config = {})
12
- report = Thinreports::Report.new layout: layout_file.path
13
- parent = report.start_new_page
14
-
15
- TextBlock::Interface.new parent, TextBlock::Format.new(format_config)
16
- end
17
-
18
- def test_format_enabled_asker_should_operate_as_delegator_of_internal
19
- tblock = create_interface('format' => {'type' => 'datetime'})
20
- assert_equal tblock.format_enabled?, tblock.internal.format_enabled?
21
- end
22
-
23
- def test_format_enabled_should_properly_set_value_to_internal
24
- tblock = create_interface('format' => {'type' => 'number'})
25
- tblock.format_enabled(false)
26
-
27
- assert_equal tblock.internal.format_enabled?, false
28
- end
29
-
30
- def test_set_should_properly_set_a_value
31
- tblock = create_interface
32
- tblock.set(1000, visible: false)
33
-
34
- assert_equal tblock.value, 1000
35
- end
36
-
37
- def test_set_should_properly_set_styles
38
- tblock = create_interface
39
- tblock.set(1000, color: '#ff0000',
40
- bold: true,
41
- italic: true)
42
-
43
- assert_equal [tblock.style(:color),
44
- tblock.style(:bold),
45
- tblock.style(:italic)],
46
- ['#ff0000', true, true]
47
- end
48
-
49
- def test_value=
50
- report = Thinreports::Report.new layout: layout_file.path
51
- page = report.start_new_page
52
-
53
- page.item(:text_block).value = 'foo'
54
- assert_equal 'foo', page.item(:text_block).value
55
-
56
- page.item(:text_block).value += 'bar'
57
- assert_equal 'foobar', page.item(:text_block).value
58
-
59
- page.item(:text_block).value = 1000
60
- page.item(:text_block).value += 999
61
- assert_equal 1999, page.item(:text_block).value
62
- end
63
- end
@@ -1,128 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Core::Shape::TextBlock::TestInternal < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- # Alias
9
- TextBlock = Thinreports::Core::Shape::TextBlock
10
-
11
- def create_parent
12
- report = Thinreports::Report.new layout: layout_file.path
13
- report.start_new_page do |page|
14
- # Add to force TextBlock shape.
15
- page.manager.format.shapes[:foo] = TextBlock::Format.new('type' => 'text-block',
16
- 'id' => 'foo')
17
- # Set value to TextBlock.
18
- page.item(:foo).value('foo value')
19
- end
20
- end
21
-
22
- def create_internal(format_config = {})
23
- TextBlock::Internal.new(create_parent, TextBlock::Format.new(format_config))
24
- end
25
-
26
- def test_multiple_asker_should_operate_as_delegator_of_format
27
- tblock = create_internal('multiple-line' => true)
28
- assert_equal tblock.multiple?, tblock.format.multiple?
29
- end
30
-
31
- def test_style_should_return_the_instance_of_Style_Text
32
- assert_instance_of Thinreports::Core::Shape::Style::Text, create_internal.style
33
- end
34
-
35
- def test_read_value_should_return_the_format_value_as_default
36
- tblock = create_internal('value' => 'default value')
37
- assert_equal tblock.read_value, 'default value'
38
- end
39
-
40
- def test_read_value_should_return_the_value_of_referenced_shape
41
- tblock = create_internal('reference-id' => 'foo', 'value' => '')
42
- assert_equal tblock.read_value, 'foo value'
43
- end
44
-
45
- def test_read_value_should_return_the_value_stored_in_states
46
- tblock = create_internal
47
- tblock.states[:value] = 'value in states'
48
-
49
- assert_equal tblock.read_value, 'value in states'
50
- end
51
-
52
- def test_write_value_should_properly_set_the_specified_value_to_states
53
- tblock = create_internal
54
- tblock.write_value(1000)
55
-
56
- assert_equal tblock.states[:value], 1000
57
- end
58
-
59
- def test_write_value_should_show_warnings_when_tblock_has_reference
60
- tblock = create_internal('id' => 'bar', 'reference-id' => 'foo')
61
- _out, err = capture_io do
62
- tblock.write_value('value')
63
- end
64
- assert_equal err.chomp, 'The set value was not saved, ' +
65
- "Because 'bar' has reference to 'foo'."
66
- end
67
-
68
- def test_real_value_should_return_the_formatted_value_when_tblock_has_any_format
69
- tblock = create_internal('format' => {'type' => 'datetime',
70
- 'datetime' => {'format' => '%Y/%m/%d'}})
71
- tblock.write_value(value = Time.now)
72
-
73
- assert_equal tblock.real_value, value.strftime('%Y/%m/%d')
74
- end
75
-
76
- def test_real_value_should_return_the_raw_value_when_tblock_has_no_format
77
- tblock = create_internal
78
- tblock.write_value('any value')
79
-
80
- assert_equal tblock.real_value, 'any value'
81
- end
82
-
83
- def test_format_enabled_should_properly_set_value_to_states_as_format_enabled
84
- tblock = create_internal
85
- tblock.format_enabled(false)
86
-
87
- assert_equal tblock.states[:format_enabled], false
88
- end
89
-
90
- def test_format_enabled_asker_should_return_true_when_format_has_any_type
91
- tblock = create_internal('format' => {'type' => 'datetime'})
92
-
93
- assert_equal tblock.format_enabled?, true
94
- end
95
-
96
- def test_format_enabled_asker_should_return_true_when_base_of_format_has_any_value
97
- tblock = create_internal('format' => {'base' => '{value}'})
98
-
99
- assert_equal tblock.format_enabled?, true
100
- end
101
-
102
- def test_format_enabled_asker_should_return_false_when_format_has_no_type_and_base_has_not_value
103
- assert_equal create_internal.format_enabled?, false
104
- end
105
-
106
- def test_format_enabled_asker_should_return_false_constantly_when_tblock_is_multiple_mode
107
- tblock = create_internal('multiple-line' => true,
108
- 'format' => {'base' => '{value}',
109
- 'type' => 'number'})
110
- tblock.format_enabled(true)
111
-
112
- assert_equal tblock.format_enabled?, false
113
- end
114
-
115
- def test_type_of_asker_should_return_true_when_value_is_tblock
116
- assert_equal create_internal.type_of?('text-block'), true
117
- end
118
-
119
- def test_type_of_asker_should_return_true_when_value_is_block
120
- assert_equal create_internal.type_of?(:block), true
121
- end
122
-
123
- def test_formatter_should_return_instance_of_FormatterBasic_when_format_is_enable
124
- tblock = create_internal('format' => {'type' => 'datetime'})
125
-
126
- assert_kind_of TextBlock::Formatter::Basic, tblock.send(:formatter)
127
- end
128
- end
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Core::TestShape < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- # Alias
9
- ShapeModule = Thinreports::Core::Shape
10
-
11
- def test_find_by_type_should_return_PageNumber
12
- assert_same ShapeModule.find_by_type('page-number'), ShapeModule::PageNumber
13
- end
14
-
15
- def test_find_by_type_should_return_ImageBlock
16
- assert_same ShapeModule.find_by_type('image-block'), ShapeModule::ImageBlock
17
- end
18
-
19
- def test_find_by_type_should_return_TextBlock
20
- assert_same ShapeModule.find_by_type('text-block'), ShapeModule::TextBlock
21
- end
22
-
23
- def test_find_by_type_should_return_List
24
- assert_same ShapeModule.find_by_type('list'), ShapeModule::List
25
- end
26
-
27
- def test_find_by_type_should_return_Text
28
- assert_same ShapeModule.find_by_type('text'), ShapeModule::Text
29
- end
30
-
31
- def test_find_by_type_should_return_Basic_as_Image
32
- assert_same ShapeModule.find_by_type('image'), ShapeModule::Basic
33
- end
34
-
35
- def test_find_by_type_should_return_Basic_as_Line
36
- assert_same ShapeModule.find_by_type('line'), ShapeModule::Basic
37
- end
38
-
39
- def test_find_by_type_should_return_Basic_as_Rect
40
- assert_same ShapeModule.find_by_type('rect'), ShapeModule::Basic
41
- end
42
-
43
- def test_find_by_type_should_return_Basic_as_Ellipse
44
- assert_same ShapeModule.find_by_type('ellipse'), ShapeModule::Basic
45
- end
46
-
47
- def test_find_by_type_should_raise
48
- assert_raises Thinreports::Errors::UnknownShapeType do
49
- ShapeModule.find_by_type('unknown')
50
- end
51
- end
52
- end
@@ -1,68 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Core::TestShape < Minitest::Test
6
- include Thinreports::TestHelper
7
- include Thinreports::Utils
8
-
9
- def test_call_block_in
10
- expected = '123'
11
- assert_same expected, call_block_in(expected)
12
-
13
- assert_equal [1, 2, 3], call_block_in([2, 1, 3], &proc { sort! })
14
- assert_equal [1, 2, 3], call_block_in([2, 1, 3], &proc { |a| a.sort! })
15
- end
16
-
17
- def test_deep_copy_in_unsupported_object
18
- [123, nil, Struct.new(:foo).new].each do |unsupported_value|
19
- assert_raises ArgumentError do
20
- deep_copy(unsupported_value)
21
- end
22
- end
23
- end
24
-
25
- def test_deep_copy_in_Array
26
- src = ['string', Time.now]
27
- dup = deep_copy(src)
28
-
29
- refute_same dup, src
30
-
31
- src.each_with_index do |e, i|
32
- assert_equal dup[i], e
33
- refute_same dup[i], e
34
- end
35
- end
36
-
37
- def test_deep_copy_in_Hash
38
- src = { a: 'string', b: Time.now }
39
- dup = deep_copy(src)
40
-
41
- refute_same dup, src
42
-
43
- src.each do |k, v|
44
- assert_equal dup[k], v
45
- refute_same dup[k], v
46
- end
47
- end
48
-
49
- def test_blank_value_in_String
50
- ["", ''].each do |val|
51
- assert_equal true, blank_value?(val)
52
- end
53
-
54
- [' ', ' ', 'abc', 'あいう'].each do |val|
55
- assert_equal false, blank_value?(val)
56
- end
57
- end
58
-
59
- def test_blank_value_in_NilClass
60
- assert_equal true, blank_value?(nil)
61
- end
62
-
63
- def test_blank_value_in_other_classes
64
- [0, 1, -1, 9.99, true, false, Time.now].each do |val|
65
- assert_equal false, blank_value?(val)
66
- end
67
- end
68
- end
@@ -1,135 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Generator::PDF::Graphics::TestAttributes < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- def setup
9
- @pdf = Thinreports::Generator::PDF::Document.new
10
- end
11
-
12
- def test_build_graphic_attributes
13
- graphic_styles = {
14
- 'border-color' => '#ff0000',
15
- 'border-width' => 2.0,
16
- 'border-style' => 'solid',
17
- 'fill-color' => '#000000'
18
- }
19
-
20
- assert_equal(
21
- {
22
- stroke: '#ff0000',
23
- stroke_width: 2.0,
24
- stroke_type: 'solid',
25
- fill: '#000000'
26
- },
27
- @pdf.build_graphic_attributes(graphic_styles)
28
- )
29
-
30
- customized_attributes = @pdf.build_graphic_attributes(graphic_styles) { |attrs| attrs[:stroke] = 'blue' }
31
- assert_equal 'blue', customized_attributes[:stroke]
32
- end
33
-
34
- def test_build_text_attributes
35
- text_styles = {
36
- 'font-family' => %w( Helvetica IPAMincho ),
37
- 'font-size' => 18.0,
38
- 'color' => 'red',
39
- 'text-align' => 'right',
40
- 'vertical-align' => 'bottom',
41
- 'font-style' => %w( bold italic ),
42
- 'letter-spacing' => 2.0,
43
- 'line-height' => 20.0,
44
- 'overflow' => 'expand',
45
- 'word-wrap' => 'break-word'
46
- }
47
-
48
- assert_equal(
49
- {
50
- font: 'Helvetica',
51
- size: 18.0,
52
- color: 'red',
53
- align: :right,
54
- valign: :bottom,
55
- styles: [:bold, :italic],
56
- letter_spacing: 2.0,
57
- line_height: 20.0,
58
- overflow: :expand,
59
- word_wrap: :break_word
60
- },
61
- @pdf.build_text_attributes(text_styles)
62
- )
63
-
64
- customized_attributes = @pdf.build_text_attributes(text_styles) { |attrs| attrs[:color] = 'blue' }
65
- assert_equal 'blue', customized_attributes[:color]
66
- end
67
-
68
- def test_font_family
69
- assert_equal 'IPAGothic', @pdf.font_family(%w( IPAGothic Helvetica ))
70
- assert_equal 'Helvetica', @pdf.font_family(%w( Unknown IPAMincho ))
71
- end
72
-
73
- def test_font_styles
74
- assert_equal [:bold, :italic, :underline, :strikethrough],
75
- @pdf.font_styles(%w( bold italic underline linethrough ))
76
- end
77
-
78
- def test_letter_spacing
79
- assert_equal 2.0, @pdf.letter_spacing(2.0)
80
- assert_nil @pdf.letter_spacing('')
81
- assert_nil @pdf.letter_spacing(nil)
82
- end
83
-
84
- def test_text_align
85
- assert_equal :left, @pdf.text_align('left')
86
- assert_equal :center, @pdf.text_align('center')
87
- assert_equal :right, @pdf.text_align('right')
88
- assert_equal :left, @pdf.text_align('')
89
- assert_equal :left, @pdf.text_align(nil)
90
- end
91
-
92
- def test_text_valign
93
- assert_equal :top, @pdf.text_valign('top')
94
- assert_equal :center, @pdf.text_valign('middle')
95
- assert_equal :bottom, @pdf.text_valign('bottom')
96
- assert_equal :top, @pdf.text_valign('')
97
- assert_equal :top, @pdf.text_valign(nil)
98
- end
99
-
100
- def test_text_overflow
101
- assert_equal :truncate, @pdf.text_overflow('truncate')
102
- assert_equal :shrink_to_fit, @pdf.text_overflow('fit')
103
- assert_equal :expand, @pdf.text_overflow('expand')
104
- assert_equal :truncate, @pdf.text_overflow('')
105
- assert_equal :truncate, @pdf.text_overflow(nil)
106
- end
107
-
108
- def test_word_wrap
109
- assert_equal :break_word, @pdf.word_wrap('break-word')
110
- assert_equal :none, @pdf.word_wrap('none')
111
- assert_equal :none, @pdf.word_wrap(nil)
112
- end
113
-
114
- def test_line_height
115
- assert_equal 20.9, @pdf.line_height(20.9)
116
- assert_nil @pdf.line_height('')
117
- assert_nil @pdf.line_height(nil)
118
- end
119
-
120
- def test_image_position_x
121
- assert_equal :left, @pdf.image_position_x('left')
122
- assert_equal :center, @pdf.image_position_x('center')
123
- assert_equal :right, @pdf.image_position_x('right')
124
- assert_equal :left, @pdf.image_position_x('')
125
- assert_equal :left, @pdf.image_position_x(nil)
126
- end
127
-
128
- def test_image_position_y
129
- assert_equal :top, @pdf.image_position_y('top')
130
- assert_equal :center, @pdf.image_position_y('middle')
131
- assert_equal :bottom, @pdf.image_position_y('bottom')
132
- assert_equal :top, @pdf.image_position_y('')
133
- assert_equal :top, @pdf.image_position_y(nil)
134
- end
135
- end
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Generator::PDF::Graphics::TestBasic < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- def setup
9
- @pdf = Thinreports::Generator::PDF::Document.new
10
- end
11
-
12
- def test_build_stroke_styles
13
- style = {
14
- stroke: 'red',
15
- stroke_width: 2.0,
16
- stroke_type: 'solid'
17
- }
18
-
19
- assert_equal(
20
- {
21
- color: 'ff0000',
22
- width: 2.0,
23
- dash: nil
24
- },
25
- @pdf.build_stroke_styles(style)
26
- )
27
-
28
- style_stroke_dashed = style.merge(stroke_type: 'dashed')
29
- assert_equal [2, 2], @pdf.build_stroke_styles(style_stroke_dashed)[:dash]
30
-
31
- style_stroke_dotted = style.merge(stroke_type: 'dotted')
32
- assert_equal [1, 2], @pdf.build_stroke_styles(style_stroke_dotted)[:dash]
33
-
34
- assert_nil @pdf.build_stroke_styles(stroke: nil, stroke_width: 1)
35
- assert_nil @pdf.build_stroke_styles(stroke: 'none', stroke_width: 1)
36
-
37
- assert_nil @pdf.build_stroke_styles(stroke_width: nil, stroke: 'red')
38
- assert_nil @pdf.build_stroke_styles(stroke_width: 0, stroke: 'red')
39
- end
40
-
41
- def test_build_fill_styles
42
- assert_equal({ color: 'ff0000' }, @pdf.build_fill_styles(fill: 'red'))
43
- assert_nil @pdf.build_fill_styles(fill: nil)
44
- assert_nil @pdf.build_fill_styles(fill: 'none')
45
- end
46
- end