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
@@ -4,16 +4,16 @@ require 'test_helper'
4
4
 
5
5
  class Thinreports::Core::Shape::Text::TestInternal < Minitest::Test
6
6
  include Thinreports::TestHelper
7
-
7
+
8
8
  Text = Thinreports::Core::Shape::Text
9
-
9
+
10
10
  def create_internal(format_config = {})
11
- report = new_report('layout_text1.tlf')
11
+ report = Thinreports::Report.new layout: layout_file.path
12
12
  Text::Internal.new(report.start_new_page, Text::Format.new(format_config))
13
13
  end
14
-
14
+
15
15
  def test_type_of?
16
- assert create_internal.type_of?(:text), true
16
+ assert create_internal.type_of?('text'), true
17
17
  refute create_internal.type_of?(:basic), false
18
18
  end
19
19
 
@@ -4,16 +4,16 @@ require 'test_helper'
4
4
 
5
5
  class Thinreports::Core::Shape::TextBlock::Formatter::TestDatetime < Minitest::Test
6
6
  include Thinreports::TestHelper
7
-
7
+
8
8
  # Aliases
9
9
  TextBlock = Thinreports::Core::Shape::TextBlock
10
10
  Formatter = TextBlock::Formatter::Datetime
11
-
11
+
12
12
  def setup
13
13
  @datetime_format = '%Y/%m/%d %H:%M:%S'
14
14
  @time = Time.now
15
15
  end
16
-
16
+
17
17
  def text_block_format(format = {})
18
18
  default = {'base' => '', 'datetime' => {'format' => '%Y/%m/%d %H:%M:%S'}}
19
19
  TextBlock::Format.new('format' => default.merge(format))
@@ -21,29 +21,29 @@ class Thinreports::Core::Shape::TextBlock::Formatter::TestDatetime < Minitest::T
21
21
 
22
22
  def test_apply_datetime_format_without_basic_format
23
23
  formatter = Formatter.new(text_block_format)
24
-
25
- assert_equal @time.strftime(@datetime_format),
24
+
25
+ assert_equal @time.strftime(@datetime_format),
26
26
  formatter.apply(@time)
27
27
  end
28
-
28
+
29
29
  def test_apply_datetime_format_with_basic_format
30
30
  formatter = Formatter.new(text_block_format('base' => 'Now: {value}'))
31
-
32
- assert_equal "Now: #{@time.strftime(@datetime_format)}",
31
+
32
+ assert_equal "Now: #{@time.strftime(@datetime_format)}",
33
33
  formatter.apply(@time)
34
-
34
+
35
35
  end
36
-
36
+
37
37
  def test_not_apply_datetime_format_and_return_raw_value
38
38
  # When value is invalid
39
39
  formatter = Formatter.new(text_block_format)
40
-
40
+
41
41
  assert_same formatter.apply(val = 'invalid value'), val
42
42
  assert_same formatter.apply(val = 123456), val
43
-
43
+
44
44
  # When format is empty
45
45
  formatter = Formatter.new(text_block_format('datetime' => {'format' => ''}))
46
-
46
+
47
47
  assert_same formatter.apply(@time), @time
48
48
  end
49
49
  end
@@ -5,166 +5,165 @@ require 'test_helper'
5
5
  class Thinreports::Core::Shape::TextBlock::TestFormat < Minitest::Test
6
6
  include Thinreports::TestHelper
7
7
 
8
- TEST_TBLOCK_FORMAT = {
9
- "type" => "s-tblock",
10
- "id" => "block_1",
11
- "display" => "true",
12
- "multiple" => "false",
13
- "overflow" => "truncate",
14
- "word-wrap" => "break-word",
15
- "box" => {
16
- "x" => 100.0,
17
- "y" => 100.0,
18
- "width" => 100.0,
19
- "height" => 100.0
20
- },
21
- "format" => {
22
- "base" => "¥{value}",
23
- "type" => "number",
24
- "number" => {
25
- "delimiter" => ",",
26
- "precision" => 1
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
27
25
  }
28
26
  },
29
- "value" => "",
30
- "ref-id" => "",
31
- "svg" => {
32
- "tag" => "text",
33
- "attrs" => {
34
- "x" => 200.1,
35
- "y" => 65.6,
36
- "text-anchor" => "end",
37
- "xml:space" => "preserve",
38
- "fill" => "#000000",
39
- "fill-opacity" => "1",
40
- "font-size" => "12",
41
- "font-family" => "Helvetica",
42
- "font-weight" => "bold",
43
- "font-style" => "normal",
44
- "text-decoration" => "none",
45
- "clip-path" => "url(#_svgdef_0)"
46
- }
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
47
40
  }
48
41
  }
49
42
 
50
- def test_build
51
- build_format
52
- rescue => e
53
- flunk exception_details(e, 'Building failed.')
54
- end
43
+ TextBlock = Thinreports::Core::Shape::TextBlock
55
44
 
