thinreports 0.6.0.pre3 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. data/README.rdoc +37 -32
  2. data/doc/yardoc_templates/default/layout/html/footer.erb +1 -1
  3. data/lib/thinreports.rb +2 -1
  4. data/lib/thinreports/config.rb +21 -0
  5. data/lib/thinreports/core/errors.rb +14 -1
  6. data/lib/thinreports/core/format/builder.rb +6 -1
  7. data/lib/thinreports/core/page.rb +6 -6
  8. data/lib/thinreports/core/shape.rb +8 -9
  9. data/lib/thinreports/core/shape/base/internal.rb +6 -12
  10. data/lib/thinreports/core/shape/basic.rb +3 -0
  11. data/lib/thinreports/core/shape/basic/block_format.rb +12 -0
  12. data/lib/thinreports/core/shape/basic/block_interface.rb +25 -0
  13. data/lib/thinreports/core/shape/basic/block_internal.rb +33 -0
  14. data/lib/thinreports/core/shape/basic/interface.rb +37 -11
  15. data/lib/thinreports/core/shape/basic/internal.rb +3 -12
  16. data/lib/thinreports/core/shape/image_block.rb +15 -0
  17. data/lib/thinreports/core/shape/image_block/format.rb +13 -0
  18. data/lib/thinreports/core/shape/image_block/interface.rb +19 -0
  19. data/lib/thinreports/core/shape/image_block/internal.rb +16 -0
  20. data/lib/thinreports/core/shape/list/events.rb +19 -2
  21. data/lib/thinreports/core/shape/list/manager.rb +17 -4
  22. data/lib/thinreports/core/shape/list/page.rb +2 -2
  23. data/lib/thinreports/core/shape/list/page_state.rb +4 -0
  24. data/lib/thinreports/core/shape/list/section_internal.rb +4 -0
  25. data/lib/thinreports/core/shape/manager/format.rb +1 -1
  26. data/lib/thinreports/core/shape/manager/internal.rb +24 -11
  27. data/lib/thinreports/core/shape/manager/target.rb +2 -2
  28. data/lib/thinreports/core/shape/style.rb +15 -0
  29. data/lib/thinreports/core/shape/style/base.rb +149 -0
  30. data/lib/thinreports/core/shape/style/basic.rb +17 -0
  31. data/lib/thinreports/core/shape/style/graphic.rb +60 -0
  32. data/lib/thinreports/core/shape/style/text.rb +138 -0
  33. data/lib/thinreports/core/shape/text/internal.rb +4 -0
  34. data/lib/thinreports/core/shape/text_block.rb +16 -0
  35. data/lib/thinreports/core/shape/{tblock → text_block}/format.rb +3 -3
  36. data/lib/thinreports/core/shape/{tblock → text_block}/formatter.rb +7 -7
  37. data/lib/thinreports/core/shape/{tblock → text_block}/formatter/basic.rb +1 -1
  38. data/lib/thinreports/core/shape/{tblock → text_block}/formatter/datetime.rb +1 -1
  39. data/lib/thinreports/core/shape/{tblock → text_block}/formatter/number.rb +1 -1
  40. data/lib/thinreports/core/shape/{tblock → text_block}/formatter/padding.rb +10 -8
  41. data/lib/thinreports/core/shape/{tblock → text_block}/interface.rb +2 -21
  42. data/lib/thinreports/core/shape/{tblock → text_block}/internal.rb +16 -10
  43. data/lib/thinreports/core/utils.rb +0 -8
  44. data/lib/thinreports/generator.rb +2 -2
  45. data/lib/thinreports/generator/configuration.rb +30 -0
  46. data/lib/thinreports/generator/pdf.rb +13 -10
  47. data/lib/thinreports/generator/pdf/configuration.rb +28 -0
  48. data/lib/thinreports/generator/pdf/document.rb +16 -56
  49. data/lib/thinreports/generator/pdf/document/draw_shape.rb +35 -17
  50. data/lib/thinreports/generator/pdf/document/font.rb +25 -9
  51. data/lib/thinreports/generator/pdf/document/graphics.rb +1 -1
  52. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +18 -4
  53. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +1 -1
  54. data/lib/thinreports/generator/pdf/document/graphics/image.rb +18 -1
  55. data/lib/thinreports/generator/pdf/document/graphics/text.rb +29 -6
  56. data/lib/thinreports/generator/pdf/document/page.rb +70 -0
  57. data/lib/thinreports/generator/pdf/document/parse_color.rb +1 -1
  58. data/lib/thinreports/generator/pdf/document/parse_svg.rb +1 -1
  59. data/lib/thinreports/generator/pdf/drawer.rb +1 -1
  60. data/lib/thinreports/generator/pdf/drawer/base.rb +5 -7
  61. data/lib/thinreports/generator/pdf/drawer/list.rb +4 -4
  62. data/lib/thinreports/generator/pdf/drawer/list_section.rb +8 -3
  63. data/lib/thinreports/generator/pdf/drawer/page.rb +10 -3
  64. data/lib/thinreports/generator/pdf/prawn_ext.rb +16 -21
  65. data/lib/thinreports/layout/format.rb +2 -2
  66. data/lib/thinreports/layout/version.rb +2 -2
  67. data/lib/thinreports/report/base.rb +68 -31
  68. data/tasks/test.rake +48 -4
  69. data/test/benchmark/basic_estimate.tlf +1 -0
  70. data/test/benchmark/bench_basic_estimate.rb +95 -0
  71. data/test/case/character_spacing/character_spacing.rb +7 -0
  72. data/test/case/character_spacing/character_spacing.tlf +1 -0
  73. data/test/case/dynamic_image/dynamic_image.rb +41 -0
  74. data/test/case/dynamic_image/dynamic_image.tlf +1 -0
  75. data/test/case/dynamic_image/img200x100.png +0 -0
  76. data/test/case/dynamic_image/img50x50.png +0 -0
  77. data/test/case/dynamic_style/dynamic_style.rb +154 -0
  78. data/test/case/dynamic_style/dynamic_style.tlf +1 -0
  79. data/test/case/dynamic_style/dynamic_style_in_list.tlf +1 -0
  80. data/test/case/dynamic_style/image.png +0 -0
  81. data/test/case/eudc/eudc.rb +20 -0
  82. data/test/case/eudc/eudc.tlf +1 -0
  83. data/test/case/eudc/eudc.ttf +0 -0
  84. data/test/case/helper.rb +27 -0
  85. data/test/case/hidden_shapes/hidden_shapes.rb +13 -0
  86. data/test/case/hidden_shapes/hidden_shapes.tlf +1 -0
  87. data/test/case/list_events/list_events.rb +32 -0
  88. data/test/case/list_events/list_events.tlf +1 -0
  89. data/test/case/list_header_inheriting/list_header_inheriting.rb +19 -0
  90. data/test/case/list_header_inheriting/list_header_inheriting.tlf +1 -0
  91. data/test/case/list_manual_generation/list_manual_generation.rb +24 -0
  92. data/test/case/list_manual_generation/list_manual_generation.tlf +1 -0
  93. data/test/case/single_line_tblock/single_line_tblock.rb +15 -0
  94. data/test/case/single_line_tblock/single_line_tblock.tlf +1 -0
  95. data/test/case/tblock_styles/tblock_styles.rb +27 -0
  96. data/test/case/tblock_styles/tblock_styles.tlf +1 -0
  97. data/test/case/text_align/text_align.rb +9 -0
  98. data/test/case/text_align/text_align.tlf +1 -0
  99. data/test/unit/core/shape/base/test_internal.rb +65 -85
  100. data/test/unit/core/shape/basic/test_basic_format.rb +30 -0
  101. data/test/unit/core/shape/basic/test_basic_interface.rb +27 -0
  102. data/test/unit/core/shape/basic/test_basic_internal.rb +55 -0
  103. data/test/unit/core/shape/basic/test_interface.rb +84 -36
  104. data/test/unit/core/shape/basic/test_internal.rb +32 -24
  105. data/test/unit/core/shape/image_block/test_format.rb +58 -0
  106. data/test/unit/core/shape/image_block/test_interface.rb +23 -0
  107. data/test/unit/core/shape/image_block/test_internal.rb +28 -0
  108. data/test/unit/core/shape/list/test_events.rb +19 -11
  109. data/test/unit/core/shape/list/test_manager.rb +112 -0
  110. data/test/unit/core/shape/list/test_page.rb +57 -0
  111. data/test/unit/core/shape/list/test_section_format.rb +1 -1
  112. data/test/unit/core/shape/list/test_section_interface.rb +37 -30
  113. data/test/unit/core/shape/list/test_section_internal.rb +39 -14
  114. data/test/unit/core/shape/manager/test_format.rb +12 -18
  115. data/test/unit/core/shape/manager/test_internal.rb +127 -93
  116. data/test/unit/core/shape/manager/test_target.rb +63 -56
  117. data/test/unit/core/shape/styles/test_base.rb +219 -0
  118. data/test/unit/core/shape/styles/test_basic.rb +24 -0
  119. data/test/unit/core/shape/styles/test_graphic.rb +69 -0
  120. data/test/unit/core/shape/styles/test_text.rb +318 -0
  121. data/test/unit/core/shape/{tblock → text_block}/formatter/test_basic.rb +2 -2
  122. data/test/unit/core/shape/{tblock → text_block}/formatter/test_datetime.rb +2 -2
  123. data/test/unit/core/shape/{tblock → text_block}/formatter/test_number.rb +2 -2
  124. data/test/unit/core/shape/{tblock → text_block}/formatter/test_padding.rb +11 -6
  125. data/test/unit/core/shape/text_block/test_format.rb +160 -0
  126. data/test/unit/core/shape/{tblock → text_block}/test_formatter.rb +2 -2
  127. data/test/unit/core/shape/text_block/test_interface.rb +46 -0
  128. data/test/unit/core/shape/text_block/test_internal.rb +128 -0
  129. data/test/unit/core/test_shape.rb +31 -6
  130. data/test/unit/data/basic_layout1.tlf +1 -0
  131. data/test/unit/data/basic_layout2.tlf +1 -0
  132. data/test/unit/data/basic_list_layout.tlf +1 -0
  133. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +81 -52
  134. data/test/unit/generator/pdf/document/graphics/test_text.rb +159 -0
  135. data/test/unit/generator/pdf/document/test_font.rb +21 -6
  136. data/test/unit/generator/pdf/document/test_graphics.rb +2 -2
  137. data/test/unit/generator/pdf/document/test_page.rb +95 -0
  138. data/test/unit/generator/pdf/document/test_parse_color.rb +2 -2
  139. data/test/unit/generator/pdf/test_configuration.rb +24 -0
  140. data/test/unit/generator/pdf/test_document.rb +28 -0
  141. data/test/unit/generator/test_configuration.rb +25 -0
  142. data/test/unit/generator/test_pdf.rb +19 -0
  143. data/test/unit/helper.rb +18 -0
  144. data/test/unit/layout/test_format.rb +24 -7
  145. data/test/unit/layout/test_version.rb +61 -27
  146. data/test/unit/report/test_base.rb +185 -89
  147. data/test/unit/test_config.rb +22 -0
  148. data/test/unit/test_report.rb +4 -4
  149. metadata +94 -43
  150. data/lib/thinreports/core/shape/tblock.rb +0 -16
  151. data/lib/thinreports/generator/pxd.rb +0 -75
  152. data/lib/thinreports/generator/pxd/helper.rb +0 -33
  153. data/lib/thinreports/generator/pxd/list_renderer.rb +0 -58
  154. data/lib/thinreports/generator/pxd/page_renderer.rb +0 -75
  155. data/tasks/clean.rake +0 -6
  156. data/test/unit/core/shape/tblock/test_format.rb +0 -125
  157. data/test/unit/core/shape/tblock/test_interface.rb +0 -40
  158. data/test/unit/core/shape/tblock/test_internal.rb +0 -139
