thinreports 0.9.1 → 0.11.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.
- checksums.yaml +5 -5
- data/.github/workflows/test.yml +39 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +59 -2
- data/Dockerfile +12 -0
- data/Gemfile +7 -4
- data/README.md +44 -22
- data/Rakefile +14 -31
- data/lib/thinreports.rb +16 -15
- data/lib/thinreports/config.rb +2 -24
- data/lib/thinreports/core/errors.rb +6 -17
- data/lib/thinreports/core/format/base.rb +62 -61
- data/lib/thinreports/core/shape.rb +10 -12
- data/lib/thinreports/core/shape/base.rb +3 -12
- data/lib/thinreports/core/shape/base/interface.rb +34 -32
- data/lib/thinreports/core/shape/base/internal.rb +45 -43
- data/lib/thinreports/core/shape/basic.rb +12 -12
- data/lib/thinreports/core/shape/basic/block_format.rb +8 -6
- data/lib/thinreports/core/shape/basic/block_interface.rb +24 -22
- data/lib/thinreports/core/shape/basic/block_internal.rb +28 -26
- data/lib/thinreports/core/shape/basic/format.rb +11 -9
- data/lib/thinreports/core/shape/basic/interface.rb +79 -77
- data/lib/thinreports/core/shape/basic/internal.rb +17 -14
- data/lib/thinreports/core/shape/image_block.rb +9 -9
- data/lib/thinreports/core/shape/image_block/format.rb +7 -5
- data/lib/thinreports/core/shape/image_block/interface.rb +15 -13
- data/lib/thinreports/core/shape/image_block/internal.rb +10 -8
- data/lib/thinreports/core/shape/list.rb +13 -13
- data/lib/thinreports/core/shape/list/format.rb +83 -77
- data/lib/thinreports/core/shape/list/manager.rb +179 -176
- data/lib/thinreports/core/shape/list/page.rb +91 -93
- data/lib/thinreports/core/shape/list/page_state.rb +42 -40
- data/lib/thinreports/core/shape/list/section_format.rb +28 -26
- data/lib/thinreports/core/shape/list/section_interface.rb +42 -40
- data/lib/thinreports/core/shape/list/section_internal.rb +21 -19
- data/lib/thinreports/core/shape/manager.rb +4 -13
- data/lib/thinreports/core/shape/manager/format.rb +21 -19
- data/lib/thinreports/core/shape/manager/internal.rb +87 -84
- data/lib/thinreports/core/shape/manager/target.rb +93 -95
- data/lib/thinreports/core/shape/page_number.rb +9 -9
- data/lib/thinreports/core/shape/page_number/format.rb +20 -18
- data/lib/thinreports/core/shape/page_number/interface.rb +20 -18
- data/lib/thinreports/core/shape/page_number/internal.rb +46 -44
- data/lib/thinreports/core/shape/style.rb +5 -14
- data/lib/thinreports/core/shape/style/base.rb +121 -120
- data/lib/thinreports/core/shape/style/basic.rb +12 -10
- data/lib/thinreports/core/shape/style/graphic.rb +35 -33
- data/lib/thinreports/core/shape/style/text.rb +113 -107
- data/lib/thinreports/core/shape/text.rb +9 -9
- data/lib/thinreports/core/shape/text/format.rb +10 -9
- data/lib/thinreports/core/shape/text/interface.rb +13 -11
- data/lib/thinreports/core/shape/text/internal.rb +14 -12
- data/lib/thinreports/core/shape/text_block.rb +10 -10
- data/lib/thinreports/core/shape/text_block/format.rb +35 -33
- data/lib/thinreports/core/shape/text_block/formatter.rb +26 -24
- data/lib/thinreports/core/shape/text_block/formatter/basic.rb +25 -25
- data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +15 -12
- data/lib/thinreports/core/shape/text_block/formatter/number.rb +52 -34
- data/lib/thinreports/core/shape/text_block/formatter/padding.rb +17 -14
- data/lib/thinreports/core/shape/text_block/interface.rb +25 -23
- data/lib/thinreports/core/shape/text_block/internal.rb +66 -68
- data/lib/thinreports/core/utils.rb +7 -3
- data/lib/thinreports/generator/pdf.rb +24 -25
- data/lib/thinreports/generator/pdf/document.rb +109 -110
- data/lib/thinreports/generator/pdf/document/draw_shape.rb +57 -51
- data/lib/thinreports/generator/pdf/document/draw_template_items.rb +50 -47
- data/lib/thinreports/generator/pdf/document/font.rb +67 -58
- data/lib/thinreports/generator/pdf/document/graphics.rb +32 -33
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +121 -121
- data/lib/thinreports/generator/pdf/document/graphics/basic.rb +112 -114
- data/lib/thinreports/generator/pdf/document/graphics/image.rb +58 -150
- data/lib/thinreports/generator/pdf/document/graphics/text.rb +149 -137
- data/lib/thinreports/generator/pdf/document/page.rb +60 -64
- data/lib/thinreports/generator/pdf/document/parse_color.rb +37 -37
- data/lib/thinreports/generator/pdf/drawer/base.rb +41 -41
- data/lib/thinreports/generator/pdf/drawer/list.rb +56 -54
- data/lib/thinreports/generator/pdf/drawer/list_section.rb +42 -40
- data/lib/thinreports/generator/pdf/drawer/page.rb +101 -96
- data/lib/thinreports/generator/pdf/prawn_ext.rb +4 -30
- data/lib/thinreports/generator/pdf/prawn_ext/calc_image_dimensions.rb +32 -0
- data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +35 -0
- data/lib/thinreports/layout.rb +5 -7
- data/lib/thinreports/layout/base.rb +5 -9
- data/lib/thinreports/layout/format.rb +17 -13
- data/lib/thinreports/layout/legacy_schema.rb +17 -13
- data/lib/thinreports/layout/version.rb +22 -25
- data/lib/thinreports/report.rb +4 -6
- data/lib/thinreports/report/base.rb +24 -51
- data/lib/thinreports/report/internal.rb +13 -15
- data/lib/thinreports/report/page.rb +5 -11
- data/lib/thinreports/version.rb +2 -2
- data/thinreports.gemspec +10 -19
- metadata +13 -288
- data/.travis.yml +0 -19
- data/examples/character_spacing/character_spacing.rb +0 -8
- data/examples/character_spacing/character_spacing.tlf +0 -293
- data/examples/dynamic_image/dynamic_image.rb +0 -31
- data/examples/dynamic_image/dynamic_image.tlf +0 -661
- data/examples/dynamic_image/img200x100.png +0 -0
- data/examples/dynamic_image/img50x50.png +0 -0
- data/examples/dynamic_style/dynamic_style.rb +0 -150
- data/examples/dynamic_style/dynamic_style.tlf +0 -1835
- data/examples/dynamic_style/dynamic_style_in_list.tlf +0 -344
- data/examples/dynamic_style/image.png +0 -0
- data/examples/eudc/eudc.rb +0 -20
- data/examples/eudc/eudc.tlf +0 -180
- data/examples/eudc/eudc.ttf +0 -0
- data/examples/helper.rb +0 -50
- data/examples/hidden_shapes/hidden_shapes.rb +0 -9
- data/examples/hidden_shapes/hidden_shapes.tlf +0 -449
- data/examples/list_events/list_events.rb +0 -32
- data/examples/list_events/list_events.tlf +0 -361
- data/examples/list_manual_generation/list_manual_generation.rb +0 -22
- data/examples/list_manual_generation/list_manual_generation.tlf +0 -132
- data/examples/list_page_number/list_page_number.rb +0 -17
- data/examples/list_page_number/list_page_number.tlf +0 -254
- data/examples/page_number/page_number.rb +0 -33
- data/examples/page_number/page_number.tlf +0 -215
- data/examples/palleted_png/palleted_png.png +0 -0
- data/examples/palleted_png/palleted_png.rb +0 -11
- data/examples/palleted_png/palleted_png.tlf +0 -47
- data/examples/password_setting/password_setting.rb +0 -10
- data/examples/password_setting/password_setting.tlf +0 -45
- data/examples/report_callbacks/report_callbacks.rb +0 -14
- data/examples/report_callbacks/report_callbacks.tlf +0 -147
- data/examples/single_line_tblock/single_line_tblock.rb +0 -13
- data/examples/single_line_tblock/single_line_tblock.tlf +0 -170
- data/examples/tblock_overflow/tblock_overflow.rb +0 -20
- data/examples/tblock_overflow/tblock_overflow.tlf +0 -538
- data/examples/tblock_styles/font_size.tlf +0 -383
- data/examples/tblock_styles/tblock_styles.rb +0 -43
- data/examples/tblock_styles/tblock_styles.tlf +0 -889
- data/examples/text_align/text_align.rb +0 -8
- data/examples/text_align/text_align.tlf +0 -241
- data/examples/typeB_page_size/B4_ISO.tlf +0 -45
- data/examples/typeB_page_size/B4_JIS.tlf +0 -45
- data/examples/typeB_page_size/typeB_page_size.rb +0 -17
- data/examples/word_wrap/word_wrap.rb +0 -26
- data/examples/word_wrap/word_wrap.tlf +0 -297
- data/lib/thinreports/generator.rb +0 -29
- data/lib/thinreports/generator/base.rb +0 -40
- data/lib/thinreports/generator/configuration.rb +0 -31
- data/lib/thinreports/report/events.rb +0 -32
- data/test/data/font.ttf +0 -0
- data/test/data/image_normal.jpg +0 -0
- data/test/data/image_normal.png +0 -0
- data/test/data/image_normal_jpg_noext +0 -0
- data/test/data/image_normal_png_noext +0 -0
- data/test/data/image_pallete_based.png +0 -0
- data/test/data/legacy_layout/all-items.tlf +0 -1
- data/test/schema_helper.rb +0 -121
- data/test/test_helper.rb +0 -42
- data/test/tmp/.gitkeep +0 -0
- data/test/unit/core/format/test_base.rb +0 -152
- data/test/unit/core/shape/base/test_internal.rb +0 -87
- data/test/unit/core/shape/basic/test_block_format.rb +0 -23
- data/test/unit/core/shape/basic/test_block_interface.rb +0 -29
- data/test/unit/core/shape/basic/test_block_internal.rb +0 -55
- data/test/unit/core/shape/basic/test_format.rb +0 -37
- data/test/unit/core/shape/basic/test_interface.rb +0 -108
- data/test/unit/core/shape/basic/test_internal.rb +0 -55
- data/test/unit/core/shape/image_block/test_interface.rb +0 -24
- data/test/unit/core/shape/image_block/test_internal.rb +0 -31
- data/test/unit/core/shape/list/test_format.rb +0 -111
- data/test/unit/core/shape/list/test_manager.rb +0 -67
- data/test/unit/core/shape/list/test_page.rb +0 -82
- data/test/unit/core/shape/list/test_page_state.rb +0 -31
- data/test/unit/core/shape/list/test_section_format.rb +0 -36
- data/test/unit/core/shape/list/test_section_interface.rb +0 -75
- data/test/unit/core/shape/list/test_section_internal.rb +0 -50
- data/test/unit/core/shape/manager/test_format.rb +0 -38
- data/test/unit/core/shape/manager/test_internal.rb +0 -132
- data/test/unit/core/shape/manager/test_target.rb +0 -140
- data/test/unit/core/shape/page_number/test_format.rb +0 -55
- data/test/unit/core/shape/page_number/test_interface.rb +0 -33
- data/test/unit/core/shape/page_number/test_internal.rb +0 -81
- data/test/unit/core/shape/styles/test_base.rb +0 -191
- data/test/unit/core/shape/styles/test_basic.rb +0 -24
- data/test/unit/core/shape/styles/test_graphic.rb +0 -50
- data/test/unit/core/shape/styles/test_text.rb +0 -97
- data/test/unit/core/shape/text/test_format.rb +0 -44
- data/test/unit/core/shape/text/test_internal.rb +0 -20
- data/test/unit/core/shape/text_block/formatter/test_basic.rb +0 -24
- data/test/unit/core/shape/text_block/formatter/test_datetime.rb +0 -49
- data/test/unit/core/shape/text_block/formatter/test_number.rb +0 -76
- data/test/unit/core/shape/text_block/formatter/test_padding.rb +0 -77
- data/test/unit/core/shape/text_block/test_format.rb +0 -169
- data/test/unit/core/shape/text_block/test_formatter.rb +0 -28
- data/test/unit/core/shape/text_block/test_interface.rb +0 -63
- data/test/unit/core/shape/text_block/test_internal.rb +0 -128
- data/test/unit/core/test_shape.rb +0 -52
- data/test/unit/core/test_utils.rb +0 -68
- data/test/unit/generator/pdf/document/graphics/test_attributes.rb +0 -135
- data/test/unit/generator/pdf/document/graphics/test_basic.rb +0 -45
- data/test/unit/generator/pdf/document/graphics/test_image.rb +0 -150
- data/test/unit/generator/pdf/document/graphics/test_text.rb +0 -171
- data/test/unit/generator/pdf/document/test_font.rb +0 -84
- data/test/unit/generator/pdf/document/test_graphics.rb +0 -42
- data/test/unit/generator/pdf/document/test_page.rb +0 -122
- data/test/unit/generator/pdf/document/test_parse_color.rb +0 -30
- data/test/unit/generator/pdf/test_document.rb +0 -20
- data/test/unit/generator/test_base.rb +0 -40
- data/test/unit/generator/test_configuration.rb +0 -21
- data/test/unit/generator/test_pdf.rb +0 -24
- data/test/unit/layout/test_base.rb +0 -41
- data/test/unit/layout/test_format.rb +0 -100
- data/test/unit/layout/test_legacy_schema.rb +0 -574
- data/test/unit/layout/test_version.rb +0 -95
- data/test/unit/report/test_base.rb +0 -262
- data/test/unit/report/test_internal.rb +0 -206
- data/test/unit/test_config.rb +0 -51
- data/test/unit/test_layout.rb +0 -12
- data/test/unit/test_report.rb +0 -18
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
# coding: utf-8
|
|
2
|
-
|
|
3
|
-
require 'test_helper'
|
|
4
|
-
|
|
5
|
-
class Thinreports::Layout::TestVersion < Minitest::Test
|
|
6
|
-
include Thinreports::TestHelper
|
|
7
|
-
|
|
8
|
-
# Alias
|
|
9
|
-
Version = Thinreports::Layout::Version
|
|
10
|
-
|
|
11
|
-
def test_comparable_version_should_add_99_when_the_given_version_is_not_PRE
|
|
12
|
-
assert_equal Version.comparable_version('0.7.0'), '0.7.0.99'
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def test_comparable_version_should_map_pre_to_1_when_the_given_version_is_PRE
|
|
16
|
-
assert_equal Version.comparable_version('0.6.0.pre'), '0.6.0.1'
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def test_comparable_version_should_map_pre2_to_2_when_the_given_version_is_PRE2
|
|
20
|
-
assert_equal Version.comparable_version('0.6.0.pre2'), '0.6.0.2'
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def test_compare_with_equal_rule_should_return_true_when_the_given_version_is_equal_to_the_version_of_rule
|
|
24
|
-
assert Version.compare('0.7.0', '== 0.7.0')
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def test_compare_with_equal_rule_should_return_false_when_the_given_version_is_not_equal_to_the_version_of_rule
|
|
28
|
-
refute Version.compare('0.6.0.pre3', '== 0.6.0.pre2')
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def test_compare_with_larger_rule_should_return_true_when_the_given_version_is_larger_than_the_version_of_rule
|
|
32
|
-
assert Version.compare('0.7.0', '> 0.6.0.pre3')
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def test_compare_with_larger_rule_should_return_false_when_the_given_version_is_not_larger_than_the_version_of_rule
|
|
36
|
-
refute Version.compare('0.7.0', '> 0.7.0')
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def test_compare_with_one_or_more_rule_should_return_true_when_the_given_version_is_equal_to_the_version_of_rule
|
|
40
|
-
assert Version.compare('0.7.0', '>= 0.7.0')
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def test_compare_with_one_or_more_rule_should_return_true_when_the_given_version_is_larger_than_the_version_of_rule
|
|
44
|
-
assert Version.compare('0.7.0', '>= 0.6.0.pre3')
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def test_compare_with_one_or_more_rule_should_return_false_when_the_give_version_is_not_more_than_the_version_of_rule
|
|
48
|
-
refute Version.compare('0.6.0.pre3', '>= 0.7.0')
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def test_compare_with_one_or_less_rule_should_return_true_when_the_given_version_is_equal_to_the_version_of_rule
|
|
52
|
-
assert Version.compare('0.7.0', '<= 0.7.0')
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def test_compare_with_one_or_less_rule_should_return_true_when_the_given_version_is_smaller_than_the_version_of_rule
|
|
56
|
-
assert Version.compare('0.7.0', '<= 0.7.1')
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def test_compare_with_one_or_less_rule_should_return_false_when_the_given_version_is_not_less_than_the_version_of_rule
|
|
60
|
-
refute Version.compare('0.7.0', '<= 0.6.0.pre3')
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def test_inspect_required_rules_should_properly_return_an_inspection_of_rule_when_one_rule_is_given
|
|
64
|
-
required_rules('== 0.6.0') do
|
|
65
|
-
assert_equal Version.inspect_required_rules, '(== 0.6.0)'
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def test_inspect_required_rules_should_properly_return_an_inspection_of_rules_when_multiple_rules_are_given
|
|
70
|
-
required_rules('>= 0.6.0.pre3', '< 0.8.0') do
|
|
71
|
-
assert_equal Version.inspect_required_rules, '(>= 0.6.0.pre3 and < 0.8.0)'
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def test_compatible_asker_should_return_true_when_the_given_version_matches_REEQUIRED_RULES
|
|
76
|
-
required_rules('>= 0.6.0.pre3', '< 0.8.0') do
|
|
77
|
-
assert Version.compatible?('0.7.0')
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def test_compatible_asker_should_return_false_when_the_given_version_does_not_matches_REQUIRED_RULES
|
|
82
|
-
required_rules('>= 0.6.0.pre3', '< 0.8.0') do
|
|
83
|
-
refute Version.compatible?('0.8.0')
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
def required_rules(*rules, &block)
|
|
88
|
-
original_required_rules = Version::REQUIRED_RULES.dup
|
|
89
|
-
|
|
90
|
-
Version::REQUIRED_RULES.replace(rules)
|
|
91
|
-
block.call
|
|
92
|
-
ensure
|
|
93
|
-
Version::REQUIRED_RULES.replace(original_required_rules)
|
|
94
|
-
end
|
|
95
|
-
end
|
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
# coding: utf-8
|
|
2
|
-
|
|
3
|
-
require 'test_helper'
|
|
4
|
-
|
|
5
|
-
class Thinreports::Report::TestBase < Minitest::Test
|
|
6
|
-
include Thinreports::TestHelper
|
|
7
|
-
|
|
8
|
-
Report = Thinreports::Report
|
|
9
|
-
|
|
10
|
-
def setup
|
|
11
|
-
@report = Report::Base.new
|
|
12
|
-
@layout_file = layout_file
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def test_on_page_create_callback
|
|
16
|
-
report = Report::Base.new layout: @layout_file.path
|
|
17
|
-
|
|
18
|
-
counter = 0
|
|
19
|
-
callback = -> page {
|
|
20
|
-
assert_instance_of Report::Page, page
|
|
21
|
-
counter += 1
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
report.on_page_create(&callback)
|
|
25
|
-
|
|
26
|
-
2.times { report.start_new_page }
|
|
27
|
-
assert_equal counter, 2
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def test_initialize_should_register_layout_as_default_when_layout_is_specified_as_the_option
|
|
31
|
-
report = Report::Base.new layout: @layout_file.path
|
|
32
|
-
assert_equal report.default_layout.filename, @layout_file.path
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def test_initialize_should_initialize_new_Report_without_default_layout
|
|
36
|
-
assert_nil @report.default_layout
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def test_use_layout_should_register_default_layout_when_default_property_is_omitted
|
|
40
|
-
@report.use_layout(@layout_file.path)
|
|
41
|
-
|
|
42
|
-
assert_equal @report.default_layout.filename, @layout_file.path
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def test_use_layout_should_register_default_layout_when_default_property_is_true
|
|
46
|
-
@report.use_layout(@layout_file.path, default: true)
|
|
47
|
-
|
|
48
|
-
assert_equal @report.default_layout.filename, @layout_file.path
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def test_start_new_page_should_properly_create_a_new_Page_and_return
|
|
52
|
-
@report.use_layout(@layout_file.path)
|
|
53
|
-
|
|
54
|
-
assert_instance_of Thinreports::Report::Page, @report.start_new_page
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def test_start_new_page_should_raise_when_the_layout_has_not_been_registered_yet
|
|
58
|
-
assert_raises Thinreports::Errors::NoRegisteredLayoutFound do
|
|
59
|
-
@report.start_new_page(layout: :unknown)
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def test_start_new_page_should_create_a_new_page_using_a_default_layout
|
|
64
|
-
@report.use_layout(@layout_file.path, default: true)
|
|
65
|
-
|
|
66
|
-
assert_equal @report.start_new_page.layout.filename, @layout_file.path
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def test_start_new_page_should_create_a_new_page_using_a_layout_with_specified_id
|
|
70
|
-
@report.use_layout(@layout_file.path, id: :foo)
|
|
71
|
-
|
|
72
|
-
assert_equal @report.start_new_page(layout: :foo).layout.filename,
|
|
73
|
-
@layout_file.path
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def test_start_new_page_should_create_a_new_page_using_a_specified_layoutfile
|
|
77
|
-
new_page = @report.start_new_page(layout: @layout_file.path)
|
|
78
|
-
assert_equal new_page.layout.filename, @layout_file.path
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def test_start_new_page_with_count_option
|
|
82
|
-
@report.use_layout @layout_file.path, default: true
|
|
83
|
-
|
|
84
|
-
new_page = @report.start_new_page count: false
|
|
85
|
-
assert_nil new_page.no
|
|
86
|
-
assert_equal @report.page_count, 0
|
|
87
|
-
|
|
88
|
-
new_page = @report.start_new_page count: true
|
|
89
|
-
assert_equal new_page.no, 1
|
|
90
|
-
assert_equal @report.page_count, 1
|
|
91
|
-
|
|
92
|
-
new_page = @report.start_new_page
|
|
93
|
-
assert_equal new_page.no, 2
|
|
94
|
-
assert_equal @report.page_count, 2
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
def test_add_blank_page_should_properly_create_a_new_blank_page
|
|
98
|
-
@report.use_layout(@layout_file.path)
|
|
99
|
-
|
|
100
|
-
assert_instance_of Thinreports::Report::BlankPage, @report.add_blank_page
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def test_layout_should_return_the_default_layout_with_no_arguments
|
|
104
|
-
@report.use_layout(@layout_file.path, default: true)
|
|
105
|
-
|
|
106
|
-
assert_equal @report.layout.filename, @layout_file.path
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
def test_layout_should_raise_when_the_specified_layout_is_not_found
|
|
110
|
-
assert_raises Thinreports::Errors::UnknownLayoutId do
|
|
111
|
-
@report.layout(:unknown_layout_id)
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def test_layout_should_return_the_layout_with_specified_id
|
|
116
|
-
@report.use_layout(@layout_file.path, id: :foo)
|
|
117
|
-
|
|
118
|
-
assert_equal @report.layout(:foo).filename, @layout_file.path
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
def test_generate_with_filename
|
|
122
|
-
report = Report::Base.new layout: @layout_file.path
|
|
123
|
-
|
|
124
|
-
report.generate :pdf, filename: temp_path.join('result1.pdf')
|
|
125
|
-
report.generate filename: temp_path.join('result2.pdf')
|
|
126
|
-
|
|
127
|
-
assert File.exist?(temp_path.join('result1.pdf'))
|
|
128
|
-
assert File.exist?(temp_path.join('result2.pdf'))
|
|
129
|
-
|
|
130
|
-
assert_equal File.read(temp_path.join('result1.pdf')),
|
|
131
|
-
File.read(temp_path.join('result2.pdf'))
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
def test_page_should_return_the_current_page
|
|
135
|
-
@report.use_layout(@layout_file.path)
|
|
136
|
-
@report.start_new_page
|
|
137
|
-
|
|
138
|
-
assert_instance_of Thinreports::Report::Page, @report.page
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
def test_page_count_should_return_total_page_count
|
|
142
|
-
@report.use_layout(@layout_file.path)
|
|
143
|
-
2.times { @report.start_new_page }
|
|
144
|
-
|
|
145
|
-
assert_equal @report.page_count, 2
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
def test_finalize_should_finalize_report
|
|
149
|
-
@report.finalize
|
|
150
|
-
assert_equal @report.finalized?, true
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
def test_finalized_asker_should_return_false_when_report_has_not_been_finalized_yet
|
|
154
|
-
assert_equal @report.finalized?, false
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
def test_finalized_asker_should_return_true_when_report_is_already_finalized
|
|
158
|
-
@report.finalize
|
|
159
|
-
assert_equal @report.finalized?, true
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
def test_list_should_create_new_page_when_page_is_not_created
|
|
163
|
-
@report.use_layout(@layout_file.path)
|
|
164
|
-
@report.list
|
|
165
|
-
|
|
166
|
-
refute_nil @report.page
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
def test_list_should_create_new_page_when_page_is_finalized
|
|
170
|
-
@report.tap do |r|
|
|
171
|
-
r.use_layout(@layout_file.path)
|
|
172
|
-
r.start_new_page
|
|
173
|
-
r.page.finalize
|
|
174
|
-
end
|
|
175
|
-
@report.list
|
|
176
|
-
|
|
177
|
-
assert_equal @report.page.finalized?, false
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
def test_list_should_properly_return_shape_with_the_specified_id
|
|
181
|
-
@report.use_layout(@layout_file.path)
|
|
182
|
-
|
|
183
|
-
assert_equal @report.list.id, 'default'
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
def test_start_page_number
|
|
187
|
-
assert_equal @report.start_page_number, 1
|
|
188
|
-
@report.start_page_number_from 10
|
|
189
|
-
assert_equal @report.start_page_number, 10
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
def test_Base_create_should_finalize_report
|
|
193
|
-
report = Report::Base.create do |r|
|
|
194
|
-
assert_instance_of Report::Base, r
|
|
195
|
-
end
|
|
196
|
-
assert_equal report.finalized?, true
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
def test_Base_create_should_raise_when_no_block_given
|
|
200
|
-
assert_raises ArgumentError do
|
|
201
|
-
Report::Base.create
|
|
202
|
-
end
|
|
203
|
-
end
|
|
204
|
-
|
|
205
|
-
def test_Base_generate_with_filename
|
|
206
|
-
Report::Base.generate(:pdf, report: { layout: @layout_file.path },
|
|
207
|
-
generator: { filename: temp_path.join('result1.pdf') }) {}
|
|
208
|
-
Report::Base.generate(report: { layout: @layout_file.path },
|
|
209
|
-
generator: { filename: temp_path.join('result2.pdf') }) {}
|
|
210
|
-
|
|
211
|
-
assert_equal temp_path.join('result1.pdf').read,
|
|
212
|
-
temp_path.join('result2.pdf').read
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
def test_Base_generate_should_raise_when_no_block_given
|
|
216
|
-
assert_raises ArgumentError do
|
|
217
|
-
Report::Base.generate(:pdf)
|
|
218
|
-
end
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
def test_Base_extract_options_should_return_as_report_option_the_value_which_has_report_in_a_key
|
|
222
|
-
report, _generator = Report::Base.send(:extract_options!, [{report: {layout: 'hoge.tlf'}}])
|
|
223
|
-
assert_equal report[:layout], 'hoge.tlf'
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
def test_Base_extract_options_should_operate_an_argument_destructively
|
|
227
|
-
args = [:pdf, 'output.pdf', {report: {layout: 'foo.tlf'}}]
|
|
228
|
-
Report::Base.send(:extract_options!, args)
|
|
229
|
-
assert_equal args, [:pdf, 'output.pdf']
|
|
230
|
-
end
|
|
231
|
-
|
|
232
|
-
def test_Base_extract_options_should_include_the_layout_key_in_the_report_option
|
|
233
|
-
report, _generator = Report::Base.send(:extract_options!, [{layout: 'hoge.tlf'}])
|
|
234
|
-
assert_equal report[:layout], 'hoge.tlf'
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
def test_Base_extract_options_should_give_priority_to_the_value_of_the_layout_key_over_in_the_report_option
|
|
238
|
-
report, _generator = Report::Base.send(:extract_options!,
|
|
239
|
-
[{report: {layout: 'foo.tlf'}, layout: 'hoge.tlf'}])
|
|
240
|
-
assert_equal report[:layout], 'hoge.tlf'
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
def test_Base_extract_options_should_return_as_generator_option_the_value_which_has_generator_in_a_key
|
|
244
|
-
_report, generator = Report::Base.send(:extract_options!,
|
|
245
|
-
[{generator: {option: 'value'}}])
|
|
246
|
-
assert_equal generator[:option], 'value'
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
def test_Base_extract_options_should_give_priority_to_the_value_of_other_keys_over_in_the_generator_option
|
|
250
|
-
_report, generator = Report::Base.send(:extract_options!,
|
|
251
|
-
[{generator: {option: 'value1'}, option: 'value2'}])
|
|
252
|
-
assert_equal generator[:option], 'value2'
|
|
253
|
-
end
|
|
254
|
-
|
|
255
|
-
def test_Base_extract_options_should_return_all_the_values_except_the_report_option_as_a_generator_option
|
|
256
|
-
_report, generator = Report::Base.send(:extract_options!,
|
|
257
|
-
[{report: {layout: 'foo.tlf'}, layout: 'hoge.tlf',
|
|
258
|
-
generator_opt1: 'value1', generator_opt2: 'value2'}])
|
|
259
|
-
assert_equal generator.values_at(:generator_opt1, :generator_opt2),
|
|
260
|
-
['value1', 'value2']
|
|
261
|
-
end
|
|
262
|
-
end
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
# coding: utf-8
|
|
2
|
-
|
|
3
|
-
require 'test_helper'
|
|
4
|
-
|
|
5
|
-
class Thinreports::Report::TestInternal < Minitest::Test
|
|
6
|
-
include Thinreports::TestHelper
|
|
7
|
-
|
|
8
|
-
Report = Thinreports::Report
|
|
9
|
-
|
|
10
|
-
def setup
|
|
11
|
-
@layout_file = layout_file
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def report
|
|
15
|
-
Report::Base.new
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def test_layout_specified_in_new_method_should_be_defined_as_default_layout
|
|
19
|
-
internal = Report::Internal.new(report, layout: @layout_file.path)
|
|
20
|
-
assert_equal internal.default_layout.filename, @layout_file.path
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def test_register_layout_should_be_set_as_default_layout_when_options_are_omitted
|
|
24
|
-
internal = Report::Internal.new(report, {})
|
|
25
|
-
internal.register_layout(@layout_file.path)
|
|
26
|
-
|
|
27
|
-
assert_equal internal.default_layout.filename, @layout_file.path
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def test_register_layout_should_be_set_as_default_layout_when_default_option_is_true
|
|
31
|
-
internal = Report::Internal.new(report, {})
|
|
32
|
-
internal.register_layout(@layout_file.path, default: true)
|
|
33
|
-
|
|
34
|
-
assert_equal internal.default_layout.filename, @layout_file.path
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def test_register_layout_should_be_able_to_change_the_default_layout
|
|
38
|
-
internal = Report::Internal.new(report, layout: @layout_file.path)
|
|
39
|
-
internal.register_layout(@layout_file.path, default: true)
|
|
40
|
-
|
|
41
|
-
assert_equal internal.default_layout.filename, @layout_file.path
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def test_register_layout_should_be_set_as_with_id_when_id_option_is_set
|
|
45
|
-
internal = Report::Internal.new(report, {})
|
|
46
|
-
internal.register_layout(@layout_file.path, id: :foo)
|
|
47
|
-
|
|
48
|
-
assert_equal internal.layout_registry[:foo].filename, @layout_file.path
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def test_register_layout_should_raise_an_error_when_id_is_already_registered
|
|
52
|
-
internal = Report::Internal.new(report, {})
|
|
53
|
-
internal.register_layout(@layout_file.path, id: :foo)
|
|
54
|
-
|
|
55
|
-
assert_raises ArgumentError do
|
|
56
|
-
internal.register_layout(@layout_file.path, id: :foo)
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def test_add_page_should_finalize_the_current_page
|
|
61
|
-
layout = Thinreports::Layout.new(@layout_file.path)
|
|
62
|
-
|
|
63
|
-
internal = Report::Internal.new(report, layout: @layout_file.path)
|
|
64
|
-
page = internal.add_page(Thinreports::Report::Page.new(report, layout))
|
|
65
|
-
internal.add_page(Thinreports::Report::Page.new(report, layout))
|
|
66
|
-
|
|
67
|
-
assert_equal page.finalized?, true
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def test_add_page_should_return_the_current_page
|
|
71
|
-
layout = Thinreports::Layout.new(@layout_file.path)
|
|
72
|
-
new_page = Thinreports::Report::Page.new(report, layout)
|
|
73
|
-
|
|
74
|
-
internal = Report::Internal.new(report, layout: @layout_file.path)
|
|
75
|
-
|
|
76
|
-
assert_same new_page, internal.add_page(new_page)
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def test_add_page_should_add_the_initialized_page
|
|
80
|
-
layout = Thinreports::Layout.new(@layout_file.path)
|
|
81
|
-
new_page = Thinreports::Report::Page.new(report, layout)
|
|
82
|
-
|
|
83
|
-
internal = Report::Internal.new(report, layout: @layout_file.path)
|
|
84
|
-
internal.add_page(new_page)
|
|
85
|
-
|
|
86
|
-
assert_same new_page, internal.pages.last
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def test_add_page_should_count_up_the_total_page_count
|
|
90
|
-
layout = Thinreports::Layout.new(@layout_file.path)
|
|
91
|
-
|
|
92
|
-
internal = Report::Internal.new(report, layout: @layout_file.path)
|
|
93
|
-
internal.add_page(Thinreports::Report::Page.new(report, layout))
|
|
94
|
-
|
|
95
|
-
assert_equal internal.page_count, 1
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
def test_add_page_should_switch_to_a_reference_to_the_current_page
|
|
99
|
-
layout = Thinreports::Layout.new(@layout_file.path)
|
|
100
|
-
new_pages = (1..2).inject([]) do |pages|
|
|
101
|
-
pages << Thinreports::Report::Page.new(report, layout)
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
internal = Report::Internal.new(report, layout: @layout_file.path)
|
|
105
|
-
internal.add_page(new_pages[0])
|
|
106
|
-
|
|
107
|
-
assert_same internal.page, new_pages[0]
|
|
108
|
-
|
|
109
|
-
internal.add_page(new_pages[1])
|
|
110
|
-
|
|
111
|
-
assert_same internal.page, new_pages[1]
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
def test_add_blank_page_should_not_count_up_the_total_page_count_when_count_is_disabled
|
|
115
|
-
internal = Report::Internal.new(report, layout: @layout_file.path)
|
|
116
|
-
internal.add_page(Thinreports::Report::BlankPage.new(false))
|
|
117
|
-
|
|
118
|
-
assert_equal internal.page_count, 0
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
def test_add_blank_page_should_count_up_the_total_page_count_when_count_is_enabled
|
|
122
|
-
internal = Report::Internal.new(report, layout: @layout_file.path)
|
|
123
|
-
internal.add_page(Thinreports::Report::BlankPage.new)
|
|
124
|
-
|
|
125
|
-
assert_equal internal.page_count, 1
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
def test_finalize_should_finalize_the_report
|
|
129
|
-
internal = Report::Internal.new(report, layout: @layout_file.path)
|
|
130
|
-
internal.finalize
|
|
131
|
-
|
|
132
|
-
assert internal.finalized?
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
def test_finalize_should_not_work_when_report_is_already_finalized
|
|
136
|
-
internal = Report::Internal.new(report, layout: @layout_file.path)
|
|
137
|
-
internal.finalize
|
|
138
|
-
|
|
139
|
-
# #finalize_current_page must never be called
|
|
140
|
-
internal.expects(:finalize_current_page).never
|
|
141
|
-
internal.finalize
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
def test_finalized_should_return_true_when_report_is_already_finalized
|
|
145
|
-
internal = Report::Internal.new(report, layout: @layout_file.path)
|
|
146
|
-
internal.finalize
|
|
147
|
-
|
|
148
|
-
assert internal.finalized?
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
def test_load_layout_with_String
|
|
152
|
-
internal = Report::Internal.new(report, layout: @layout_file.path)
|
|
153
|
-
|
|
154
|
-
assert_equal internal.load_layout(@layout_file.path).filename,
|
|
155
|
-
@layout_file.path
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
def test_load_layout_with_id
|
|
159
|
-
internal = Report::Internal.new(report, {})
|
|
160
|
-
internal.register_layout(@layout_file.path, id: :sample)
|
|
161
|
-
|
|
162
|
-
assert_equal internal.load_layout(:sample).filename,
|
|
163
|
-
@layout_file.path
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
def test_load_layout_with_unknown_id
|
|
167
|
-
internal = Report::Internal.new(report, {})
|
|
168
|
-
assert_nil internal.load_layout(:unknown)
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
def test_load_layout_should_set_default_layout_when_default_layout_is_nil
|
|
172
|
-
internal = Report::Internal.new(report, {})
|
|
173
|
-
internal.load_layout(@layout_file.path)
|
|
174
|
-
|
|
175
|
-
assert_equal internal.default_layout.filename,
|
|
176
|
-
@layout_file.path
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
def test_load_layout_should_raise_error_when_invalid_value_set
|
|
180
|
-
internal = Report::Internal.new(report, {})
|
|
181
|
-
|
|
182
|
-
assert_raises Thinreports::Errors::LayoutFileNotFound do
|
|
183
|
-
internal.load_layout('/path/to/unkown.tlf')
|
|
184
|
-
end
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
def test_copy_page_should_finalize_current_page
|
|
188
|
-
layout = Thinreports::Layout.new(@layout_file.path)
|
|
189
|
-
|
|
190
|
-
internal = Report::Internal.new(report, layout: @layout_file.path)
|
|
191
|
-
internal.add_page(page = Thinreports::Report::Page.new(report, layout))
|
|
192
|
-
internal.copy_page
|
|
193
|
-
|
|
194
|
-
assert page.finalized?
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
def test_copy_page_should_add_the_copied_page
|
|
198
|
-
layout = Thinreports::Layout.new(@layout_file.path)
|
|
199
|
-
|
|
200
|
-
internal = Report::Internal.new(report, layout: @layout_file.path)
|
|
201
|
-
internal.add_page(Thinreports::Report::Page.new(report, layout))
|
|
202
|
-
internal.copy_page
|
|
203
|
-
|
|
204
|
-
assert_equal internal.page_count, 2
|
|
205
|
-
end
|
|
206
|
-
end
|