56
- def test_value_reader_via_TEST_TBLOCK_FORMAT
57
- assert_equal format(TEST_TBLOCK_FORMAT).value, ''
58
- end
45
+ def test_attribute_readers
46
+ format = TextBlock::Format.new(TEXT_BLOCK_FORMAT)
59
47
 
60
- def test_word_wrap_reader_via_TEST_TBLOCK_FORMAT
61
- assert_equal format(TEST_TBLOCK_FORMAT).word_wrap, 'break-word'
62
- end
63
-
64
- def test_ref_id_reader_via_TEST_TBLOCK_FORMAT
65
- assert_equal format(TEST_TBLOCK_FORMAT).ref_id, ''
66
- end
67
-
68
- def test_format_base_reader_via_TEST_TBLOCK_FORMAT
69
- assert_equal format(TEST_TBLOCK_FORMAT).format_base, '¥{value}'
70
- end
71
-
72
- def test_format_type_reader_via_TEST_TBLOCK_FORMAT
73
- assert_equal format(TEST_TBLOCK_FORMAT).format_type, 'number'
74
- end
75
-
76
- def test_box_reader_via_TEST_TBLOCK_FORMAT
77
- assert_equal format(TEST_TBLOCK_FORMAT).box.values_at('x', 'y', 'width', 'height'),
78
- [100.0, 100.0, 100.0, 100.0]
79
- end
80
-
81
- def test_format_datetime_format_reader_via_TEST_TBLOCK_FORMAT
82
- assert_nil format(TEST_TBLOCK_FORMAT).format_datetime_format
83
- end
84
-
85
- def test_format_padding_char_reader_via_TEST_TBLOCK_FORMAT
86
- assert_nil format(TEST_TBLOCK_FORMAT).format_padding_char
87
- end
88
-
89
- def test_format_padding_dir_reader_via_TEST_TBLOCK_FORMAT
90
- assert_nil format(TEST_TBLOCK_FORMAT).format_padding_dir
91
- end
92
-
93
- def test_format_padding_length_via_TEST_TBLOCK_FORMAT
94
- assert_equal format(TEST_TBLOCK_FORMAT).format_padding_length, 0
95
- end
96
-
97
- def test_format_padding_rdir_checker_via_TEST_TBLOCK_FORMAT
98
- assert_equal format(TEST_TBLOCK_FORMAT).format_padding_rdir?, false
99
- end
100
-
101
- def test_format_has_format_asker_via_TEST_TBLOCK_FORMAT
102
- assert_equal format(TEST_TBLOCK_FORMAT).has_format?, true
103
- end
104
-
105
- def test_format_has_reference_asker_via_TEST_TBLOCK_FORMAT
106
- assert_equal format(TEST_TBLOCK_FORMAT).has_reference?, false
107
- end
108
-
109
- def test_format_multiple_checker_via_TEST_TBLOCK_FORMAT
110
- assert_equal format(TEST_TBLOCK_FORMAT).multiple?, false
111
- end
112
-
113
- def test_overflow_via_TEST_TBLOCK_FORMAT
114
- assert_equal format(TEST_TBLOCK_FORMAT).overflow, 'truncate'
115
- end
116
-
117
- def test_multiple_checker_should_return_true
118
- assert format('multiple' => 'true').multiple?
119
- end
120
-
121
- def test_multiple_checker_should_return_false
122
- refute format('multiple' => 'false').multiple?
123
- end
124
-
125
- def test_format_padding_rdir_checker_should_return_false
126
- data = {'format' => {'padding' => {'direction' => 'L'}}}
127
- refute format(data).format_padding_rdir?
128
- end
129
-
130
- def test_format_padding_rdir_checker_should_return_true
131
- data = {'format' => {'padding' => {'direction' => 'R'}}}
132
- assert format(data).format_padding_rdir?
133
- end
134
-
135
- def test_format_padding_length_should_return_Numeric
136
- data = {'format' => {'padding' => {'length' => '999'}}}
137
- assert_kind_of ::Numeric, format(data).format_padding_length
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
138
55
  end
139
56
 
140
- def test_has_format_asker_should_return_false_with_empty_value
141
- data = {'format' => {'type' => ''}}
142
- refute format(data).has_format?
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?
143
63
  end
144
-
145
- def test_has_format_asker_should_return_false_with_unknown_type
146
- data = {'format' => {'type' => 'unknown'}}
147
- refute format(data).has_format?
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?
148
75
  end
149
-
150
- def test_has_format_asker_should_return_true
151
- data = {'format' => {'type' => 'number'}}
152
- assert format(data).has_format?
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
153
89
  end
154
-
155
- def test_has_reference_asker_should_return_false
156
- refute format('ref-id' => '').has_reference?
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
157
101
  end
158
-
159
- def test_has_reference_asker_should_return_true
160
- assert format('ref-id' => 'ref_tblock_1').has_reference?
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
161
116
  end
162
-
163
- def build_format
164
- Thinreports::Core::Shape::TextBlock::Format.build(TEST_TBLOCK_FORMAT)
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
165
142
  end