@@ -2,11 +2,11 @@
2
2
 
3
3
  require 'test/unit/helper'
4
4
 
5
- class ThinReports::Core::Shape::Tblock::Formatter::TestBasic < MiniTest::Unit::TestCase
5
+ class ThinReports::Core::Shape::TextBlock::Formatter::TestBasic < MiniTest::Unit::TestCase
6
6
  include ThinReports::TestHelpers
7
7
 
8
8
  # Alias
9
- Formatter = ThinReports::Core::Shape::Tblock::Formatter::Basic
9
+ Formatter = ThinReports::Core::Shape::TextBlock::Formatter::Basic
10
10
 
11
11
  def test_apply_simple_format
12
12
  format = flexmock(:format_base => 'Hello {value}!')
@@ -2,11 +2,11 @@
2
2
 
3
3
  require 'test/unit/helper'
4
4
 
5
- class ThinReports::Core::Shape::Tblock::Formatter::TestDatetime < MiniTest::Unit::TestCase
5
+ class ThinReports::Core::Shape::TextBlock::Formatter::TestDatetime < MiniTest::Unit::TestCase
6
6
  include ThinReports::TestHelpers
7
7
 
8
8
  # Alias
9
- Formatter = ThinReports::Core::Shape::Tblock::Formatter::Datetime
9
+ Formatter = ThinReports::Core::Shape::TextBlock::Formatter::Datetime
10
10
 
