thinreports 0.6.0.pre3

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 (146) hide show
  1. data/.yardopts +1 -0
  2. data/README.rdoc +100 -0
  3. data/Rakefile +10 -0
  4. data/doc/yardoc_templates/default/layout/html/footer.erb +10 -0
  5. data/lib/thinreports.rb +11 -0
  6. data/lib/thinreports/core.rb +20 -0
  7. data/lib/thinreports/core/errors.rb +58 -0
  8. data/lib/thinreports/core/events.rb +71 -0
  9. data/lib/thinreports/core/ext.rb +5 -0
  10. data/lib/thinreports/core/ext/array.rb +19 -0
  11. data/lib/thinreports/core/ext/hash.rb +19 -0
  12. data/lib/thinreports/core/ext/object.rb +25 -0
  13. data/lib/thinreports/core/format.rb +14 -0
  14. data/lib/thinreports/core/format/base.rb +93 -0
  15. data/lib/thinreports/core/format/builder.rb +65 -0
  16. data/lib/thinreports/core/ordered_hash.rb +39 -0
  17. data/lib/thinreports/core/page.rb +91 -0
  18. data/lib/thinreports/core/shape.rb +53 -0
  19. data/lib/thinreports/core/shape/base.rb +16 -0
  20. data/lib/thinreports/core/shape/base/interface.rb +38 -0
  21. data/lib/thinreports/core/shape/base/internal.rb +60 -0
  22. data/lib/thinreports/core/shape/basic.rb +15 -0
  23. data/lib/thinreports/core/shape/basic/format.rb +26 -0
  24. data/lib/thinreports/core/shape/basic/interface.rb +57 -0
  25. data/lib/thinreports/core/shape/basic/internal.rb +29 -0
  26. data/lib/thinreports/core/shape/list.rb +25 -0
  27. data/lib/thinreports/core/shape/list/configuration.rb +33 -0
  28. data/lib/thinreports/core/shape/list/events.rb +30 -0
  29. data/lib/thinreports/core/shape/list/format.rb +72 -0
  30. data/lib/thinreports/core/shape/list/manager.rb +209 -0
  31. data/lib/thinreports/core/shape/list/page.rb +118 -0
  32. data/lib/thinreports/core/shape/list/page_state.rb +40 -0
  33. data/lib/thinreports/core/shape/list/section_format.rb +32 -0
  34. data/lib/thinreports/core/shape/list/section_interface.rb +48 -0
  35. data/lib/thinreports/core/shape/list/section_internal.rb +29 -0
  36. data/lib/thinreports/core/shape/list/store.rb +34 -0
  37. data/lib/thinreports/core/shape/manager.rb +14 -0
  38. data/lib/thinreports/core/shape/manager/format.rb +28 -0
  39. data/lib/thinreports/core/shape/manager/internal.rb +87 -0
  40. data/lib/thinreports/core/shape/manager/target.rb +85 -0
  41. data/lib/thinreports/core/shape/tblock.rb +16 -0
  42. data/lib/thinreports/core/shape/tblock/format.rb +36 -0
  43. data/lib/thinreports/core/shape/tblock/formatter.rb +32 -0
  44. data/lib/thinreports/core/shape/tblock/formatter/basic.rb +38 -0
  45. data/lib/thinreports/core/shape/tblock/formatter/datetime.rb +21 -0
  46. data/lib/thinreports/core/shape/tblock/formatter/number.rb +49 -0
  47. data/lib/thinreports/core/shape/tblock/formatter/padding.rb +43 -0
  48. data/lib/thinreports/core/shape/tblock/interface.rb +52 -0
  49. data/lib/thinreports/core/shape/tblock/internal.rb +70 -0
  50. data/lib/thinreports/core/shape/text.rb +15 -0
  51. data/lib/thinreports/core/shape/text/format.rb +25 -0
  52. data/lib/thinreports/core/shape/text/interface.rb +16 -0
  53. data/lib/thinreports/core/shape/text/internal.rb +17 -0
  54. data/lib/thinreports/core/utils.rb +48 -0
  55. data/lib/thinreports/generator.rb +30 -0
  56. data/lib/thinreports/generator/base.rb +49 -0
  57. data/lib/thinreports/generator/pdf.rb +63 -0
  58. data/lib/thinreports/generator/pdf/document.rb +171 -0
  59. data/lib/thinreports/generator/pdf/document/draw_shape.rb +74 -0
  60. data/lib/thinreports/generator/pdf/document/font.rb +59 -0
  61. data/lib/thinreports/generator/pdf/document/graphics.rb +42 -0
  62. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +92 -0
  63. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +132 -0
  64. data/lib/thinreports/generator/pdf/document/graphics/image.rb +51 -0
  65. data/lib/thinreports/generator/pdf/document/graphics/text.rb +130 -0
  66. data/lib/thinreports/generator/pdf/document/parse_color.rb +51 -0
  67. data/lib/thinreports/generator/pdf/document/parse_svg.rb +102 -0
  68. data/lib/thinreports/generator/pdf/drawer.rb +16 -0
  69. data/lib/thinreports/generator/pdf/drawer/base.rb +56 -0
  70. data/lib/thinreports/generator/pdf/drawer/list.rb +39 -0
  71. data/lib/thinreports/generator/pdf/drawer/list_section.rb +46 -0
  72. data/lib/thinreports/generator/pdf/drawer/page.rb +101 -0
  73. data/lib/thinreports/generator/pdf/prawn_ext.rb +36 -0
  74. data/lib/thinreports/generator/pxd.rb +75 -0
  75. data/lib/thinreports/generator/pxd/helper.rb +33 -0
  76. data/lib/thinreports/generator/pxd/list_renderer.rb +58 -0
  77. data/lib/thinreports/generator/pxd/page_renderer.rb +75 -0
  78. data/lib/thinreports/layout.rb +17 -0
  79. data/lib/thinreports/layout/base.rb +78 -0
  80. data/lib/thinreports/layout/configuration.rb +27 -0
  81. data/lib/thinreports/layout/format.rb +77 -0
  82. data/lib/thinreports/layout/version.rb +43 -0
  83. data/lib/thinreports/report.rb +31 -0
  84. data/lib/thinreports/report/base.rb +160 -0
  85. data/lib/thinreports/report/events.rb +32 -0
  86. data/lib/thinreports/report/internal.rb +131 -0
  87. data/resources/fonts/IPA_Font_License_Agreement_v1.0.txt +117 -0
  88. data/resources/fonts/ipag.ttf +0 -0
  89. data/resources/fonts/ipagp.ttf +0 -0
  90. data/resources/fonts/ipam.ttf +0 -0
  91. data/resources/fonts/ipamp.ttf +0 -0
  92. data/tasks/clean.rake +6 -0
  93. data/tasks/doc.rake +13 -0
  94. data/tasks/test.rake +18 -0
  95. data/test/unit/core/ext/array_spec.rb +29 -0
  96. data/test/unit/core/ext/hash_spec.rb +29 -0
  97. data/test/unit/core/ext/object_spec.rb +30 -0
  98. data/test/unit/core/format/test_base.rb +148 -0
  99. data/test/unit/core/format/test_builder.rb +114 -0
  100. data/test/unit/core/ordered_hash_spec.rb +51 -0
  101. data/test/unit/core/shape/base/test_interface.rb +52 -0
  102. data/test/unit/core/shape/base/test_internal.rb +109 -0
  103. data/test/unit/core/shape/basic/test_format.rb +59 -0
  104. data/test/unit/core/shape/basic/test_interface.rb +70 -0
  105. data/test/unit/core/shape/basic/test_internal.rb +42 -0
  106. data/test/unit/core/shape/list/test_configuration.rb +52 -0
  107. data/test/unit/core/shape/list/test_events.rb +28 -0
  108. data/test/unit/core/shape/list/test_format.rb +71 -0
  109. data/test/unit/core/shape/list/test_page.rb +10 -0
  110. data/test/unit/core/shape/list/test_page_state.rb +31 -0
  111. data/test/unit/core/shape/list/test_section_format.rb +46 -0
  112. data/test/unit/core/shape/list/test_section_interface.rb +52 -0
  113. data/test/unit/core/shape/list/test_section_internal.rb +30 -0
  114. data/test/unit/core/shape/list/test_store.rb +41 -0
  115. data/test/unit/core/shape/manager/test_format.rb +40 -0
  116. data/test/unit/core/shape/manager/test_internal.rb +137 -0
  117. data/test/unit/core/shape/manager/test_target.rb +109 -0
  118. data/test/unit/core/shape/tblock/formatter/test_basic.rb +24 -0
  119. data/test/unit/core/shape/tblock/formatter/test_datetime.rb +47 -0
  120. data/test/unit/core/shape/tblock/formatter/test_number.rb +76 -0
  121. data/test/unit/core/shape/tblock/formatter/test_padding.rb +72 -0
  122. data/test/unit/core/shape/tblock/test_format.rb +125 -0
  123. data/test/unit/core/shape/tblock/test_formatter.rb +28 -0
  124. data/test/unit/core/shape/tblock/test_interface.rb +40 -0
  125. data/test/unit/core/shape/tblock/test_internal.rb +139 -0
  126. data/test/unit/core/shape/text/test_format.rb +73 -0
  127. data/test/unit/core/shape/text/test_internal.rb +21 -0
  128. data/test/unit/core/test_events.rb +91 -0
  129. data/test/unit/core/test_shape.rb +35 -0
  130. data/test/unit/core/utils_spec.rb +56 -0
  131. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +103 -0
  132. data/test/unit/generator/pdf/document/test_font.rb +54 -0
  133. data/test/unit/generator/pdf/document/test_graphics.rb +43 -0
  134. data/test/unit/generator/pdf/document/test_parse_color.rb +30 -0
  135. data/test/unit/generator/test_base.rb +51 -0
  136. data/test/unit/helper.rb +37 -0
  137. data/test/unit/layout/test_base.rb +92 -0
  138. data/test/unit/layout/test_configuration.rb +46 -0
  139. data/test/unit/layout/test_format.rb +104 -0
  140. data/test/unit/layout/test_version.rb +62 -0
  141. data/test/unit/report/test_base.rb +187 -0
  142. data/test/unit/report/test_events.rb +22 -0
  143. data/test/unit/report/test_internal.rb +234 -0
  144. data/test/unit/test_layout.rb +12 -0
  145. data/test/unit/test_report.rb +30 -0
  146. metadata +218 -0
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Core::Shape::Tblock::Formatter::TestBasic < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ # Alias
9
+ Formatter = ThinReports::Core::Shape::Tblock::Formatter::Basic
10
+
11
+ def test_apply_simple_format
12
+ format = flexmock(:format_base => 'Hello {value}!')
13
+
14
+ assert_equal Formatter.new(format).apply('ThinReports'),
15
+ 'Hello ThinReports!'
16
+ end
17
+
18
+ def test_apply_multiple_format
19
+ format = flexmock(:format_base => 'Hello {value}! And good bye {value}.')
20
+
21
+ assert_equal Formatter.new(format).apply('ThinReports'),
22
+ 'Hello ThinReports! And good bye ThinReports.'
23
+ end
24
+ end
@@ -0,0 +1,47 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Core::Shape::Tblock::Formatter::TestDatetime < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ # Alias
9
+ Formatter = ThinReports::Core::Shape::Tblock::Formatter::Datetime
10
+
11
+ def setup
12
+ @datetime_format = '%Y/%m/%d %H:%M:%S'
13
+ @time = Time.now
14
+
15
+ @format = flexmock(:format_base => '',
16
+ :format_datetime_format => @datetime_format)
17
+ end
18
+
19
+ def test_apply_datetime_format_without_basic_format
20
+ formatter = Formatter.new(@format)
21
+
22
+ assert_equal formatter.apply(@time), @time.strftime(@datetime_format)
23
+ end
24
+
25
+ def test_apply_datetime_format_with_basic_format
26
+ # Partial mock
27
+ format = flexmock(@format, :format_base => 'Now: {value}')
28
+
29
+ formatter = Formatter.new(format)
30
+
31
+ assert_equal formatter.apply(@time),
32
+ "Now: #{@time.strftime(@datetime_format)}"
33
+ end
34
+
35
+ def test_not_apply_datetime_format_and_return_raw_value
36
+ # When value is invalid
37
+ formatter = Formatter.new(@format)
38
+
39
+ assert_same formatter.apply(val = 'invalid value'), val
40
+ assert_same formatter.apply(val = 123456), val
41
+
42
+ # When format is empty
43
+ format = flexmock(@format, :format_datetime_format => '')
44
+
45
+ assert_same formatter.apply(@time), @time
46
+ end
47
+ end
@@ -0,0 +1,76 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Core::Shape::Tblock::Formatter::TestNumber < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ # Alias
9
+ Formatter = ThinReports::Core::Shape::Tblock::Formatter::Number
10
+
11
+ def init_formatter(expect_formats)
12
+ format = flexmock({:format_base => '',
13
+ :format_number_precision => nil,
14
+ :format_number_delimiter => nil}.merge(expect_formats))
15
+ Formatter.new(format)
16
+ end
17
+
18
+ def test_apply_precision_formats
19
+ # When precision is 2
20
+ formatter = init_formatter(:format_number_precision => 2)
21
+
22
+ assert_equal formatter.apply(1.005), '1.01'
23
+ assert_equal formatter.apply(1.004), '1.00'
24
+ assert_equal formatter.apply(1), '1.00'
25
+ # With String value
26
+ assert_equal formatter.apply('999.999'), '1000.00'
27
+ assert_equal formatter.apply('-999.999'), '-1000.00'
28
+ assert_equal formatter.apply('9'), '9.00'
29
+ # Cannot apply, Return the raw value
30
+ assert_equal formatter.apply('invalid value'), 'invalid value'
31
+
32
+ # When precision is 0
33
+ formatter = init_formatter(:format_number_precision => 0)
34
+
35
+ assert_equal formatter.apply(1.5), '2'
36
+ end
37
+
38
+ def test_apply_precision_format_with_basic_format
39
+ formatter = init_formatter(:format_base => '$ {value}',
40
+ :format_number_precision => 0)
41
+
42
+ assert_equal formatter.apply(199.5), '$ 200'
43
+ end
44
+
45
+ def test_apply_delimiter_formats
46
+ # When delimiter is ','
47
+ formatter = init_formatter(:format_number_delimiter => ',')
48
+
49
+ assert_equal formatter.apply(1000000), '1,000,000'
50
+ assert_equal formatter.apply(-1000000), '-1,000,000'
51
+ assert_equal formatter.apply('1000.0'), '1,000.0'
52
+ assert_equal formatter.apply('-1000.0'), '-1,000.0'
53
+ # Cannot apply, Return the raw value
54
+ assert_equal formatter.apply('invalid value'), 'invalid value'
55
+
56
+ # When delimiter is whitespace
57
+ formatter = init_formatter(:format_number_delimiter => ' ')
58
+
59
+ assert_equal formatter.apply(99999), '99 999'
60
+ end
61
+
62
+ def test_apply_delimiter_format_with_basic_format
63
+ formatter = init_formatter(:format_base => '¥{value}',
64
+ :format_number_delimiter => ',')
65
+
66
+ assert_equal formatter.apply(199800), '¥199,800'
67
+ end
68
+
69
+ def test_apply_all_format
70
+ formatter = init_formatter(:format_base => '-- {value} --',
71
+ :format_number_delimiter => ',',
72
+ :format_number_precision => 2)
73
+
74
+ assert_equal formatter.apply(95618.88567), '-- 95,618.89 --'
75
+ end
76
+ end
@@ -0,0 +1,72 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Core::Shape::Tblock::Formatter::TestPadding < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ # Alias
9
+ Formatter = ThinReports::Core::Shape::Tblock::Formatter::Padding
10
+
11
+ def init_formatter(expect_formats)
12
+ format = flexmock({:format_base => nil,
13
+ :format_padding_length => 0,
14
+ :format_padding_char => nil,
15
+ :format_padding_rdir? => false}.merge(expect_formats))
16
+ Formatter.new(format)
17
+ end
18
+
19
+ def test_apply_padding_formats
20
+ formatter = init_formatter(:format_padding_length => 5,
21
+ :format_padding_char => '0')
22
+
23
+ assert_equal formatter.apply(1), '00001'
24
+ assert_equal formatter.apply('日本語'), '00日本語'
25
+
26
+ # Text length is longer than the specified length.
27
+ assert_equal formatter.apply('1234567'), '1234567'
28
+
29
+ # When direction is right
30
+ formatter = init_formatter(:format_padding_length => 5,
31
+ :format_padding_char => '0',
32
+ :format_padding_rdir? => true)
33
+
34
+ assert_equal formatter.apply(123), '12300'
35
+ end
36
+
37
+ def test_apply_padding_format_with_basic_format
38
+ formatter = init_formatter(:format_base => '[{value}]',
39
+ :format_padding_length => 10,
40
+ :format_padding_char => ' ')
41
+
42
+ assert_equal formatter.apply('ABC'), '[ ABC]'
43
+ end
44
+
45
+ def test_return_raw_value_when_length_is_0
46
+ formatter = init_formatter(:format_padding_length => 0,
47
+ :format_padding_char => '0')
48
+
49
+ assert_same formatter.apply(v = 123), v
50
+
51
+ # But apply only basic format if have basic-format.
52
+ formatter = init_formatter(:format_base => '<{value}>',
53
+ :format_padding_length => 0,
54
+ :format_padding_char => '0')
55
+
56
+ assert_equal formatter.apply(123), '<123>'
57
+ end
58
+
59
+ def test_return_raw_value_when_char_is_empty
60
+ formatter = init_formatter(:format_padding_length => 10,
61
+ :format_padding_char => '')
62
+
63
+ assert_same formatter.apply(v = '1'), v
64
+
65
+ # But apply only basic format if have basic-format.
66
+ formatter = init_formatter(:format_base => '<{value}>',
67
+ :format_padding_length => 0,
68
+ :format_padding_char => '0')
69
+
70
+ assert_equal formatter.apply('1'), '<1>'
71
+ end
72
+ end
@@ -0,0 +1,125 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Core::Shape::Tblock::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
51
+ flunk exception_details(e, 'Building failed.')
52
+ end
53
+
54
+ def test_config_readers
55
+ format = format(TEST_TBLOCK_FORMAT)
56
+
57
+ assert_equal format.value, ''
58
+ assert_equal format.ref_id, ''
59
+ assert_equal format.format_base, '¥{value}'
60
+ assert_equal format.format_type, 'number'
61
+ assert_instance_of ::Hash, format.box
62
+ assert_equal format.box['x'], 100.0
63
+
64
+ # Methods reference to unknown value returns a nil value
65
+ assert_nil format.format_datetime_format
66
+ assert_nil format.format_padding_char
67
+ assert_nil format.format_padding_dir
68
+
69
+ # In face, #format_padding_length returns a nil value
70
+ assert_equal format.format_padding_length, 0
71
+
72
+ assert_equal format.format_padding_rdir?, false
73
+ assert_equal format.has_format?, true
74
+ assert_equal format.has_reference?, false
75
+ assert_equal format.multiple?, false
76
+ end
77
+
78
+ def test_multiple?
79
+ assert format('multiple' => 'true').multiple?
80
+ refute format('multiple' => 'false').multiple?
81
+ end
82
+
83
+ def test_format_padding_rdir?
84
+ data = {'format' => {'padding' => {'direction' => 'L'}}}
85
+
86
+ refute format(data).format_padding_rdir?
87
+
88
+ data['format']['padding']['direction'] = 'R'
89
+ assert format(data).format_padding_rdir?
90
+ end
91
+
92
+ def test_format_padding_length
93
+ data = {'format' => {'padding' => {'length' => '0'}}}
94
+
95
+ assert_equal format(data).format_padding_length, 0
96
+
97
+ data['format']['padding']['length'] = '10'
98
+ assert_equal format(data).format_padding_length, 10
99
+ end
100
+
101
+ def test_has_format?
102
+ data = {'format' => {'type' => ''}}
103
+
104
+ refute format(data).has_format?
105
+
106
+ data['format']['type'] = 'number'
107
+ assert format(data).has_format?
108
+
109
+ data['format']['type'] = 'unknown'
110
+ refute format(data).has_format?
111
+ end
112
+
113
+ def test_has_reference?
114
+ refute format('ref-id' => '').has_reference?
115
+ assert format('ref-id' => 'ref_tblock_1').has_reference?
116
+ end
117
+
118
+ def build_format
119
+ ThinReports::Core::Shape::Tblock::Format.build(TEST_TBLOCK_FORMAT)
120
+ end
121
+
122
+ def format(data)
123
+ ThinReports::Core::Shape::Tblock::Format.new(data)
124
+ end
125
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Core::Shape::Tblock::TestFormatter < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ # Alias
9
+ Formatter = ThinReports::Core::Shape::Tblock::Formatter
10
+
11
+ def test_initialize_formatter_by_type
12
+ assert_instance_of Formatter::Basic,
13
+ Formatter.setup( flexmock(:format_type => '') )
14
+
15
+ assert_instance_of Formatter::Number,
16
+ Formatter.setup( flexmock(:format_type => 'number') )
17
+
18
+ assert_instance_of Formatter::Datetime,
19
+ Formatter.setup( flexmock(:format_type => 'datetime') )
20
+
21
+ assert_instance_of Formatter::Padding,
22
+ Formatter.setup( flexmock(:format_type => 'padding') )
23
+
24
+ assert_raises ThinReports::Errors::UnknownFormatterType do
25
+ Formatter.setup( flexmock(:format_type => 'unknown') )
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Core::Shape::Tblock::TestInterface < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ Tblock = ThinReports::Core::Shape::Tblock
9
+
10
+ def setup
11
+ @interface = Tblock::Interface.new(flexmock('parent'), flexmock('format'))
12
+ end
13
+
14
+ def test_value_work_as_getter_when_receive_no_arguments
15
+ flexmock(@interface.internal).should_receive(:read_value).
16
+ and_return('value').once
17
+
18
+ assert_equal @interface.value, 'value'
19
+ end
20
+
21
+ def test_value_work_as_setter_when_receive_an_just_one_argument
22
+ flexmock(@interface.internal).should_receive(:write_value).once
23
+
24
+ @interface.value('any value')
25
+ end
26
+
27
+ def test_value_raise_error_when_receive_more_than_two
28
+ assert_raises ArgumentError do
29
+ @interface.value('arg1', 'arg2')
30
+ end
31
+ end
32
+
33
+ def test_set
34
+ flexmock(@interface).
35
+ should_receive(:value).once.
36
+ should_receive(:styles).once
37
+
38
+ @interface.set('value', :fill => 'red')
39
+ end
40
+ end
@@ -0,0 +1,139 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Core::Shape::Tblock::TestInternal < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ Tblock = ThinReports::Core::Shape::Tblock
9
+
10
+ def test_read_value_return_the_format_value
11
+ format = flexmock('format')
12
+ format.should_receive(:value => 'format value').times(2)
13
+ format.should_receive(:has_reference? => false)
14
+
15
+ internal = init_internal(format)
16
+
17
+ assert_equal internal.read_value, 'format value'
18
+ assert_equal internal.value, 'format value'
19
+ end
20
+
21
+ def test_read_value_return_the_value_of_referenced_shape
22
+ format = flexmock('format')
23
+ format.should_receive(:has_reference? => true)
24
+ format.should_receive(:ref_id => 'dummy')
25
+
26
+ internal = init_internal(format)
27
+
28
+ assert_equal internal.read_value, 'referenced value'
29
+ assert_equal internal.value, 'referenced value'
30
+ end
31
+
32
+ def test_read_value_return_the_value_stored_in_states
33
+ format = flexmock('format')
34
+ format.should_receive(:has_reference? => false)
35
+
36
+ internal = init_internal(format)
37
+ internal.states[:value] = 'any value'
38
+
39
+ assert_equal internal.read_value, 'any value'
40
+ assert_equal internal.value, 'any value'
41
+ end
42
+
43
+ def test_write_value
44
+ format = flexmock('format')
45
+ format.should_receive(:has_reference? => false)
46
+
47
+ internal = init_internal(format)
48
+ internal.write_value('value written')
49
+
50
+ assert_equal internal.value, 'value written'
51
+ end
52
+
53
+ def test_write_value_show_warnings_when_has_reference
54
+ format = flexmock('format')
55
+ format.should_receive(:has_reference? => true,
56
+ :ref_id => 'ref id',
57
+ :id => 'id')
58
+ out, err = capture_io do
59
+ init_internal(format).write_value('value written')
60
+ end
61
+ assert_equal err.chomp, 'The set value is not reflected, ' +
62
+ "Because 'id' refers to 'ref id'."
63
+ end
64
+
65
+ def test_real_value_return_the_formatted_value
66
+ format = flexmock('format')
67
+ format.should_receive(:has_format? => true,
68
+ :multiple? => false)
69
+
70
+ internal = init_internal(format)
71
+ flexmock(internal, :read_value => 'dummy')
72
+
73
+ assert_equal internal.real_value, 'formatted value'
74
+ end
75
+
76
+ def test_real_value_return_the_raw_value_when_has_not_format
77
+ format = flexmock('format')
78
+ format.should_receive(:has_format? => false,
79
+ :multiple? => false)
80
+
81
+ internal = init_internal(format)
82
+ flexmock(internal, :read_value => 'raw value')
83
+
84
+ assert_equal internal.real_value, 'raw value'
85
+ end
86
+
87
+ def test_real_value_return_the_raw_value_constantly_when_is_multiple
88
+ format = flexmock('format')
89
+ format.should_receive(:has_format? => true,
90
+ :multiple? => true)
91
+
92
+ internal = init_internal(format)
93
+ flexmock(internal, :read_value => 'raw value')
94
+
95
+ assert_equal internal.real_value, 'raw value'
96
+ end
97
+
98
+ def test_format_enabled
99
+ internal = init_internal(flexmock('format'))
100
+ internal.format_enabled(true)
101
+
102
+ assert_equal internal.states[:format_enabled], true
103
+ end
104
+
105
+ def test_format_enabled?
106
+ internal = init_internal(flexmock(:has_format? => true,
107
+ :multiple? => false))
108
+
109
+ assert_equal internal.format_enabled?, true
110
+
111
+ internal.format_enabled(false)
112
+
113
+ assert_equal internal.format_enabled?, false
114
+
115
+ flexmock(internal.format, :multiple? => true)
116
+ internal.format_enabled(true)
117
+
118
+ assert_equal internal.format_enabled?, false
119
+ end
120
+
121
+ def test_type_of?
122
+ assert_equal init_internal(flexmock('format')).type_of?(:tblock), true
123
+ end
124
+
125
+ def init_internal(format)
126
+ parent = flexmock('parent')
127
+ parent.should_receive(:item).
128
+ and_return(flexmock(:value => 'referenced value'))
129
+
130
+ formatter = flexmock('formatter')
131
+ formatter.should_receive(:apply).
132
+ and_return('formatted value')
133
+
134
+ flexmock(Tblock::Internal).new_instances.should_receive(:formatter).
135
+ and_return(formatter)
136
+
137
+ Tblock::Internal.new(parent, format)
138
+ end
139
+ end