166
-
167
- def format(data)
168
- Thinreports::Core::Shape::TextBlock::Format.new(data)
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?
169
168
  end
170
169
  end
@@ -9,7 +9,7 @@ class Thinreports::Core::Shape::TextBlock::TestInterface < Minitest::Test
9
9
  TextBlock = Thinreports::Core::Shape::TextBlock
10
10
 
11
11
  def create_interface(format_config = {})
12
- report = new_report 'layout_text1'
12
+ report = Thinreports::Report.new layout: layout_file.path
13
13
  parent = report.start_new_page
14
14
 
15
15
  TextBlock::Interface.new parent, TextBlock::Format.new(format_config)
@@ -47,17 +47,17 @@ class Thinreports::Core::Shape::TextBlock::TestInterface < Minitest::Test
47
47
  end
48
48
 
49
49
  def test_value=
50
- report = new_report 'layout_block.tlf'
50
+ report = Thinreports::Report.new layout: layout_file.path
51
51
  page = report.start_new_page
52
52
 
53
- page.item(:text_block1).value = 'foo'
54
- assert_equal 'foo', page.item(:text_block1).value
53
+ page.item(:text_block).value = 'foo'
54
+ assert_equal 'foo', page.item(:text_block).value
55
55
 
56
- page.item(:text_block1).value += 'bar'
57
- assert_equal 'foobar', page.item(:text_block1).value
56
+ page.item(:text_block).value += 'bar'
57
+ assert_equal 'foobar', page.item(:text_block).value
58
58
 
59
- page.item(:text_block1).value = 1000
60
- page.item(:text_block1).value += 999
61
- assert_equal 1999, page.item(:text_block1).value
59
+ page.item(:text_block).value = 1000
60
+ page.item(:text_block).value += 999
61
+ assert_equal 1999, page.item(:text_block).value
62
62
  end
63
63
  end
@@ -9,10 +9,10 @@ class Thinreports::Core::Shape::TextBlock::TestInternal < Minitest::Test
9
9
  TextBlock = Thinreports::Core::Shape::TextBlock
10
10
 
11
11
  def create_parent
12
- report = new_report('layout_text1.tlf')
12
+ report = Thinreports::Report.new layout: layout_file.path
13
13
  report.start_new_page do |page|
14
14
  # Add to force TextBlock shape.
15
- page.manager.format.shapes[:foo] = TextBlock::Format.new('type' => 's-tblock',
15
+ page.manager.format.shapes[:foo] = TextBlock::Format.new('type' => 'text-block',
16
16
  'id' => 'foo')
17
17
  # Set value to TextBlock.
18
18
  page.item(:foo).value('foo value')
@@ -24,7 +24,7 @@ class Thinreports::Core::Shape::TextBlock::TestInternal < Minitest::Test
24
24
  end
25
25
 
26
26
  def test_multiple_asker_should_operate_as_delegator_of_format
27
- tblock = create_internal('multiple' => 'true')
27
+ tblock = create_internal('multiple-line' => true)
28
28
  assert_equal tblock.multiple?, tblock.format.multiple?
29
29
  end
30
30
 
@@ -38,7 +38,7 @@ class Thinreports::Core::Shape::TextBlock::TestInternal < Minitest::Test
38
38
  end
39
39
 
40
40
  def test_read_value_should_return_the_value_of_referenced_shape
41
- tblock = create_internal('ref-id' => 'foo')
41
+ tblock = create_internal('reference-id' => 'foo', 'value' => '')
42
42
  assert_equal tblock.read_value, 'foo value'
43
43
  end
44
44
 
@@ -57,7 +57,7 @@ class Thinreports::Core::Shape::TextBlock::TestInternal < Minitest::Test
57
57
  end
58
58
 
59
59
  def test_write_value_should_show_warnings_when_tblock_has_reference
60
- tblock = create_internal('id' => 'bar', 'ref-id' => 'foo')
60
+ tblock = create_internal('id' => 'bar', 'reference-id' => 'foo')
61
61
  _out, err = capture_io do
62
62
  tblock.write_value('value')
63
63
  end
@@ -104,16 +104,16 @@ class Thinreports::Core::Shape::TextBlock::TestInternal < Minitest::Test
104
104
  end
105
105
 
106
106
  def test_format_enabled_asker_should_return_false_constantly_when_tblock_is_multiple_mode
107
- tblock = create_internal('multiple' => 'true',
108
- 'format' => {'base' => '{value}',
109
- 'type' => 'number'})
107
+ tblock = create_internal('multiple-line' => true,
108
+ 'format' => {'base' => '{value}',
109
+ 'type' => 'number'})
110
110
  tblock.format_enabled(true)
111
111
 
112
112
  assert_equal tblock.format_enabled?, false
113
113
  end
114
114
 
115
115
  def test_type_of_asker_should_return_true_when_value_is_tblock
116
- assert_equal create_internal.type_of?(:tblock), true
116
+ assert_equal create_internal.type_of?('text-block'), true
117
117
  end
118
118
 
119
119
  def test_type_of_asker_should_return_true_when_value_is_block