11
11
  def setup
12
12
  @datetime_format = '%Y/%m/%d %H:%M:%S'
@@ -2,11 +2,11 @@
2
2
 
3
3
  require 'test/unit/helper'
4
4
 
5
- class ThinReports::Core::Shape::Tblock::Formatter::TestNumber < MiniTest::Unit::TestCase
5
+ class ThinReports::Core::Shape::TextBlock::Formatter::TestNumber < MiniTest::Unit::TestCase
6
6
  include ThinReports::TestHelpers
7
7
 
8
8
  # Alias
9
- Formatter = ThinReports::Core::Shape::Tblock::Formatter::Number
9
+ Formatter = ThinReports::Core::Shape::TextBlock::Formatter::Number
10
10
 
11
11
  def init_formatter(expect_formats)
12
12
  format = flexmock({:format_base => '',
@@ -2,11 +2,11 @@
2
2
 
3
3
  require 'test/unit/helper'
4
4
 
5
- class ThinReports::Core::Shape::Tblock::Formatter::TestPadding < MiniTest::Unit::TestCase
5
+ class ThinReports::Core::Shape::TextBlock::Formatter::TestPadding < MiniTest::Unit::TestCase
6
6
  include ThinReports::TestHelpers
7
7
 
8
8
  # Alias
9
- Formatter = ThinReports::Core::Shape::Tblock::Formatter::Padding
9
+ Formatter = ThinReports::Core::Shape::TextBlock::Formatter::Padding
10
10
 
11
11
  def init_formatter(expect_formats)
12
12
  format = flexmock({:format_base => nil,
@@ -16,17 +16,22 @@ class ThinReports::Core::Shape::Tblock::Formatter::TestPadding < MiniTest::Unit:
16
16
  Formatter.new(format)
17
17
  end
18
18
 
19
- def test_apply_padding_formats
19
+ def test_apply_padding_formats_with_left_direction
20
20
  formatter = init_formatter(:format_padding_length => 5,
21
21
  :format_padding_char => '0')
22
22
 
23
23
  assert_equal formatter.apply(1), '00001'
24
24
  assert_equal formatter.apply('日本語'), '00日本語'
25
+ end
26
+
27
+ def test_apply_padding_formats_should_not_apply_when_character_length_is_short
28
+ formatter = init_formatter(:format_padding_length => 5,
29
+ :format_padding_char => '0')
25
30
 
26
- # Text length is longer than the specified length.
27
31
  assert_equal formatter.apply('1234567'), '1234567'
28
-
29
- # When direction is right
32
+ end
33
+
34
+ def test_apply_padding_formats_with_right_direction
30
35
  formatter = init_formatter(:format_padding_length => 5,
31
36
  :format_padding_char => '0',
32
37
  :format_padding_rdir? => true)
@@ -0,0 +1,160 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Core::Shape::TextBlock::TestFormat < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ TEST_TBLOCK_FORMAT = {
9
+ "type" => "s-tblock",
10
+ "id" => "block_1",
11
+ "display" => "true",
12
+ "multiple" => "false",
13
+ "box" => {
14
+ "x" => 100.0,
15
+ "y" => 100.0,
16
+ "width" => 100.0,
17
+ "height" => 100.0
18
+ },
19
+ "format" => {
20
+ "base" => "¥{value}",
21
+ "type" => "number",
22
+ "number" => {
23
+ "delimiter" => ",",
24
+ "precision" => 1
25
+ }
26
+ },
27
+ "value" => "",
28
+ "ref-id" => "",
29
+ "svg" => {
30
+ "tag" => "text",
31
+ "attrs" => {
32
+ "x" => 200.1,
33
+ "y" => 65.6,
34
+ "text-anchor" => "end",
35
+ "xml:space" => "preserve",
36
+ "fill" => "#000000",
37
+ "fill-opacity" => "1",
38
+ "font-size" => "12",
39
+ "font-family" => "\uFF2D\uFF33 \u30B4\u30B7\u30C3\u30AF",
40
+ "font-weight" => "bold",
41
+ "font-style" => "normal",
42
+ "text-decoration" => "none",
43
+ "clip-path" => "url(#_svgdef_0)"
44
+ }
45
+ }
46
+ }
47
+
48
+ def test_build
49
+ build_format
50
+ rescue => e
51
+ flunk exception_details(e, 'Building failed.')
52
+ end
53
+
54
+ def test_value_reader_via_TEST_TBLOCK_FORMAT
55
+ assert_equal format(TEST_TBLOCK_FORMAT).value, ''
56
+ end
57
+
58
+ def test_ref_id_reader_via_TEST_TBLOCK_FORMAT
59
+ assert_equal format(TEST_TBLOCK_FORMAT).ref_id, ''
60
+ end
61
+
62
+ def test_format_base_reader_via_TEST_TBLOCK_FORMAT
63
+ assert_equal format(TEST_TBLOCK_FORMAT).format_base, '¥{value}'
64
+ end
65
+
66
+ def test_format_type_reader_via_TEST_TBLOCK_FORMAT
67
+ assert_equal format(TEST_TBLOCK_FORMAT).format_type, 'number'
68
+ end
69
+
70
+ def test_box_reader_via_TEST_TBLOCK_FORMAT
71
+ assert_equal format(TEST_TBLOCK_FORMAT).box.values_at('x', 'y', 'width', 'height'),
72
+ [100.0, 100.0, 100.0, 100.0]
73
+ end
74
+
75
+ def test_format_datetime_format_reader_via_TEST_TBLOCK_FORMAT
76
+ assert_nil format(TEST_TBLOCK_FORMAT).format_datetime_format
77
+ end
78
+
79
+ def test_format_padding_char_reader_via_TEST_TBLOCK_FORMAT
80
+ assert_nil format(TEST_TBLOCK_FORMAT).format_padding_char
81
+ end
82
+
83
+ def test_format_padding_dir_reader_via_TEST_TBLOCK_FORMAT
84
+ assert_nil format(TEST_TBLOCK_FORMAT).format_padding_dir
85
+ end
86
+
87
+ def test_format_padding_length_via_TEST_TBLOCK_FORMAT
88
+ assert_equal format(TEST_TBLOCK_FORMAT).format_padding_length, 0
89
+ end
90
+
91
+ def test_format_padding_rdir_checker_via_TEST_TBLOCK_FORMAT
92
+ assert_equal format(TEST_TBLOCK_FORMAT).format_padding_rdir?, false
93
+ end
94
+
95
+ def test_format_has_format_asker_via_TEST_TBLOCK_FORMAT
96
+ assert_equal format(TEST_TBLOCK_FORMAT).has_format?, true
97
+ end
98
+
99
+ def test_format_has_reference_asker_via_TEST_TBLOCK_FORMAT
100
+ assert_equal format(TEST_TBLOCK_FORMAT).has_reference?, false
101
+ end
102
+
103
+ def test_format_multiple_checker_via_TEST_TBLOCK_FORMAT
104
+ assert_equal format(TEST_TBLOCK_FORMAT).multiple?, false
105
+ end
106
+
107
+ def test_multiple_checker_should_return_true
108
+ assert format('multiple' => 'true').multiple?
109
+ end
110
+
111
+ def test_multiple_checker_should_return_false
112
+ refute format('multiple' => 'false').multiple?
113
+ end
114
+
115
+ def test_format_padding_rdir_checker_should_return_false
116
+ data = {'format' => {'padding' => {'direction' => 'L'}}}
117
+ refute format(data).format_padding_rdir?
118
+ end
119
+
120
+ def test_format_padding_rdir_checker_should_return_true
121
+ data = {'format' => {'padding' => {'direction' => 'R'}}}
122
+ assert format(data).format_padding_rdir?
123
+ end
124
+
125
+ def test_format_padding_length_should_return_Numeric
126
+ data = {'format' => {'padding' => {'length' => '999'}}}
127
+ assert_kind_of ::Numeric, format(data).format_padding_length
128
+ end
129
+
130
+ def test_has_format_asker_should_return_false_with_empty_value
131
+ data = {'format' => {'type' => ''}}
132
+ refute format(data).has_format?
133
+ end
134
+
135
+ def test_has_format_asker_should_return_false_with_unknown_type
136
+ data = {'format' => {'type' => 'unknown'}}
137
+ refute format(data).has_format?
138
+ end
139
+
140
+ def test_has_format_asker_should_return_true
141
+ data = {'format' => {'type' => 'number'}}
142
+ assert format(data).has_format?
143
+ end
144
+
145
+ def test_has_reference_asker_should_return_false
146
+ refute format('ref-id' => '').has_reference?
147
+ end
148
+
149
+ def test_has_reference_asker_should_return_true
150
+ assert format('ref-id' => 'ref_tblock_1').has_reference?
151
+ end
152
+
153
+ def build_format
154
+ ThinReports::Core::Shape::TextBlock::Format.build(TEST_TBLOCK_FORMAT)
155
+ end
156
+
157
+ def format(data)
158
+ ThinReports::Core::Shape::TextBlock::Format.new(data)
159
+ end
160
+ end
@@ -2,11 +2,11 @@
2
2
 
3
3
  require 'test/unit/helper'
4
4
 
5
- class ThinReports::Core::Shape::Tblock::TestFormatter < MiniTest::Unit::TestCase
5
+ class ThinReports::Core::Shape::TextBlock::TestFormatter < MiniTest::Unit::TestCase
6
6
  include ThinReports::TestHelpers
7
7
 
8
8
  # Alias
9
- Formatter = ThinReports::Core::Shape::Tblock::Formatter
9
+ Formatter = ThinReports::Core::Shape::TextBlock::Formatter
10
10
 
11
11
  def test_initialize_formatter_by_type
12
12
  assert_instance_of Formatter::Basic,
@@ -0,0 +1,46 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Core::Shape::TextBlock::TestInterface < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ # Alias
9
+ TextBlock = ThinReports::Core::Shape::TextBlock
10
+
11
+ def create_interface(format_config = {})
12
+ TextBlock::Interface.new(flexmock('parent'),
13
+ TextBlock::Format.new(format_config))
14
+ end
15
+
16
+ def test_format_enabled_asker_should_operate_as_delegator_of_internal
17
+ tblock = create_interface('format' => {'type' => 'datetime'})
18
+ assert_equal tblock.format_enabled?, tblock.internal.format_enabled?
19
+ end
20
+
21
+ def test_format_enabled_should_properly_set_value_to_internal
22
+ tblock = create_interface('format' => {'type' => 'number'})
23
+ tblock.format_enabled(false)
24
+
25
+ assert_equal tblock.internal.format_enabled?, false
26
+ end
27
+
28
+ def test_set_should_properly_set_a_value
29
+ tblock = create_interface
30
+ tblock.set(1000, :visible => false)
31
+
32
+ assert_equal tblock.value, 1000
33
+ end
34
+
35
+ def test_set_should_properly_set_styles
36
+ tblock = create_interface
37
+ tblock.set(1000, :color => '#ff0000',
38
+ :bold => true,
39
+ :italic => true)
40
+
41
+ assert_equal [tblock.style(:color),
42
+ tblock.style(:bold),
43
+ tblock.style(:italic)],
44
+ ['#ff0000', true, true]
45
+ end
46
+ end
@@ -0,0 +1,128 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Core::Shape::TextBlock::TestInternal < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ # Alias
9
+ TextBlock = ThinReports::Core::Shape::TextBlock
10
+
11
+ def create_parent
12
+ report = create_basic_report('basic_layout1.tlf')
13
+ report.start_new_page do |page|
14
+ # Add to force TextBlock shape.
15
+ page.manager.format.shapes[:foo] = TextBlock::Format.new('type' => 's-tblock',
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' => '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('ref-id' => 'foo')
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', 'ref-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' refers 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' => '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?(:tblock), 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
@@ -8,25 +8,50 @@ class ThinReports::Core::TestShape < MiniTest::Unit::TestCase
8
8
  # Alias
9
9
  ShapeModule = ThinReports::Core::Shape
10
10
 
11
- def test_find_by_type
12
- assert_same ShapeModule.find_by_type('s-tblock'), ShapeModule::Tblock
11
+ def test_find_by_type_should_return_ImageBlock
12
+ assert_same ShapeModule.find_by_type('s-iblock'), ShapeModule::ImageBlock
13
+ end
14
+
15
+ def test_find_by_type_should_return_TextBlock
16
+ assert_same ShapeModule.find_by_type('s-tblock'), ShapeModule::TextBlock
17
+ end
18
+
19
+ def test_find_by_type_should_return_List
13
20
  assert_same ShapeModule.find_by_type('s-list'), ShapeModule::List
21
+ end
22
+
23
+ def test_find_by_type_should_return_Text
14
24
  assert_same ShapeModule.find_by_type('s-text'), ShapeModule::Text
15
-
25
+ end
26
+
27
+ def test_find_by_type_should_return_Basic_as_Image
16
28
  assert_same ShapeModule.find_by_type('s-image'), ShapeModule::Basic
29
+ end
30
+
31
+ def test_find_by_type_should_return_Basic_as_Line
17
32
  assert_same ShapeModule.find_by_type('s-line'), ShapeModule::Basic
33
+ end
34
+
35
+ def test_find_by_type_should_return_Basic_as_Rect
18
36
  assert_same ShapeModule.find_by_type('s-rect'), ShapeModule::Basic
37
+ end
38
+
39
+ def test_find_by_type_should_return_Basic_as_Ellipse
19
40
  assert_same ShapeModule.find_by_type('s-ellipse'), ShapeModule::Basic
20
-
41
+ end
42
+
43
+ def test_find_by_type_should_raise
21
44
  assert_raises ThinReports::Errors::UnknownShapeType do
22
45
  ShapeModule.find_by_type('unknown')
23
46
  end
24
47
  end
25
48
 
26
- def test_Configuration
49
+ def test_Configuration_should_return_Configuration_of_List
27
50
  assert_same ShapeModule::Configuration('s-list'),
28
51
  ShapeModule::List::Configuration
29
-
52
+ end
53
+
54
+ def test_Configuration_should_raise
30
55
  # When shape don't have a Configuration
31
56
  assert_raises ThinReports::Errors::NoConfigurationFound do
32
57
  ShapeModule::Configuration('s-line')