thinreports 0.6.0.pre3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +37 -32
- data/doc/yardoc_templates/default/layout/html/footer.erb +1 -1
- data/lib/thinreports.rb +2 -1
- data/lib/thinreports/config.rb +21 -0
- data/lib/thinreports/core/errors.rb +14 -1
- data/lib/thinreports/core/format/builder.rb +6 -1
- data/lib/thinreports/core/page.rb +6 -6
- data/lib/thinreports/core/shape.rb +8 -9
- data/lib/thinreports/core/shape/base/internal.rb +6 -12
- data/lib/thinreports/core/shape/basic.rb +3 -0
- data/lib/thinreports/core/shape/basic/block_format.rb +12 -0
- data/lib/thinreports/core/shape/basic/block_interface.rb +25 -0
- data/lib/thinreports/core/shape/basic/block_internal.rb +33 -0
- data/lib/thinreports/core/shape/basic/interface.rb +37 -11
- data/lib/thinreports/core/shape/basic/internal.rb +3 -12
- data/lib/thinreports/core/shape/image_block.rb +15 -0
- data/lib/thinreports/core/shape/image_block/format.rb +13 -0
- data/lib/thinreports/core/shape/image_block/interface.rb +19 -0
- data/lib/thinreports/core/shape/image_block/internal.rb +16 -0
- data/lib/thinreports/core/shape/list/events.rb +19 -2
- data/lib/thinreports/core/shape/list/manager.rb +17 -4
- data/lib/thinreports/core/shape/list/page.rb +2 -2
- data/lib/thinreports/core/shape/list/page_state.rb +4 -0
- data/lib/thinreports/core/shape/list/section_internal.rb +4 -0
- data/lib/thinreports/core/shape/manager/format.rb +1 -1
- data/lib/thinreports/core/shape/manager/internal.rb +24 -11
- data/lib/thinreports/core/shape/manager/target.rb +2 -2
- data/lib/thinreports/core/shape/style.rb +15 -0
- data/lib/thinreports/core/shape/style/base.rb +149 -0
- data/lib/thinreports/core/shape/style/basic.rb +17 -0
- data/lib/thinreports/core/shape/style/graphic.rb +60 -0
- data/lib/thinreports/core/shape/style/text.rb +138 -0
- data/lib/thinreports/core/shape/text/internal.rb +4 -0
- data/lib/thinreports/core/shape/text_block.rb +16 -0
- data/lib/thinreports/core/shape/{tblock → text_block}/format.rb +3 -3
- data/lib/thinreports/core/shape/{tblock → text_block}/formatter.rb +7 -7
- data/lib/thinreports/core/shape/{tblock → text_block}/formatter/basic.rb +1 -1
- data/lib/thinreports/core/shape/{tblock → text_block}/formatter/datetime.rb +1 -1
- data/lib/thinreports/core/shape/{tblock → text_block}/formatter/number.rb +1 -1
- data/lib/thinreports/core/shape/{tblock → text_block}/formatter/padding.rb +10 -8
- data/lib/thinreports/core/shape/{tblock → text_block}/interface.rb +2 -21
- data/lib/thinreports/core/shape/{tblock → text_block}/internal.rb +16 -10
- data/lib/thinreports/core/utils.rb +0 -8
- data/lib/thinreports/generator.rb +2 -2
- data/lib/thinreports/generator/configuration.rb +30 -0
- data/lib/thinreports/generator/pdf.rb +13 -10
- data/lib/thinreports/generator/pdf/configuration.rb +28 -0
- data/lib/thinreports/generator/pdf/document.rb +16 -56
- data/lib/thinreports/generator/pdf/document/draw_shape.rb +35 -17
- data/lib/thinreports/generator/pdf/document/font.rb +25 -9
- data/lib/thinreports/generator/pdf/document/graphics.rb +1 -1
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +18 -4
- data/lib/thinreports/generator/pdf/document/graphics/basic.rb +1 -1
- data/lib/thinreports/generator/pdf/document/graphics/image.rb +18 -1
- data/lib/thinreports/generator/pdf/document/graphics/text.rb +29 -6
- data/lib/thinreports/generator/pdf/document/page.rb +70 -0
- data/lib/thinreports/generator/pdf/document/parse_color.rb +1 -1
- data/lib/thinreports/generator/pdf/document/parse_svg.rb +1 -1
- data/lib/thinreports/generator/pdf/drawer.rb +1 -1
- data/lib/thinreports/generator/pdf/drawer/base.rb +5 -7
- data/lib/thinreports/generator/pdf/drawer/list.rb +4 -4
- data/lib/thinreports/generator/pdf/drawer/list_section.rb +8 -3
- data/lib/thinreports/generator/pdf/drawer/page.rb +10 -3
- data/lib/thinreports/generator/pdf/prawn_ext.rb +16 -21
- data/lib/thinreports/layout/format.rb +2 -2
- data/lib/thinreports/layout/version.rb +2 -2
- data/lib/thinreports/report/base.rb +68 -31
- data/tasks/test.rake +48 -4
- data/test/benchmark/basic_estimate.tlf +1 -0
- data/test/benchmark/bench_basic_estimate.rb +95 -0
- data/test/case/character_spacing/character_spacing.rb +7 -0
- data/test/case/character_spacing/character_spacing.tlf +1 -0
- data/test/case/dynamic_image/dynamic_image.rb +41 -0
- data/test/case/dynamic_image/dynamic_image.tlf +1 -0
- data/test/case/dynamic_image/img200x100.png +0 -0
- data/test/case/dynamic_image/img50x50.png +0 -0
- data/test/case/dynamic_style/dynamic_style.rb +154 -0
- data/test/case/dynamic_style/dynamic_style.tlf +1 -0
- data/test/case/dynamic_style/dynamic_style_in_list.tlf +1 -0
- data/test/case/dynamic_style/image.png +0 -0
- data/test/case/eudc/eudc.rb +20 -0
- data/test/case/eudc/eudc.tlf +1 -0
- data/test/case/eudc/eudc.ttf +0 -0
- data/test/case/helper.rb +27 -0
- data/test/case/hidden_shapes/hidden_shapes.rb +13 -0
- data/test/case/hidden_shapes/hidden_shapes.tlf +1 -0
- data/test/case/list_events/list_events.rb +32 -0
- data/test/case/list_events/list_events.tlf +1 -0
- data/test/case/list_header_inheriting/list_header_inheriting.rb +19 -0
- data/test/case/list_header_inheriting/list_header_inheriting.tlf +1 -0
- data/test/case/list_manual_generation/list_manual_generation.rb +24 -0
- data/test/case/list_manual_generation/list_manual_generation.tlf +1 -0
- data/test/case/single_line_tblock/single_line_tblock.rb +15 -0
- data/test/case/single_line_tblock/single_line_tblock.tlf +1 -0
- data/test/case/tblock_styles/tblock_styles.rb +27 -0
- data/test/case/tblock_styles/tblock_styles.tlf +1 -0
- data/test/case/text_align/text_align.rb +9 -0
- data/test/case/text_align/text_align.tlf +1 -0
- data/test/unit/core/shape/base/test_internal.rb +65 -85
- data/test/unit/core/shape/basic/test_basic_format.rb +30 -0
- data/test/unit/core/shape/basic/test_basic_interface.rb +27 -0
- data/test/unit/core/shape/basic/test_basic_internal.rb +55 -0
- data/test/unit/core/shape/basic/test_interface.rb +84 -36
- data/test/unit/core/shape/basic/test_internal.rb +32 -24
- data/test/unit/core/shape/image_block/test_format.rb +58 -0
- data/test/unit/core/shape/image_block/test_interface.rb +23 -0
- data/test/unit/core/shape/image_block/test_internal.rb +28 -0
- data/test/unit/core/shape/list/test_events.rb +19 -11
- data/test/unit/core/shape/list/test_manager.rb +112 -0
- data/test/unit/core/shape/list/test_page.rb +57 -0
- data/test/unit/core/shape/list/test_section_format.rb +1 -1
- data/test/unit/core/shape/list/test_section_interface.rb +37 -30
- data/test/unit/core/shape/list/test_section_internal.rb +39 -14
- data/test/unit/core/shape/manager/test_format.rb +12 -18
- data/test/unit/core/shape/manager/test_internal.rb +127 -93
- data/test/unit/core/shape/manager/test_target.rb +63 -56
- data/test/unit/core/shape/styles/test_base.rb +219 -0
- data/test/unit/core/shape/styles/test_basic.rb +24 -0
- data/test/unit/core/shape/styles/test_graphic.rb +69 -0
- data/test/unit/core/shape/styles/test_text.rb +318 -0
- data/test/unit/core/shape/{tblock → text_block}/formatter/test_basic.rb +2 -2
- data/test/unit/core/shape/{tblock → text_block}/formatter/test_datetime.rb +2 -2
- data/test/unit/core/shape/{tblock → text_block}/formatter/test_number.rb +2 -2
- data/test/unit/core/shape/{tblock → text_block}/formatter/test_padding.rb +11 -6
- data/test/unit/core/shape/text_block/test_format.rb +160 -0
- data/test/unit/core/shape/{tblock → text_block}/test_formatter.rb +2 -2
- data/test/unit/core/shape/text_block/test_interface.rb +46 -0
- data/test/unit/core/shape/text_block/test_internal.rb +128 -0
- data/test/unit/core/test_shape.rb +31 -6
- data/test/unit/data/basic_layout1.tlf +1 -0
- data/test/unit/data/basic_layout2.tlf +1 -0
- data/test/unit/data/basic_list_layout.tlf +1 -0
- data/test/unit/generator/pdf/document/graphics/test_attributes.rb +81 -52
- data/test/unit/generator/pdf/document/graphics/test_text.rb +159 -0
- data/test/unit/generator/pdf/document/test_font.rb +21 -6
- data/test/unit/generator/pdf/document/test_graphics.rb +2 -2
- data/test/unit/generator/pdf/document/test_page.rb +95 -0
- data/test/unit/generator/pdf/document/test_parse_color.rb +2 -2
- data/test/unit/generator/pdf/test_configuration.rb +24 -0
- data/test/unit/generator/pdf/test_document.rb +28 -0
- data/test/unit/generator/test_configuration.rb +25 -0
- data/test/unit/generator/test_pdf.rb +19 -0
- data/test/unit/helper.rb +18 -0
- data/test/unit/layout/test_format.rb +24 -7
- data/test/unit/layout/test_version.rb +61 -27
- data/test/unit/report/test_base.rb +185 -89
- data/test/unit/test_config.rb +22 -0
- data/test/unit/test_report.rb +4 -4
- metadata +94 -43
- data/lib/thinreports/core/shape/tblock.rb +0 -16
- data/lib/thinreports/generator/pxd.rb +0 -75
- data/lib/thinreports/generator/pxd/helper.rb +0 -33
- data/lib/thinreports/generator/pxd/list_renderer.rb +0 -58
- data/lib/thinreports/generator/pxd/page_renderer.rb +0 -75
- data/tasks/clean.rake +0 -6
- data/test/unit/core/shape/tblock/test_format.rb +0 -125
- data/test/unit/core/shape/tblock/test_interface.rb +0 -40
- data/test/unit/core/shape/tblock/test_internal.rb +0 -139
@@ -0,0 +1,219 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit/helper'
|
4
|
+
|
5
|
+
class ThinReports::Core::Shape::Style::TestBase < MiniTest::Unit::TestCase
|
6
|
+
include ThinReports::TestHelpers
|
7
|
+
|
8
|
+
# Alias
|
9
|
+
Style = ThinReports::Core::Shape::Style::Base
|
10
|
+
|
11
|
+
def create_basic_format(attrs = {})
|
12
|
+
ThinReports::Core::Shape::Basic::Format.new('svg' => {'attrs' => attrs})
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_style(base = {})
|
16
|
+
Style.new(create_basic_format(base))
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_new_style(base = {}, &block)
|
20
|
+
klass = ::Class.new(Style, &block)
|
21
|
+
klass.new(create_basic_format(base))
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_self_style_reader_should_properly_define_a_reading_method
|
25
|
+
style = create_new_style {
|
26
|
+
style_reader :hoge, 'foo'
|
27
|
+
}
|
28
|
+
assert_respond_to style, :hoge
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_self_style_writer_should_properly_define_a_writing_method
|
32
|
+
style = create_new_style {
|
33
|
+
style_writer :hoge, 'foo'
|
34
|
+
}
|
35
|
+
assert_respond_to style, :hoge=
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_self_style_accessor_should_properly_defines_reading_and_writing_methods
|
39
|
+
style = create_new_style {
|
40
|
+
style_accessor :hoge, 'foo'
|
41
|
+
}
|
42
|
+
assert_respond_to style, :hoge
|
43
|
+
assert_respond_to style, :hoge=
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_self_style_accessible_should_add_specified_styles_to_the_accessible_styles_variable
|
47
|
+
style = create_new_style {
|
48
|
+
style_accessible :hoge
|
49
|
+
style_accessible :foo, :bar
|
50
|
+
}
|
51
|
+
assert_equal style.class.accessible_styles, [:hoge, :foo, :bar]
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_self_accessible_styles_variable_should_not_be_shared_each_SubClasses
|
55
|
+
style1 = create_new_style {
|
56
|
+
style_accessible :hoge, :foo
|
57
|
+
}
|
58
|
+
style2 = create_new_style {
|
59
|
+
style_accessible :bar, :fuga
|
60
|
+
}
|
61
|
+
assert_equal style1.class.accessible_styles, [:hoge, :foo]
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_self_accessible_styles_variable_should_be_inherited_to_SubClass
|
65
|
+
super_klass = ::Class.new(Style) {
|
66
|
+
style_accessible :hoge, :foo
|
67
|
+
}
|
68
|
+
sub_klass = ::Class.new(super_klass)
|
69
|
+
|
70
|
+
assert_equal sub_klass.accessible_styles, super_klass.accessible_styles
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_self_accessible_styles_variables_of_SubClass_should_not_interfere_mutually
|
74
|
+
super_klass = ::Class.new(Style) {
|
75
|
+
style_accessible :foo, :bar
|
76
|
+
}
|
77
|
+
sub_klass1 = ::Class.new(super_klass)
|
78
|
+
sub_klass2 = ::Class.new(super_klass)
|
79
|
+
|
80
|
+
refute_same sub_klass1.accessible_styles, sub_klass2.accessible_styles
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_read_internal_style_should_return_style_of_styles_when_style_is_found_in_styles
|
84
|
+
style = create_style('hoge' => 'base_style')
|
85
|
+
style.write_internal_style('hoge', 'new_style')
|
86
|
+
|
87
|
+
assert_equal style.read_internal_style('hoge'), 'new_style'
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_read_internal_style_should_return_style_of_base_when_style_is_not_found_in_styles
|
91
|
+
style = create_style('hoge' => 'base_style')
|
92
|
+
assert_equal style.read_internal_style('hoge'), 'base_style'
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_write_internal_style_should_properly_set_style_to_the_styles
|
96
|
+
style = create_style({})
|
97
|
+
style.write_internal_style('hoge', 'hoge_style')
|
98
|
+
|
99
|
+
assert_equal style.styles['hoge'], 'hoge_style'
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_finalized_svg_attributes_should_return_the_Hash_of_having_combined_styles_and_base
|
103
|
+
style = create_style('hoge' => 'base_hoge_style',
|
104
|
+
'foo' => 'base_foo_style')
|
105
|
+
style.write_internal_style('hoge', 'modified_hoge_style')
|
106
|
+
|
107
|
+
assert_equal style.finalized_svg_attributes.values_at('hoge', 'foo'),
|
108
|
+
['modified_hoge_style', 'base_foo_style']
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_finalized_svg_attributes_should_return_a_base_when_styles_is_empty
|
112
|
+
style = create_style
|
113
|
+
assert_equal style.finalized_svg_attributes, style.instance_variable_get(:@base_styles)
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_finalized_svg_attributes_should_return_a_cloned_base_when_styles_is_empty
|
117
|
+
style = create_style
|
118
|
+
refute_same style.finalized_svg_attributes, style.instance_variable_get(:@base_styles)
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_finalized_svg_attributes_should_return_same_value_constantly
|
122
|
+
style = create_style('hoge' => 'hoge_style')
|
123
|
+
style.write_internal_style('foo', 'foo_style')
|
124
|
+
|
125
|
+
assert_same style.finalized_svg_attributes,
|
126
|
+
style.finalized_svg_attributes
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_svg_attrs_should_operate_like_a_finalized_svg_attributes
|
130
|
+
style = create_style('hoge' => 'hoge_style',
|
131
|
+
'foo' => 'foo_style')
|
132
|
+
style.write_internal_style('foo', 'overwrite_foo_style')
|
133
|
+
|
134
|
+
assert_same style.finalized_svg_attributes, style.svg_attrs
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_has_style_asker_should_return_true_when_specified_style_method_is_accessible
|
138
|
+
style = create_new_style {
|
139
|
+
style_accessible :hoge, :foo
|
140
|
+
}
|
141
|
+
assert_equal style.has_style?(:foo), true
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_has_style_asker_should_return_false_when_specified_style_method_is_not_accessible
|
145
|
+
style = create_new_style {
|
146
|
+
style_accessible :foo
|
147
|
+
}
|
148
|
+
assert_equal style.has_style?(:hoge), false
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_verify_style_value_should_raise_when_value_is_not_included_in_list
|
152
|
+
assert_raises ArgumentError do
|
153
|
+
create_style.send(:verify_style_value, :invalid, [:hoge, :foo, :bar])
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_verify_style_value_should_not_raise_when_value_is_found_in_list
|
158
|
+
create_style.send(:verify_style_value, :valid, [:hoge, :valid, :foo])
|
159
|
+
rescue ArgumentError
|
160
|
+
flunk
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_reader_method_caller_should_properly_delegate_to_real_method
|
164
|
+
style = create_new_style('hoge_style' => 'hoge_style_value') {
|
165
|
+
style_accessible :hoge
|
166
|
+
style_reader :hoge, 'hoge_style'
|
167
|
+
}
|
168
|
+
assert_equal style[:hoge], 'hoge_style_value'
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_writer_method_caller_should_properly_delegate_to_real_method
|
172
|
+
style = create_new_style {
|
173
|
+
style_accessible :hoge
|
174
|
+
style_accessor :hoge, 'hoge_style'
|
175
|
+
}
|
176
|
+
style[:hoge] = 'hoge_style_value'
|
177
|
+
assert_equal style.hoge, 'hoge_style_value'
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_reader_method_caller_should_raise_when_style_is_not_accessible
|
181
|
+
assert_raises ThinReports::Errors::UnknownShapeStyleName do
|
182
|
+
create_new_style[:unknown]
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_writer_method_caller_should_raise_when_style_is_not_accessible
|
187
|
+
assert_raises ThinReports::Errors::UnknownShapeStyleName do
|
188
|
+
create_new_style[:unknown] = 'value'
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_copy_should_return_the_instance_of_the_same_class_as_itself
|
193
|
+
style = create_style
|
194
|
+
assert_instance_of Style, style.copy
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_styles_of_copied_style_should_not_same_the_styles_of_original
|
198
|
+
style = create_style
|
199
|
+
refute_same style.styles, style.copy.styles
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_styles_of_copied_style_should_equal_the_style_of_original
|
203
|
+
style = create_style
|
204
|
+
style.write_internal_style('foo', 'foo_value')
|
205
|
+
assert_equal style.styles['foo'], style.copy.styles['foo']
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_identifier_should_return_empty_string_when_the_style_is_not_set
|
209
|
+
style = create_style
|
210
|
+
assert_equal style.identifier, ''
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_identifier_should_return_the_same_as_hash_value_of_styles_when_style_is_set_something
|
214
|
+
style = create_style
|
215
|
+
style.write_internal_style('foo', 'foo_value')
|
216
|
+
|
217
|
+
assert_equal style.identifier, style.styles.hash.to_s
|
218
|
+
end
|
219
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit/helper'
|
4
|
+
|
5
|
+
class ThinReports::Core::Shape::Style::TestBasic < MiniTest::Unit::TestCase
|
6
|
+
include ThinReports::TestHelpers
|
7
|
+
|
8
|
+
def create_basic_style(format_config = {})
|
9
|
+
format = ThinReports::Core::Shape::Basic::Format.new(format_config)
|
10
|
+
ThinReports::Core::Shape::Style::Basic.new(format)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_visible_should_return_visibility_of_format_as_default
|
14
|
+
style = create_basic_style('display' => 'false')
|
15
|
+
assert_equal style.visible, false
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_visible_should_properly_set_visibility
|
19
|
+
style = create_basic_style('display' => 'false')
|
20
|
+
style.visible = true
|
21
|
+
|
22
|
+
assert_equal style.visible, true
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit/helper'
|
4
|
+
|
5
|
+
class ThinReports::Core::Shape::Style::TestGraphic < MiniTest::Unit::TestCase
|
6
|
+
include ThinReports::TestHelpers
|
7
|
+
|
8
|
+
def create_graphic_style
|
9
|
+
format = ThinReports::Core::Shape::Basic::Format.new({})
|
10
|
+
ThinReports::Core::Shape::Style::Graphic.new(format)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_border_color_should_properly_set_to_internal_styles_as_stroke_style
|
14
|
+
style = create_graphic_style
|
15
|
+
style.border_color = '#ff0000'
|
16
|
+
|
17
|
+
assert_equal style.styles['stroke'], '#ff0000'
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_border_width_should_properly_set_to_internal_styles_as_stroke_width_style
|
21
|
+
style = create_graphic_style
|
22
|
+
style.border_width = 1
|
23
|
+
|
24
|
+
assert_equal style.styles['stroke-width'], 1
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_border_width_should_set_stroke_opacity_to_1_when_width_is_not_zero
|
28
|
+
style = create_graphic_style
|
29
|
+
style.border_width = 5
|
30
|
+
|
31
|
+
assert_equal style.styles['stroke-opacity'], '1'
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_fill_color_should_properly_set_to_internal_styles_as_fill_style
|
35
|
+
style = create_graphic_style
|
36
|
+
style.fill_color = '#0000ff'
|
37
|
+
|
38
|
+
assert_equal style.styles['fill'], '#0000ff'
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_fill_should_operate_like_the_fill_color_method
|
42
|
+
style = create_graphic_style
|
43
|
+
style.fill = '#ff0000'
|
44
|
+
|
45
|
+
assert_same style.fill_color, style.fill
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_stroke_should_operate_like_the_border_width_method
|
49
|
+
style = create_graphic_style
|
50
|
+
style.stroke = 5
|
51
|
+
|
52
|
+
assert_same style.border_width, style.stroke
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_border_should_return_an_Array_included_border_width_and_border_color
|
56
|
+
style = create_graphic_style
|
57
|
+
style.border_width = 1
|
58
|
+
style.border_color = '#ff0000'
|
59
|
+
|
60
|
+
assert_equal style.border, [style.border_width, style.border_color]
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_border_should_properly_set_both_border_width_and_border_color_from_the_specified_array_argument
|
64
|
+
style = create_graphic_style
|
65
|
+
style.border = [5, '#000000']
|
66
|
+
|
67
|
+
assert_equal style.border, [5, '#000000']
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,318 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit/helper'
|
4
|
+
|
5
|
+
class ThinReports::Core::Shape::Style::TestText < MiniTest::Unit::TestCase
|
6
|
+
include ThinReports::TestHelpers
|
7
|
+
|
8
|
+
def create_format(format = {})
|
9
|
+
ThinReports::Core::Shape::Text::Format.new(format)
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_text_style(format = nil)
|
13
|
+
format ||= create_format
|
14
|
+
ThinReports::Core::Shape::Style::Text.new(format)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_bold_should_return_true_when_font_weight_property_of_format_is_bold
|
18
|
+
format = create_format('svg' => {'attrs' => {'font-weight' => 'bold'}})
|
19
|
+
style = create_text_style(format)
|
20
|
+
|
21
|
+
assert_equal style.bold, true
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_bold_should_return_false_when_font_weight_property_of_format_is_not_bold
|
25
|
+
format = create_format('svg' => {'attrs' => {'font-weight' => 'normal'}})
|
26
|
+
style = create_text_style(format)
|
27
|
+
|
28
|
+
assert_equal style.bold, false
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_bold_should_set_normal_to_font_weight_style_when_value_is_false
|
32
|
+
style = create_text_style
|
33
|
+
style.bold = false
|
34
|
+
|
35
|
+
assert_equal style.styles['font-weight'], 'normal'
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_bold_should_set_bold_to_font_weight_style_when_value_is_true
|
39
|
+
style = create_text_style
|
40
|
+
style.bold = true
|
41
|
+
|
42
|
+
assert_equal style.styles['font-weight'], 'bold'
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_bold_should_return_true_when_font_weight_of_internal_style_is_bold
|
46
|
+
style = create_text_style
|
47
|
+
style.styles['font-weight'] = 'bold'
|
48
|
+
|
49
|
+
assert_equal style.bold, true
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_bold_should_return_false_when_font_weight_of_internal_style_is_not_bold
|
53
|
+
style = create_text_style
|
54
|
+
style.styles['font-weight'] = 'normal'
|
55
|
+
|
56
|
+
assert_equal style.bold, false
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_italic_should_return_true_when_font_style_property_of_format_is_italic
|
60
|
+
format = create_format('svg' => {'attrs' => {'font-style' => 'italic'}})
|
61
|
+
style = create_text_style(format)
|
62
|
+
|
63
|
+
assert_equal style.italic, true
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_italic_should_return_false_when_font_style_property_of_format_is_not_italic
|
67
|
+
format = create_format('svg' => {'attrs' => {'font-style' => 'normal'}})
|
68
|
+
style = create_text_style(format)
|
69
|
+
|
70
|
+
assert_equal style.italic, false
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_italic_should_set_normal_to_font_style_style_when_value_is_false
|
74
|
+
style = create_text_style
|
75
|
+
style.italic = false
|
76
|
+
|
77
|
+
assert_equal style.styles['font-style'], 'normal'
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_italic_should_set_italic_to_font_style_style_when_value_is_true
|
81
|
+
style = create_text_style
|
82
|
+
style.italic = true
|
83
|
+
|
84
|
+
assert_equal style.styles['font-style'], 'italic'
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_italic_should_return_false_when_font_style_of_internal_style_is_not_italic
|
88
|
+
style = create_text_style
|
89
|
+
style.styles['font-style'] = 'normal'
|
90
|
+
|
91
|
+
assert_equal style.italic, false
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_italic_should_return_true_when_font_style_of_internal_style_is_italic
|
95
|
+
style = create_text_style
|
96
|
+
style.styles['font-style'] = 'italic'
|
97
|
+
|
98
|
+
assert_equal style.italic, true
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_underline_should_return_true_when_underline_is_included_in_text_decoration_property_of_format
|
102
|
+
format = create_format('svg' => {'attrs' => {'text-decoration' => 'underline line-through'}})
|
103
|
+
style = create_text_style(format)
|
104
|
+
|
105
|
+
assert_equal style.underline, true
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_underline_should_return_false_when_underline_is_not_included_in_text_decoration_property_of_format
|
109
|
+
format = create_format('svg' => {'attrs' => {'text-decoration' => 'line-through'}})
|
110
|
+
style = create_text_style(format)
|
111
|
+
|
112
|
+
assert_equal style.underline, false
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_underline_should_return_true_when_underline_is_included_in_text_decoration_of_internal_style
|
116
|
+
style = create_text_style
|
117
|
+
style.styles['text-decoration'] = 'underline line-through'
|
118
|
+
|
119
|
+
assert_equal style.underline, true
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_underline_should_return_false_when_underline_is_not_included_in_text_decoration_of_internal_style
|
123
|
+
style = create_text_style
|
124
|
+
style.styles['text-decoration'] = 'none'
|
125
|
+
|
126
|
+
assert_equal style.underline, false
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_underline_should_include_underline_in_text_decoration_when_value_is_true
|
130
|
+
format = create_format('svg' => {'attrs' => {'text-decoration' => 'line-through'}})
|
131
|
+
style = create_text_style(format)
|
132
|
+
style.underline = true
|
133
|
+
|
134
|
+
assert_includes style.styles['text-decoration'], 'underline'
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_underline_should_remove_underline_from_text_decoration_when_value_is_false
|
138
|
+
format = create_format('svg' => {'attrs' => {'text-decoration' => 'underline line-through'}})
|
139
|
+
style = create_text_style(format)
|
140
|
+
style.underline = false
|
141
|
+
|
142
|
+
refute_includes style.styles['text-decoration'], 'underline'
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_linethrough_should_return_true_when_line_through_is_included_in_text_decoration_property_of_format
|
146
|
+
format = create_format('svg' => {'attrs' => {'text-decoration' => 'underline line-through'}})
|
147
|
+
style = create_text_style(format)
|
148
|
+
|
149
|
+
assert_equal style.linethrough, true
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_linethrough_should_return_false_when_line_through_is_not_included_in_text_decoration_property_of_format
|
153
|
+
format = create_format('svg' => {'attrs' => {'text-decoration' => 'underline'}})
|
154
|
+
style = create_text_style(format)
|
155
|
+
|
156
|
+
assert_equal style.linethrough, false
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_linethrough_should_return_true_when_line_through_is_included_in_text_decoration_of_internal_style
|
160
|
+
style = create_text_style
|
161
|
+
style.styles['text-decoration'] = 'underline line-through'
|
162
|
+
|
163
|
+
assert_equal style.linethrough, true
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_linethrough_should_return_false_when_line_through_is_not_included_in_text_decoration_of_internal_style
|
167
|
+
style = create_text_style
|
168
|
+
style.styles['text-decoration'] = 'underline'
|
169
|
+
|
170
|
+
assert_equal style.linethrough, false
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_linethrough_should_include_line_through_in_text_decoration_when_value_is_true
|
174
|
+
format = create_format('svg' => {'attrs' => {'text-decoration' => 'none'}})
|
175
|
+
style = create_text_style(format)
|
176
|
+
style.linethrough = true
|
177
|
+
|
178
|
+
assert_includes style.styles['text-decoration'], 'line-through'
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_linethrough_should_remove_line_through_from_text_decoration_when_value_is_false
|
182
|
+
format = create_format('svg' => {'attrs' => {'text-decoration' => 'underline line-through'}})
|
183
|
+
style = create_text_style(format)
|
184
|
+
style.linethrough = false
|
185
|
+
|
186
|
+
refute_includes style.styles['text-decoration'], 'line-through'
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_text_decoration_should_return_none
|
190
|
+
assert_equal create_text_style.send(:text_decoration, false, false), 'none'
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_text_decoration_should_return_underline
|
194
|
+
assert_equal create_text_style.send(:text_decoration, true, false), 'underline'
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_text_decoration_should_return_line_through
|
198
|
+
assert_equal create_text_style.send(:text_decoration, false, true), 'line-through'
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_text_decoration_should_return_underline_line_through
|
202
|
+
assert_equal create_text_style.send(:text_decoration, true, true), 'underline line-through'
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_interface_text_align_should_return_Symbol_left_when_value_is_undefined
|
206
|
+
assert_equal create_text_style.send(:interface_text_align, nil), :left
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_interface_text_align_should_return_Symbol_left_when_value_is_String_start
|
210
|
+
assert_equal create_text_style.send(:interface_text_align, 'start'), :left
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_interface_text_align_should_return_Symbol_left_when_value_is_unknown_align_type
|
214
|
+
assert_equal create_text_style.send(:interface_text_align, 'unknown'), :left
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_interface_text_align_should_return_Symbol_center_when_value_is_String_middle
|
218
|
+
assert_equal create_text_style.send(:interface_text_align, 'middle'), :center
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_interface_text_align_should_return_Symbol_right_when_value_is_String_end
|
222
|
+
assert_equal create_text_style.send(:interface_text_align, 'end'), :right
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_internal_text_align_should_return_nil_when_value_is_unknown
|
226
|
+
assert_equal create_text_style.send(:internal_text_align, :unknown), nil
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_internal_text_align_should_return_String_start_when_value_is_Symbol_left
|
230
|
+
assert_equal create_text_style.send(:internal_text_align, :left), 'start'
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_internal_text_align_should_return_String_middle_when_value_is_Symbol_center
|
234
|
+
assert_equal create_text_style.send(:internal_text_align, :center), 'middle'
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_internal_text_align_should_return_String_end_when_value_is_Symbol_right
|
238
|
+
assert_equal create_text_style.send(:internal_text_align, :right), 'end'
|
239
|
+
end
|
240
|
+
|
241
|
+
def test_align_should_properly_return_align_type_with_reference_to_text_anchor_property_of_format
|
242
|
+
result = []
|
243
|
+
|
244
|
+
format_left = create_format('svg' => {'attrs' => {'text-anchor' => 'start'}})
|
245
|
+
format_center = create_format('svg' => {'attrs' => {'text-anchor' => 'middle'}})
|
246
|
+
format_right = create_format('svg' => {'attrs' => {'text-anchor' => 'end'}})
|
247
|
+
|
248
|
+
result << create_text_style(format_left).align
|
249
|
+
result << create_text_style(format_center).align
|
250
|
+
result << create_text_style(format_right).align
|
251
|
+
|
252
|
+
assert_equal result, [:left, :center, :right]
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_copy_should_properly_copy_the_valign_property_of_the_original
|
256
|
+
style = create_text_style
|
257
|
+
style.valign = :center
|
258
|
+
|
259
|
+
assert_equal style.copy.valign, :center
|
260
|
+
end
|
261
|
+
|
262
|
+
def test_align_should_property_return_align_type_with_reference_to_text_anchor_of_internal_style
|
263
|
+
style = create_text_style
|
264
|
+
style.styles['text-anchor'] = 'middle'
|
265
|
+
|
266
|
+
assert_equal style.align, :center
|
267
|
+
end
|
268
|
+
|
269
|
+
def test_align_should_set_interface_align_type_to_text_anchor
|
270
|
+
style = create_text_style
|
271
|
+
style.align = :right
|
272
|
+
|
273
|
+
assert_equal style.styles['text-anchor'], 'end'
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_align_should_raise_when_the_specified_type_is_unknown
|
277
|
+
assert_raises ArgumentError do
|
278
|
+
create_text_style.align = :unknown
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
def test_valign_should_return_top_when_valign_of_format_is_blank
|
283
|
+
assert_equal create_text_style.valign, :top
|
284
|
+
end
|
285
|
+
|
286
|
+
def test_valign_should_return_valign_type_of_format_as_default
|
287
|
+
format = create_format('valign' => 'bottom')
|
288
|
+
style = create_text_style(format)
|
289
|
+
|
290
|
+
assert_equal style.valign, :bottom
|
291
|
+
end
|
292
|
+
|
293
|
+
def test_valign_should_properly_set_valign_type
|
294
|
+
style = create_text_style
|
295
|
+
style.valign = :center
|
296
|
+
|
297
|
+
assert_equal style.valign, :center
|
298
|
+
end
|
299
|
+
|
300
|
+
def test_valign_should_raise_when_the_specified_type_is_unknown
|
301
|
+
assert_raises ArgumentError do
|
302
|
+
create_text_style.valign = :unknonw
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
def test_identifier_should_return_the_same_value_as_create_identifier_method_when_valign_has_not_been_changed
|
307
|
+
style = create_text_style
|
308
|
+
assert_equal style.identifier, style.send(:create_identifier, style.styles)
|
309
|
+
end
|
310
|
+
|
311
|
+
def test_identifier_should_return_the_value_which_added_valign_to_the_value_of_create_identifier_when_valign_has_been_changed
|
312
|
+
style = create_text_style
|
313
|
+
style.valign = :bottom
|
314
|
+
|
315
|
+
assert_equal style.identifier,
|
316
|
+
style.send(:create_identifier, style.styles) + 'bottom'
|
317
|
+
end
|
318
|
+
end
|