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.
- data/.yardopts +1 -0
- data/README.rdoc +100 -0
- data/Rakefile +10 -0
- data/doc/yardoc_templates/default/layout/html/footer.erb +10 -0
- data/lib/thinreports.rb +11 -0
- data/lib/thinreports/core.rb +20 -0
- data/lib/thinreports/core/errors.rb +58 -0
- data/lib/thinreports/core/events.rb +71 -0
- data/lib/thinreports/core/ext.rb +5 -0
- data/lib/thinreports/core/ext/array.rb +19 -0
- data/lib/thinreports/core/ext/hash.rb +19 -0
- data/lib/thinreports/core/ext/object.rb +25 -0
- data/lib/thinreports/core/format.rb +14 -0
- data/lib/thinreports/core/format/base.rb +93 -0
- data/lib/thinreports/core/format/builder.rb +65 -0
- data/lib/thinreports/core/ordered_hash.rb +39 -0
- data/lib/thinreports/core/page.rb +91 -0
- data/lib/thinreports/core/shape.rb +53 -0
- data/lib/thinreports/core/shape/base.rb +16 -0
- data/lib/thinreports/core/shape/base/interface.rb +38 -0
- data/lib/thinreports/core/shape/base/internal.rb +60 -0
- data/lib/thinreports/core/shape/basic.rb +15 -0
- data/lib/thinreports/core/shape/basic/format.rb +26 -0
- data/lib/thinreports/core/shape/basic/interface.rb +57 -0
- data/lib/thinreports/core/shape/basic/internal.rb +29 -0
- data/lib/thinreports/core/shape/list.rb +25 -0
- data/lib/thinreports/core/shape/list/configuration.rb +33 -0
- data/lib/thinreports/core/shape/list/events.rb +30 -0
- data/lib/thinreports/core/shape/list/format.rb +72 -0
- data/lib/thinreports/core/shape/list/manager.rb +209 -0
- data/lib/thinreports/core/shape/list/page.rb +118 -0
- data/lib/thinreports/core/shape/list/page_state.rb +40 -0
- data/lib/thinreports/core/shape/list/section_format.rb +32 -0
- data/lib/thinreports/core/shape/list/section_interface.rb +48 -0
- data/lib/thinreports/core/shape/list/section_internal.rb +29 -0
- data/lib/thinreports/core/shape/list/store.rb +34 -0
- data/lib/thinreports/core/shape/manager.rb +14 -0
- data/lib/thinreports/core/shape/manager/format.rb +28 -0
- data/lib/thinreports/core/shape/manager/internal.rb +87 -0
- data/lib/thinreports/core/shape/manager/target.rb +85 -0
- data/lib/thinreports/core/shape/tblock.rb +16 -0
- data/lib/thinreports/core/shape/tblock/format.rb +36 -0
- data/lib/thinreports/core/shape/tblock/formatter.rb +32 -0
- data/lib/thinreports/core/shape/tblock/formatter/basic.rb +38 -0
- data/lib/thinreports/core/shape/tblock/formatter/datetime.rb +21 -0
- data/lib/thinreports/core/shape/tblock/formatter/number.rb +49 -0
- data/lib/thinreports/core/shape/tblock/formatter/padding.rb +43 -0
- data/lib/thinreports/core/shape/tblock/interface.rb +52 -0
- data/lib/thinreports/core/shape/tblock/internal.rb +70 -0
- data/lib/thinreports/core/shape/text.rb +15 -0
- data/lib/thinreports/core/shape/text/format.rb +25 -0
- data/lib/thinreports/core/shape/text/interface.rb +16 -0
- data/lib/thinreports/core/shape/text/internal.rb +17 -0
- data/lib/thinreports/core/utils.rb +48 -0
- data/lib/thinreports/generator.rb +30 -0
- data/lib/thinreports/generator/base.rb +49 -0
- data/lib/thinreports/generator/pdf.rb +63 -0
- data/lib/thinreports/generator/pdf/document.rb +171 -0
- data/lib/thinreports/generator/pdf/document/draw_shape.rb +74 -0
- data/lib/thinreports/generator/pdf/document/font.rb +59 -0
- data/lib/thinreports/generator/pdf/document/graphics.rb +42 -0
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +92 -0
- data/lib/thinreports/generator/pdf/document/graphics/basic.rb +132 -0
- data/lib/thinreports/generator/pdf/document/graphics/image.rb +51 -0
- data/lib/thinreports/generator/pdf/document/graphics/text.rb +130 -0
- data/lib/thinreports/generator/pdf/document/parse_color.rb +51 -0
- data/lib/thinreports/generator/pdf/document/parse_svg.rb +102 -0
- data/lib/thinreports/generator/pdf/drawer.rb +16 -0
- data/lib/thinreports/generator/pdf/drawer/base.rb +56 -0
- data/lib/thinreports/generator/pdf/drawer/list.rb +39 -0
- data/lib/thinreports/generator/pdf/drawer/list_section.rb +46 -0
- data/lib/thinreports/generator/pdf/drawer/page.rb +101 -0
- data/lib/thinreports/generator/pdf/prawn_ext.rb +36 -0
- data/lib/thinreports/generator/pxd.rb +75 -0
- data/lib/thinreports/generator/pxd/helper.rb +33 -0
- data/lib/thinreports/generator/pxd/list_renderer.rb +58 -0
- data/lib/thinreports/generator/pxd/page_renderer.rb +75 -0
- data/lib/thinreports/layout.rb +17 -0
- data/lib/thinreports/layout/base.rb +78 -0
- data/lib/thinreports/layout/configuration.rb +27 -0
- data/lib/thinreports/layout/format.rb +77 -0
- data/lib/thinreports/layout/version.rb +43 -0
- data/lib/thinreports/report.rb +31 -0
- data/lib/thinreports/report/base.rb +160 -0
- data/lib/thinreports/report/events.rb +32 -0
- data/lib/thinreports/report/internal.rb +131 -0
- data/resources/fonts/IPA_Font_License_Agreement_v1.0.txt +117 -0
- data/resources/fonts/ipag.ttf +0 -0
- data/resources/fonts/ipagp.ttf +0 -0
- data/resources/fonts/ipam.ttf +0 -0
- data/resources/fonts/ipamp.ttf +0 -0
- data/tasks/clean.rake +6 -0
- data/tasks/doc.rake +13 -0
- data/tasks/test.rake +18 -0
- data/test/unit/core/ext/array_spec.rb +29 -0
- data/test/unit/core/ext/hash_spec.rb +29 -0
- data/test/unit/core/ext/object_spec.rb +30 -0
- data/test/unit/core/format/test_base.rb +148 -0
- data/test/unit/core/format/test_builder.rb +114 -0
- data/test/unit/core/ordered_hash_spec.rb +51 -0
- data/test/unit/core/shape/base/test_interface.rb +52 -0
- data/test/unit/core/shape/base/test_internal.rb +109 -0
- data/test/unit/core/shape/basic/test_format.rb +59 -0
- data/test/unit/core/shape/basic/test_interface.rb +70 -0
- data/test/unit/core/shape/basic/test_internal.rb +42 -0
- data/test/unit/core/shape/list/test_configuration.rb +52 -0
- data/test/unit/core/shape/list/test_events.rb +28 -0
- data/test/unit/core/shape/list/test_format.rb +71 -0
- data/test/unit/core/shape/list/test_page.rb +10 -0
- data/test/unit/core/shape/list/test_page_state.rb +31 -0
- data/test/unit/core/shape/list/test_section_format.rb +46 -0
- data/test/unit/core/shape/list/test_section_interface.rb +52 -0
- data/test/unit/core/shape/list/test_section_internal.rb +30 -0
- data/test/unit/core/shape/list/test_store.rb +41 -0
- data/test/unit/core/shape/manager/test_format.rb +40 -0
- data/test/unit/core/shape/manager/test_internal.rb +137 -0
- data/test/unit/core/shape/manager/test_target.rb +109 -0
- data/test/unit/core/shape/tblock/formatter/test_basic.rb +24 -0
- data/test/unit/core/shape/tblock/formatter/test_datetime.rb +47 -0
- data/test/unit/core/shape/tblock/formatter/test_number.rb +76 -0
- data/test/unit/core/shape/tblock/formatter/test_padding.rb +72 -0
- data/test/unit/core/shape/tblock/test_format.rb +125 -0
- data/test/unit/core/shape/tblock/test_formatter.rb +28 -0
- data/test/unit/core/shape/tblock/test_interface.rb +40 -0
- data/test/unit/core/shape/tblock/test_internal.rb +139 -0
- data/test/unit/core/shape/text/test_format.rb +73 -0
- data/test/unit/core/shape/text/test_internal.rb +21 -0
- data/test/unit/core/test_events.rb +91 -0
- data/test/unit/core/test_shape.rb +35 -0
- data/test/unit/core/utils_spec.rb +56 -0
- data/test/unit/generator/pdf/document/graphics/test_attributes.rb +103 -0
- data/test/unit/generator/pdf/document/test_font.rb +54 -0
- data/test/unit/generator/pdf/document/test_graphics.rb +43 -0
- data/test/unit/generator/pdf/document/test_parse_color.rb +30 -0
- data/test/unit/generator/test_base.rb +51 -0
- data/test/unit/helper.rb +37 -0
- data/test/unit/layout/test_base.rb +92 -0
- data/test/unit/layout/test_configuration.rb +46 -0
- data/test/unit/layout/test_format.rb +104 -0
- data/test/unit/layout/test_version.rb +62 -0
- data/test/unit/report/test_base.rb +187 -0
- data/test/unit/report/test_events.rb +22 -0
- data/test/unit/report/test_internal.rb +234 -0
- data/test/unit/test_layout.rb +12 -0
- data/test/unit/test_report.rb +30 -0
- metadata +218 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'test/unit/helper'
|
|
4
|
+
|
|
5
|
+
class ThinReports::Core::Shape::List::TestPageState < MiniTest::Unit::TestCase
|
|
6
|
+
include ThinReports::TestHelpers
|
|
7
|
+
|
|
8
|
+
# Alias
|
|
9
|
+
List = ThinReports::Core::Shape::List
|
|
10
|
+
|
|
11
|
+
def setup
|
|
12
|
+
parent = flexmock('parent')
|
|
13
|
+
format = flexmock('format')
|
|
14
|
+
|
|
15
|
+
@state = List::PageState.new(parent, format)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_alias_class
|
|
19
|
+
assert_same List::PageState, List::Internal
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_type_of?
|
|
23
|
+
assert_equal @state.type_of?(:list), true
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_finalized!
|
|
27
|
+
assert_equal @state.finalized?, false
|
|
28
|
+
@state.finalized!
|
|
29
|
+
assert_equal @state.finalized?, true
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'test/unit/helper'
|
|
4
|
+
|
|
5
|
+
class ThinReports::Core::Shape::List::TestSectionFormat < MiniTest::Unit::TestCase
|
|
6
|
+
include ThinReports::TestHelpers
|
|
7
|
+
|
|
8
|
+
TEST_LIST_SECTION_FORMAT = {
|
|
9
|
+
"height" => 47.7,
|
|
10
|
+
"translate" => {"x" => 0, "y" => -64.2},
|
|
11
|
+
"svg" => {
|
|
12
|
+
"tag" => "g",
|
|
13
|
+
"content" => "<!---SHAPE{\"type\":\"s-tblock\",\"id\":\"t1\"}SHAPE--->" +
|
|
14
|
+
"<!---SHAPE{\"type\":\"s-rect\",\"id\":\"r1\"}SHAPE--->" +
|
|
15
|
+
"<!---SHAPE{\"type\":\"s-tblock\",\"id\":\"t2\"}SHAPE--->"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
Shape = ThinReports::Core::Shape
|
|
20
|
+
|
|
21
|
+
def test_build
|
|
22
|
+
shape_format = flexmock(:id => 'mock')
|
|
23
|
+
|
|
24
|
+
flexmock(Shape::Tblock::Format).
|
|
25
|
+
should_receive(:build).times(2).and_return(shape_format)
|
|
26
|
+
flexmock(Shape::Basic::Format).
|
|
27
|
+
should_receive(:build).times(1).and_return(shape_format)
|
|
28
|
+
begin
|
|
29
|
+
build_format
|
|
30
|
+
rescue => e
|
|
31
|
+
flunk exception_details(e, 'Building failed.')
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_config_readers
|
|
36
|
+
format = Shape::List::SectionFormat.new(TEST_LIST_SECTION_FORMAT)
|
|
37
|
+
|
|
38
|
+
assert_equal format.height, 47.7
|
|
39
|
+
assert_equal format.relative_left, 0
|
|
40
|
+
assert_equal format.relative_top, -64.2
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def build_format
|
|
44
|
+
Shape::List::SectionFormat.build(TEST_LIST_SECTION_FORMAT.dup)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'test/unit/helper'
|
|
4
|
+
|
|
5
|
+
class ThinReports::Core::Shape::List::TestSectionInterface < MiniTest::Unit::TestCase
|
|
6
|
+
include ThinReports::TestHelpers
|
|
7
|
+
|
|
8
|
+
# Alias
|
|
9
|
+
List = ThinReports::Core::Shape::List
|
|
10
|
+
|
|
11
|
+
def setup
|
|
12
|
+
parent = flexmock('parent')
|
|
13
|
+
format = flexmock('format')
|
|
14
|
+
|
|
15
|
+
@interface = List::SectionInterface.new(parent, format, :section)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_undef_list_method
|
|
19
|
+
refute_respond_to @interface, :list
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_internal
|
|
23
|
+
assert_instance_of List::SectionInternal, @interface.internal
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_properly_set_init_item_handler
|
|
27
|
+
shape_format = flexmock('shape_format')
|
|
28
|
+
|
|
29
|
+
flexmock(ThinReports::Core::Shape).
|
|
30
|
+
should_receive(:Interface).with(@interface, shape_format).once
|
|
31
|
+
|
|
32
|
+
@interface.manager.init_item(shape_format)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_copy
|
|
36
|
+
original_foo = flexmock('original_foo')
|
|
37
|
+
copied_foo = flexmock('copied_foo')
|
|
38
|
+
|
|
39
|
+
flexmock(original_foo).
|
|
40
|
+
should_receive(:copy).and_return(copied_foo).once
|
|
41
|
+
@interface.manager.shapes[:foo] = original_foo
|
|
42
|
+
|
|
43
|
+
copied_interface = @interface.copy(flexmock('new_parent'))
|
|
44
|
+
|
|
45
|
+
assert_instance_of List::SectionInterface, copied_interface
|
|
46
|
+
refute_equal @interface.object_id, copied_interface.object_id
|
|
47
|
+
|
|
48
|
+
assert_equal copied_interface.internal.section_name,
|
|
49
|
+
@interface.internal.section_name
|
|
50
|
+
assert_same copied_interface.manager.shapes[:foo], copied_foo
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'test/unit/helper'
|
|
4
|
+
|
|
5
|
+
class ThinReports::Core::Shape::List::TestSectionInternal < MiniTest::Unit::TestCase
|
|
6
|
+
include ThinReports::TestHelpers
|
|
7
|
+
|
|
8
|
+
# Alias
|
|
9
|
+
List = ThinReports::Core::Shape::List
|
|
10
|
+
|
|
11
|
+
def setup
|
|
12
|
+
parent = flexmock('parent')
|
|
13
|
+
format = flexmock(:height => 100,
|
|
14
|
+
:relative_left => 100,
|
|
15
|
+
:relative_top => 200,
|
|
16
|
+
:svg_tag => 'g')
|
|
17
|
+
@internal = List::SectionInternal.new(parent, format)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_move_top_to
|
|
21
|
+
@internal.move_top_to(100)
|
|
22
|
+
assert_equal @internal.states[:relative_top], 100
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_relative_position
|
|
26
|
+
assert_equal @internal.relative_position, [100, 200]
|
|
27
|
+
@internal.move_top_to(50)
|
|
28
|
+
assert_equal @internal.relative_position, [100, 250]
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'test/unit/helper'
|
|
4
|
+
|
|
5
|
+
class ThinReports::Core::Shape::List::TestStore < MiniTest::Unit::TestCase
|
|
6
|
+
include ThinReports::TestHelpers
|
|
7
|
+
|
|
8
|
+
List = ThinReports::Core::Shape::List
|
|
9
|
+
|
|
10
|
+
def test_new
|
|
11
|
+
klass = List::Store.new(:foo => 'foo', :hoge => 0)
|
|
12
|
+
|
|
13
|
+
assert_instance_of ::Class, klass
|
|
14
|
+
|
|
15
|
+
st1 = klass.new
|
|
16
|
+
st2 = klass.new
|
|
17
|
+
|
|
18
|
+
refute_same st1.foo, st2.foo
|
|
19
|
+
# Fixnum is immutable
|
|
20
|
+
assert_same st1.hoge, st2.hoge
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_init
|
|
24
|
+
store = List::Store.init(:foo => 0, :hoge => 'hoge')
|
|
25
|
+
|
|
26
|
+
assert_respond_to store, :foo
|
|
27
|
+
assert_respond_to store, :hoge
|
|
28
|
+
|
|
29
|
+
assert_equal store.foo, 0
|
|
30
|
+
assert_equal store.hoge, 'hoge'
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_copy
|
|
34
|
+
store = List::Store.init(:foo => Time.now)
|
|
35
|
+
|
|
36
|
+
copied = store.copy
|
|
37
|
+
|
|
38
|
+
assert_equal store.foo, copied.foo
|
|
39
|
+
refute_same store.foo, copied.foo
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'test/unit/helper'
|
|
4
|
+
|
|
5
|
+
class ThinReports::Core::Shape::Manager::TestFormat < MiniTest::Unit::TestCase
|
|
6
|
+
include ThinReports::TestHelpers
|
|
7
|
+
|
|
8
|
+
class TestFormat < ThinReports::Core::Shape::Manager::Format
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_identifier_equal_the_object_id
|
|
12
|
+
format = TestFormat.new({})
|
|
13
|
+
assert_equal format.identifier, format.object_id
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_identifier_equal_the_given_id
|
|
17
|
+
format = TestFormat.new({}, :any_id)
|
|
18
|
+
assert_equal format.identifier, :any_id
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_shapes
|
|
22
|
+
format = TestFormat.new({})
|
|
23
|
+
assert_instance_of ThinReports::Core::OrderedHash, format.shapes
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_find_shape
|
|
27
|
+
format = TestFormat.new({}) do |f|
|
|
28
|
+
f.shapes[:foo] = 'foo'
|
|
29
|
+
f.shapes[:boo] = 'boo'
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
assert_equal format.find_shape(:foo), 'foo'
|
|
33
|
+
assert_equal format.find_shape(:boo), 'boo'
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_find_shape_return_nil_when_id_is_not_found
|
|
37
|
+
format = TestFormat.new({})
|
|
38
|
+
assert_nil format.find_shape(:unknown)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'test/unit/helper'
|
|
4
|
+
|
|
5
|
+
class ThinReports::Core::Shape::Manager::TestInternal < MiniTest::Unit::TestCase
|
|
6
|
+
include ThinReports::TestHelpers
|
|
7
|
+
|
|
8
|
+
def setup
|
|
9
|
+
@init_item_handler = flexmock('init_item_handler')
|
|
10
|
+
|
|
11
|
+
@format_tblock = flexmock(:type => 's-tblock')
|
|
12
|
+
@format_list = flexmock(:type => 's-list')
|
|
13
|
+
@format_rect = flexmock(:type => 's-rect')
|
|
14
|
+
|
|
15
|
+
@item_tblock = flexmock(:type => 's-tblock')
|
|
16
|
+
@item_list = flexmock(:type => 's-list')
|
|
17
|
+
@item_rect = flexmock(:type => 's-rect')
|
|
18
|
+
|
|
19
|
+
layout_format = flexmock('layout_format')
|
|
20
|
+
|
|
21
|
+
layout_format.should_receive(:find_shape).
|
|
22
|
+
with(:tblock).and_return(@format_tblock)
|
|
23
|
+
layout_format.should_receive(:find_shape).
|
|
24
|
+
with(:list).and_return(@format_list)
|
|
25
|
+
layout_format.should_receive(:find_shape).
|
|
26
|
+
with(:rect).and_return(@format_rect)
|
|
27
|
+
layout_format.should_receive(:find_shape).
|
|
28
|
+
with(:unknown).and_return(nil)
|
|
29
|
+
|
|
30
|
+
@manager = ThinReports::Core::Shape::Manager::Internal.new(layout_format,
|
|
31
|
+
@init_item_handler)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_find_format
|
|
35
|
+
assert_same @manager.find_format(:tblock), @format_tblock
|
|
36
|
+
assert_same @manager.find_format('list'), @format_list
|
|
37
|
+
assert_nil @manager.find_format(:unknown)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_valid_type?
|
|
41
|
+
# Without limit options.
|
|
42
|
+
assert_equal @manager.valid_type?('s-list'), true
|
|
43
|
+
# With only limitation.
|
|
44
|
+
assert_equal @manager.valid_type?('s-list', :only => 's-list'), true
|
|
45
|
+
assert_equal @manager.valid_type?('s-list', :only => 'other'), false
|
|
46
|
+
# With except limitation.
|
|
47
|
+
assert_equal @manager.valid_type?('s-list', :except => 'other'), true
|
|
48
|
+
assert_equal @manager.valid_type?('s-list', :except => 's-list'), false
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_find_item
|
|
52
|
+
flexmock(@init_item_handler).
|
|
53
|
+
should_receive(:call).once.and_return(@item_tblock)
|
|
54
|
+
|
|
55
|
+
# Should initialize item.
|
|
56
|
+
@manager.find_item(:tblock)
|
|
57
|
+
# Should be stored a one initialized item.
|
|
58
|
+
assert_equal @manager.shapes.size, 1
|
|
59
|
+
assert_same @manager.shapes[:tblock], @item_tblock
|
|
60
|
+
|
|
61
|
+
flexmock(@init_item_handler).
|
|
62
|
+
should_receive(:call).times(0)
|
|
63
|
+
|
|
64
|
+
# Should must not be initialized when given a initialized item.
|
|
65
|
+
assert_same @manager.find_item(:tblock), @item_tblock
|
|
66
|
+
|
|
67
|
+
# Should returnes the nil value when given unknown item.
|
|
68
|
+
assert_nil @manager.find_item(:unknown)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_find_item_with_limitation
|
|
72
|
+
# Should returns the nil value when outside limitation.
|
|
73
|
+
assert_nil @manager.find_item(:tblock, :only => 's-list')
|
|
74
|
+
assert_nil @manager.find_item(:list, :except => 's-list')
|
|
75
|
+
|
|
76
|
+
flexmock(@init_item_handler).
|
|
77
|
+
should_receive(:call).and_return(@item_tblock)
|
|
78
|
+
|
|
79
|
+
# Should initialize and store item.
|
|
80
|
+
@manager.find_item(:tblock, :except => 's-list')
|
|
81
|
+
assert_equal @manager.shapes[:tblock], @item_tblock
|
|
82
|
+
|
|
83
|
+
# Should returns the nil value.
|
|
84
|
+
assert_nil @manager.find_item(:tblock, :only => 's-list')
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def test_final_shape_when_give_the_initialized_item_that_visibility_is_enabled
|
|
88
|
+
@manager.shapes[:tblock] = flexmock(:visible? => true)
|
|
89
|
+
|
|
90
|
+
assert_same @manager.final_shape(:tblock), @manager.shapes[:tblock]
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def test_final_shape_when_give_the_initialized_item_that_visibility_is_disabled
|
|
94
|
+
@manager.shapes[:tblock] = flexmock(:visible? => false)
|
|
95
|
+
|
|
96
|
+
assert_nil @manager.final_shape(:tblock)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def test_final_shape_when_give_the_uninitialized_basic_item
|
|
100
|
+
flexmock(@format_rect, :display? => true)
|
|
101
|
+
|
|
102
|
+
flexmock(@init_item_handler).
|
|
103
|
+
should_receive(:call).once.and_return(@item_rect)
|
|
104
|
+
|
|
105
|
+
# Should initialize item.
|
|
106
|
+
assert_same @manager.final_shape(:rect), @item_rect
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def test_final_shape_return_nil_when_give_the_tblock_item_that_has_no_value
|
|
110
|
+
flexmock(@format_tblock, :display? => true,
|
|
111
|
+
:has_reference? => false,
|
|
112
|
+
:value => '')
|
|
113
|
+
assert_nil @manager.final_shape(:tblock)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def test_final_shape_initialize_item_when_give_the_tblock_item_that_has_an_reference
|
|
117
|
+
flexmock(@format_tblock, :display? => true,
|
|
118
|
+
:has_reference? => true,
|
|
119
|
+
:value => '')
|
|
120
|
+
|
|
121
|
+
flexmock(@init_item_handler).
|
|
122
|
+
should_receive(:call).once.and_return(@item_tblock)
|
|
123
|
+
|
|
124
|
+
assert_same @manager.final_shape(:tblock), @item_tblock
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def test_final_shape_initialize_item_when_give_the_tblock_item_that_has_a_value
|
|
128
|
+
flexmock(@format_tblock, :display? => true,
|
|
129
|
+
:has_reference? => false,
|
|
130
|
+
:value => 'value')
|
|
131
|
+
|
|
132
|
+
flexmock(@init_item_handler).
|
|
133
|
+
should_receive(:call).once.and_return(@item_tblock)
|
|
134
|
+
|
|
135
|
+
assert_same @manager.final_shape(:tblock), @item_tblock
|
|
136
|
+
end
|
|
137
|
+
end
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'test/unit/helper'
|
|
4
|
+
|
|
5
|
+
class ThinReports::Core::Shape::Manager::TestTarget < MiniTest::Unit::TestCase
|
|
6
|
+
include ThinReports::TestHelpers
|
|
7
|
+
|
|
8
|
+
# Alias
|
|
9
|
+
Shape = ThinReports::Core::Shape
|
|
10
|
+
|
|
11
|
+
class TestFormat < Shape::Manager::Format; end
|
|
12
|
+
|
|
13
|
+
class TestManager
|
|
14
|
+
include Shape::Manager::Target
|
|
15
|
+
|
|
16
|
+
def initialize(format)
|
|
17
|
+
initialize_manager(format) do |f|
|
|
18
|
+
Shape::Interface(self, f)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def setup
|
|
24
|
+
tblock1_format = Shape::Tblock::Format.new('id' => 'tblock1',
|
|
25
|
+
'type' => 's-tblock')
|
|
26
|
+
tblock2_format = Shape::Tblock::Format.new('id' => 'tblock2',
|
|
27
|
+
'type' => 's-tblock')
|
|
28
|
+
list_format = Shape::List::Format.new('id' => 'list',
|
|
29
|
+
'type' => 's-list')
|
|
30
|
+
|
|
31
|
+
@format = TestFormat.new({}) do |f|
|
|
32
|
+
f.shapes[:tblock1] = tblock1_format
|
|
33
|
+
f.shapes[:tblock2] = tblock2_format
|
|
34
|
+
f.shapes[:list] = list_format
|
|
35
|
+
end
|
|
36
|
+
@manager = TestManager.new(@format)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_item_with_Symbol_id
|
|
40
|
+
assert_instance_of Shape::Tblock::Interface, @manager.item(:tblock1)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_item_with_String_id
|
|
44
|
+
assert_instance_of Shape::Tblock::Interface, @manager.item('tblock1')
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_item_raise_error_when_given_the_id_of_list
|
|
48
|
+
assert_raises ThinReports::Errors::UnknownItemId do
|
|
49
|
+
@manager.item(:list)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_item_raise_error_when_given_the_unknown_id
|
|
54
|
+
assert_raises ThinReports::Errors::UnknownItemId do
|
|
55
|
+
@manager.item(:unknown)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_item_with_block_that_has_no_arguments
|
|
60
|
+
@manager.item(:tblock1) do
|
|
61
|
+
value(1000)
|
|
62
|
+
end
|
|
63
|
+
assert_equal @manager.item(:tblock1).value, 1000
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def test_item_with_block_that_has_an_argument
|
|
67
|
+
@manager.item(:tblock2) do |t|
|
|
68
|
+
t.value(1000)
|
|
69
|
+
end
|
|
70
|
+
assert_equal @manager.item(:tblock2).value, 1000
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_list_raise_error_when_given_id_of_non_list
|
|
74
|
+
assert_raises ThinReports::Errors::UnknownItemId do
|
|
75
|
+
@manager.list(:tblock1)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def test_list_should_be_stored_in_the_special_store
|
|
80
|
+
flexmock(@manager).
|
|
81
|
+
should_receive(:find_item).and_return(flexmock('item_list'))
|
|
82
|
+
|
|
83
|
+
@manager.list(:list)
|
|
84
|
+
assert_includes @manager.manager.lists, :list
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def test_items_should_be_warned_as_deprecated
|
|
88
|
+
out, err = capture_io do
|
|
89
|
+
@manager.items :tblock1 => 1000
|
|
90
|
+
end
|
|
91
|
+
assert_match %r!DEPRECATION!, err
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def test_values
|
|
95
|
+
@manager.values :tblock1 => 1000,
|
|
96
|
+
:tblock2 => 2000
|
|
97
|
+
|
|
98
|
+
assert_equal @manager.item(:tblock1).value, 1000
|
|
99
|
+
assert_equal @manager.item(:tblock2).value, 2000
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def test_item_exists?
|
|
103
|
+
assert_equal @manager.item_exists?(:tblock1), true
|
|
104
|
+
assert_equal @manager.item_exists?('list'), true
|
|
105
|
+
assert_equal @manager.item_exists?(:unknown), false
|
|
106
|
+
# Alias method
|
|
107
|
+
assert_equal @manager.exists?(:tblock1), true
|
|
108
|
+
end
|
|
109
|
+
end
|