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
Binary file
Binary file
Binary file
Binary file
data/tasks/clean.rake ADDED
@@ -0,0 +1,6 @@
1
+ # coding: utf-8
2
+
3
+ require 'rake/clean'
4
+
5
+ CLEAN.include(['doc/yardoc', '.yardoc'])
6
+ CLOBBER.include([ 'pkg' ])
data/tasks/doc.rake ADDED
@@ -0,0 +1,13 @@
1
+ # coding: utf-8
2
+
3
+ require 'yard'
4
+
5
+ YARD::Rake::YardocTask.new(:doc) do |yard|
6
+ yard.files = Dir['lib/**/*.rb']
7
+ yard.options = [
8
+ '--no-private',
9
+ '--readme', 'README.rdoc',
10
+ '--output-dir', 'doc/yardoc',
11
+ '--template-path', 'doc/yardoc_templates'
12
+ ]
13
+ end
data/tasks/test.rake ADDED
@@ -0,0 +1,18 @@
1
+ # coding: utf-8
2
+
3
+ namespace :test do
4
+ desc 'Run all unit tests'
5
+ task :unit do
6
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/..'))
7
+
8
+ files = Dir['test/unit/**/test_*.rb'] + Dir['test/unit/**/*_spec.rb']
9
+ files.each {|f| require f }
10
+ end
11
+
12
+ desc 'Run all examples'
13
+ task :example do
14
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/..'))
15
+
16
+ Dir['test/example/**/*.rb'].each {|f| require f }
17
+ end
18
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ describe 'Array#simple_deep_copy' do
6
+
7
+ it 'should original not be same as copied' do
8
+ original = []
9
+ original.wont_be_same_as original.simple_deep_copy
10
+ end
11
+
12
+ it 'should not immutable elements at fist node has been cloned' do
13
+ original = ['element', Time.now]
14
+ copied = original.simple_deep_copy
15
+
16
+ original.each_with_index do |o, i|
17
+ o.wont_be_same_as copied[i]
18
+ end
19
+ end
20
+
21
+ it 'should immutable objects at first node returns the raw' do
22
+ original = [nil, 1, 100, :symbol]
23
+ copied = original.simple_deep_copy
24
+
25
+ original.each_with_index do |o, i|
26
+ o.must_be_same_as copied[i]
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ describe 'Hash#simple_deep_copy' do
6
+
7
+ it 'should original not be same as copied' do
8
+ original = {}
9
+ original.wont_be_same_as original.simple_deep_copy
10
+ end
11
+
12
+ it 'should not immutable elements at fist node has been cloned' do
13
+ original = {:a => 'string', :b => Time.now}
14
+ copied = original.simple_deep_copy
15
+
16
+ original.each do |k, v|
17
+ v.wont_be_same_as copied[k]
18
+ end
19
+ end
20
+
21
+ it 'should immutable objects at first node returns the raw' do
22
+ original = {:a => nil, :b => 1, :c => 100, :d => :symbol}
23
+ copied = original.simple_deep_copy
24
+
25
+ original.each do |k, v|
26
+ v.must_be_same_as copied[k]
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ describe 'String#blank?' do
6
+ it 'should return the true value if self is empty' do
7
+ ''.blank?.must_equal true
8
+ "".blank?.must_equal true
9
+ end
10
+
11
+ it 'should return the false value if self is not empty' do
12
+ [' ', ' ', 'string', '日本語'].each do |v|
13
+ v.blank?.must_equal false
14
+ end
15
+ end
16
+ end
17
+
18
+ describe 'NilClass#blank?' do
19
+ it 'should always return the true value' do
20
+ nil.blank?.must_equal true
21
+ end
22
+ end
23
+
24
+ describe 'OtherClasses#blank?' do
25
+ it 'should always return the false value' do
26
+ [0, 1, -1, 9.99, true, false, ::Time.now].each do |v|
27
+ v.blank?.must_equal false
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,148 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Core::Format::BaseTest < MiniTest::Unit::TestCase
6
+ TEST_FORMAT_CONFIG = {
7
+ 'c1' => 'c1',
8
+ 'c2' => {
9
+ 'c2_1' => 'c2_1'
10
+ },
11
+ 'c3' => {
12
+ 'c3_1' => {
13
+ 'c3_1_1' => 'c3_1_1',
14
+ 'c3_1_2' => 'c3_1_2'
15
+ }
16
+ },
17
+ 'c4' => 'c4',
18
+ 'c5' => 'c5',
19
+ 'c6' => 9999,
20
+ 'c7' => 'true',
21
+ 'c8' => 'false',
22
+ 'c9' => {
23
+ 'c9_1' => 'true',
24
+ 'c9_2' => 'false'
25
+ },
26
+ 'c10' => 'c10',
27
+ 'c11' => {
28
+ 'c11_1' => 'c11_1'
29
+ },
30
+ 'c20' => 'c20',
31
+ 'c21' => 'c21'
32
+ }
33
+
34
+ class TestFormat < ThinReports::Core::Format::Base
35
+ # For testing
36
+ attr_reader :config
37
+
38
+ # Basic methods
39
+ config_reader :c1
40
+ config_reader :c2_1 => %w( c2 c2_1 ),
41
+ :c3_1_1 => %w( c3 c3_1 c3_1_1 )
42
+ config_reader :c4, :c5
43
+ config_reader 'c6'
44
+
45
+ # Alias methods
46
+ config_reader :c1_alias => %w( c1 ),
47
+ :c2_1_alias => %w( c2 c2_1 )
48
+
49
+ # Invalid methods
50
+ config_reader :c3_invalid => %w( c3 c3_1 not_exist_key )
51
+
52
+ # Customized methods
53
+ config_reader :c2_1_customized => %w( c2 c2_1 ) do |val|
54
+ "Customized #{val}"
55
+ end
56
+
57
+ # Checker methods
58
+ config_checker 'true', :c7, :c8
59
+ config_checker 'true', :c9_1 => %w( c9 c9_1 ),
60
+ :c9_2 => %w( c9 c9_2 )
61
+
62
+ # Writer methods
63
+ config_writer :c10
64
+ config_writer :c10_alias => %w( c10 )
65
+ config_writer :c11_1 => %w( c11 c11_1 )
66
+ # Writer for not exist config on default
67
+ config_writer :c11_2 => %w( c11 c11_2 )
68
+
69
+ # Accessor methods
70
+ config_accessor :c20
71
+ config_accessor :c21 do |val|
72
+ "Customized #{val}"
73
+ end
74
+ end
75
+
76
+ def setup
77
+ @format = TestFormat.new(TEST_FORMAT_CONFIG)
78
+ end
79
+
80
+ def test_definition_of_all_config_methods
81
+ methods = [:c1, :c2_1, :c3_1_1, :c4, :c5, :c6,
82
+ :c1_alias, :c2_1_alias,
83
+ :c3_invalid,
84
+ :c2_1_customized,
85
+ :c7?, :c8?, :c9_1?, :c9_2?,
86
+ :c10=, :c10_alias=, :c11_1=, :c11_2=,
87
+ :c20, :c20=, :c21, :c21=]
88
+ assert methods.all? {|m| TestFormat.method_defined?(m) }
89
+ end
90
+
91
+ def test_readers
92
+ # Basic
93
+ assert_equal @format.c1, 'c1'
94
+ assert_equal @format.c2_1, 'c2_1'
95
+ assert_equal @format.c3_1_1, 'c3_1_1'
96
+ assert_equal @format.c4, 'c4'
97
+ assert_equal @format.c5, 'c5'
98
+ assert_equal @format.c6, 9999
99
+ # Alias
100
+ assert_equal @format.c1_alias, @format.c1
101
+ assert_equal @format.c2_1_alias, @format.c2_1
102
+ # Invalid location
103
+ assert_nil @format.c3_invalid
104
+ # Customized
105
+ assert_equal @format.c2_1_customized, 'Customized c2_1'
106
+ end
107
+
108
+ def test_checkers
109
+ assert_equal @format.c7?, true
110
+ assert_equal @format.c8?, false
111
+ assert_equal @format.c9_1?, true
112
+ assert_equal @format.c9_2?, false
113
+ end
114
+
115
+ def test_reader_cannot_write_value
116
+ assert_raises NoMethodError do
117
+ @format.c1 = 'write'
118
+ end
119
+ # Alias method
120
+ assert_raises NoMethodError do
121
+ @format.c1_alias = 'write'
122
+ end
123
+ end
124
+
125
+ def test_writers
126
+ config = @format.config
127
+
128
+ @format.c10 = 'c1_changed'
129
+ assert_equal config['c10'], 'c1_changed'
130
+
131
+ @format.c10_alias = 'c10_changed_by_alias'
132
+ assert_equal config['c10'], 'c10_changed_by_alias'
133
+
134
+ @format.c11_1 = 'c11_1_changed'
135
+ assert_equal config['c11']['c11_1'], 'c11_1_changed'
136
+
137
+ @format.c11_2 = 'c11_2_created'
138
+ assert_equal config['c11']['c11_2'], 'c11_2_created'
139
+ end
140
+
141
+ def test_accessors
142
+ @format.c20 = 'c20_changed'
143
+ assert_equal @format.c20, 'c20_changed'
144
+
145
+ @format.c21 = 'c21_changed'
146
+ assert_equal @format.c21, 'Customized c21_changed'
147
+ end
148
+ end
@@ -0,0 +1,114 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Core::Format::TestBuilder < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ TEST_RAW_FORMAT = <<-'EOS'
9
+ {
10
+ "node1":"\u3042\u6f22\u5b57\uff20\u3231\u2160\u30ab\u30ca\uff76\uff85",
11
+ "node2":{"node2_child":"node2_child value"},
12
+ "layout":
13
+ "<svg width=\"595.2\" height=\"841.8\">
14
+ <g class=\"canvas\">
15
+ <rect x=\"100\" y=\"100\" width=\"100\" height=\"100\" fill=\"red\" x-attr=\"cleaned attr\"></rect>
16
+ <!--SHAPE{\"type\":\"s-tblock\",\"id\":\"t1\",\"attrs\":{\"x\":58,\"y\":103.6}}SHAPE-->
17
+ <!--LAYOUT<text x=\"60\" y=\"103\">t1</text>LAYOUT-->
18
+ </g>
19
+ </svg>"
20
+ }
21
+ EOS
22
+
23
+ class TestFormat < ThinReports::Core::Format::Base
24
+ extend ::ThinReports::Core::Format::Builder
25
+
26
+ config_reader :layout
27
+ config_accessor :shapes
28
+
29
+ # For test
30
+ public_class_method :parse_json, :build_layout, :clean,
31
+ :clean_with_attributes, :shape_tag
32
+ end
33
+
34
+ def setup
35
+ @raw_format = clean_whitespaces(TEST_RAW_FORMAT)
36
+ end
37
+
38
+ def test_parse_json
39
+ expected_format = {
40
+ "node1" => "あ漢字@㈱Ⅰカナカナ",
41
+ "node2" => {
42
+ "node2_child" => "node2_child value"
43
+ },
44
+ "layout" => clean_whitespaces(<<-EOS)
45
+ <svg width=\"595.2\" height=\"841.8\">
46
+ <g class=\"canvas\">
47
+ <rect x=\"100\" y=\"100\" width=\"100\" height=\"100\" fill=\"red\" x-attr=\"cleaned attr\"></rect>
48
+ <!--SHAPE{\"type\":\"s-tblock\",\"id\":\"t1\",\"attrs\":{\"x\":58,\"y\":103.6}}SHAPE-->
49
+ <!--LAYOUT<text x=\"60\" y=\"103\">t1</text>LAYOUT-->
50
+ </g>
51
+ </svg>
52
+ EOS
53
+ }
54
+ assert_equal TestFormat.parse_json(@raw_format), expected_format
55
+ end
56
+
57
+ def test_build_layout
58
+ format = TestFormat.new(TestFormat.parse_json(@raw_format))
59
+ format.shapes = {}
60
+
61
+ TestFormat.build_layout(format) do |type, f|
62
+ flexmock(:id => f['id'])
63
+ end
64
+
65
+ assert_equal format.layout, clean_whitespaces(<<-'EOS')
66
+ <svg width="595.2" height="841.8">
67
+ <g class="canvas">
68
+ <rect x="100" y="100" width="100" height="100" fill="red" x-attr="cleaned attr"></rect>
69
+ <%= r(:"t1")%>
70
+ <!--LAYOUT<text x="60" y="103">t1</text>LAYOUT-->
71
+ </g>
72
+ </svg>
73
+ EOS
74
+ assert_includes format.shapes.keys, :t1
75
+ end
76
+
77
+ def test_clean
78
+ source = clean_whitespaces(<<-'EOS')
79
+ <svg width="595.2" height="841.8">
80
+ <rect x="100" y="100" width="100" height="100" fill="red"></rect>
81
+ <!--LAYOUT<text x="60" y="103">t1</text>LAYOUT-->
82
+ <!---LAYOUT<text x="60" y="103">t1</text>LAYOUT--->
83
+ </svg>
84
+ EOS
85
+ TestFormat.clean(source)
86
+
87
+ assert_equal source, clean_whitespaces(<<-'EOS')
88
+ <svg width="595.2" height="841.8">
89
+ <rect x="100" y="100" width="100" height="100" fill="red"></rect>
90
+ </svg>
91
+ EOS
92
+ end
93
+
94
+ def test_clean_with_attributes
95
+ source = clean_whitespaces(<<-'EOS')
96
+ <svg width="595.2" height="841.8">
97
+ <!--LAYOUT<text x="60" y="103">t1</text>LAYOUT-->
98
+ <rect x="100" y="100" x-hoge="hoge" width="100" class="foo"></rect>
99
+ <!---LAYOUT<text x="60" y="103">t1</text>LAYOUT--->
100
+ </svg>
101
+ EOS
102
+ TestFormat.clean_with_attributes(source)
103
+
104
+ assert_equal source, clean_whitespaces(<<-'EOS')
105
+ <svg width="595.2" height="841.8">
106
+ <rect x="100" y="100" width="100"></rect>
107
+ </svg>
108
+ EOS
109
+ end
110
+
111
+ def test_shape_tag
112
+ assert_equal TestFormat.shape_tag(flexmock(:id => :foo)), '<%= r(:"foo")%>'
113
+ end
114
+ end
@@ -0,0 +1,51 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ include ThinReports::TestHelpers
6
+
7
+ describe 'OrderedHash#[]=' do
8
+ before do
9
+ skip_if_ruby19
10
+ @ohash = ThinReports::Core::OrderedHash.new
11
+ end
12
+
13
+ it 'should be given keys in stored in the keys array' do
14
+ @ohash[:foo] = 'foo'
15
+ @ohash[:hoge] = 'hoge'
16
+ @ohash.instance_variable_get(:@keys).must_equal [:foo, :hoge]
17
+ end
18
+
19
+ it 'should properly set the given value' do
20
+ @ohash[:foo] = 'foo'
21
+ @ohash[:foo].must_equal 'foo'
22
+ end
23
+
24
+ it 'should not exist a duplicate key in store of key' do
25
+ @ohash[:foo] = 'foo1'
26
+ @ohash[:foo] = 'foo2'
27
+ @ohash.instance_variable_get(:@keys).uniq.size.must_equal 1
28
+ end
29
+ end
30
+
31
+ describe 'OrderedHash#each_key' do
32
+ it 'should get the key in the order registerd' do
33
+ skip_if_ruby19
34
+
35
+ ohash = ThinReports::Core::OrderedHash.new
36
+ (keys = [:key3, :key1, :key2]).each {|key| ohash[key] = key.to_s }
37
+
38
+ i = 0
39
+ ohash.each_key do |key|
40
+ key.must_equal keys[i]; i += 1
41
+ end
42
+ end
43
+ end
44
+
45
+ describe 'OrderedHash on Ruby 1.9' do
46
+ it 'should same Hash class on Ruby 1.9' do
47
+ skip_if_ruby18
48
+
49
+ ThinReports::Core::OrderedHash.must_be_same_as ::Hash
50
+ end
51
+ end