thinreports 0.8.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CONTRIBUTING.md +2 -0
  3. data/.travis.yml +3 -3
  4. data/CHANGELOG.md +98 -1
  5. data/README.md +0 -9
  6. data/Rakefile +1 -2
  7. data/examples/character_spacing/character_spacing.tlf +293 -1
  8. data/examples/dynamic_image/dynamic_image.tlf +661 -1
  9. data/examples/dynamic_style/dynamic_style.rb +4 -4
  10. data/examples/dynamic_style/dynamic_style.tlf +1835 -1
  11. data/examples/dynamic_style/dynamic_style_in_list.tlf +344 -1
  12. data/examples/eudc/eudc.tlf +180 -1
  13. data/examples/hidden_shapes/hidden_shapes.tlf +449 -1
  14. data/examples/list_events/list_events.rb +1 -28
  15. data/examples/list_events/list_events.tlf +361 -0
  16. data/examples/list_manual_generation/list_manual_generation.tlf +132 -1
  17. data/examples/list_page_number/list_page_number.tlf +254 -1
  18. data/examples/page_number/page_number.tlf +215 -1
  19. data/examples/palleted_png/palleted_png.rb +2 -0
  20. data/examples/palleted_png/palleted_png.tlf +47 -1
  21. data/examples/password_setting/password_setting.tlf +45 -1
  22. data/examples/report_callbacks/report_callbacks.rb +1 -18
  23. data/examples/report_callbacks/report_callbacks.tlf +147 -1
  24. data/examples/single_line_tblock/single_line_tblock.tlf +170 -1
  25. data/examples/tblock_overflow/tblock_overflow.tlf +538 -1
  26. data/examples/tblock_styles/font_size.tlf +383 -1
  27. data/examples/tblock_styles/tblock_styles.tlf +889 -1
  28. data/examples/text_align/text_align.tlf +241 -1
  29. data/examples/typeB_page_size/B4_ISO.tlf +45 -1
  30. data/examples/typeB_page_size/B4_JIS.tlf +45 -1
  31. data/examples/word_wrap/word_wrap.tlf +297 -1
  32. data/lib/thinreports.rb +0 -1
  33. data/lib/thinreports/config.rb +3 -0
  34. data/lib/thinreports/core/errors.rb +0 -3
  35. data/lib/thinreports/core/format/base.rb +4 -4
  36. data/lib/thinreports/core/shape.rb +1 -9
  37. data/lib/thinreports/core/shape/basic.rb +3 -3
  38. data/lib/thinreports/core/shape/basic/block_format.rb +1 -1
  39. data/lib/thinreports/core/shape/basic/format.rb +2 -14
  40. data/lib/thinreports/core/shape/basic/internal.rb +2 -2
  41. data/lib/thinreports/core/shape/image_block.rb +3 -3
  42. data/lib/thinreports/core/shape/image_block/format.rb +0 -2
  43. data/lib/thinreports/core/shape/image_block/internal.rb +1 -1
  44. data/lib/thinreports/core/shape/list.rb +3 -7
  45. data/lib/thinreports/core/shape/list/format.rb +37 -24
  46. data/lib/thinreports/core/shape/list/manager.rb +1 -36
  47. data/lib/thinreports/core/shape/list/page.rb +0 -15
  48. data/lib/thinreports/core/shape/list/page_state.rb +1 -1
  49. data/lib/thinreports/core/shape/list/section_format.rb +14 -12
  50. data/lib/thinreports/core/shape/list/section_internal.rb +4 -7
  51. data/lib/thinreports/core/shape/manager/format.rb +0 -2
  52. data/lib/thinreports/core/shape/manager/internal.rb +1 -1
  53. data/lib/thinreports/core/shape/page_number.rb +1 -1
  54. data/lib/thinreports/core/shape/page_number/format.rb +9 -6
  55. data/lib/thinreports/core/shape/page_number/interface.rb +1 -1
  56. data/lib/thinreports/core/shape/page_number/internal.rb +2 -6
  57. data/lib/thinreports/core/shape/style/base.rb +11 -13
  58. data/lib/thinreports/core/shape/style/basic.rb +4 -4
  59. data/lib/thinreports/core/shape/style/graphic.rb +4 -10
  60. data/lib/thinreports/core/shape/style/text.rb +36 -69
  61. data/lib/thinreports/core/shape/text.rb +3 -3
  62. data/lib/thinreports/core/shape/text/format.rb +3 -13
  63. data/lib/thinreports/core/shape/text/internal.rb +2 -2
  64. data/lib/thinreports/core/shape/text_block.rb +3 -3
  65. data/lib/thinreports/core/shape/text_block/format.rb +9 -6
  66. data/lib/thinreports/core/shape/text_block/interface.rb +7 -7
  67. data/lib/thinreports/core/shape/text_block/internal.rb +1 -1
  68. data/lib/thinreports/generator/pdf.rb +0 -1
  69. data/lib/thinreports/generator/pdf/document.rb +2 -2
  70. data/lib/thinreports/generator/pdf/document/draw_shape.rb +25 -51
  71. data/lib/thinreports/generator/pdf/document/draw_template_items.rb +66 -0
  72. data/lib/thinreports/generator/pdf/document/font.rb +3 -8
  73. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +97 -77
  74. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +18 -13
  75. data/lib/thinreports/generator/pdf/document/graphics/image.rb +17 -12
  76. data/lib/thinreports/generator/pdf/document/page.rb +1 -1
  77. data/lib/thinreports/generator/pdf/drawer/list.rb +5 -1
  78. data/lib/thinreports/generator/pdf/drawer/list_section.rb +1 -4
  79. data/lib/thinreports/generator/pdf/drawer/page.rb +9 -9
  80. data/lib/thinreports/layout.rb +3 -3
  81. data/lib/thinreports/layout/base.rb +0 -16
  82. data/lib/thinreports/layout/format.rb +38 -57
  83. data/lib/thinreports/layout/legacy_schema.rb +354 -0
  84. data/lib/thinreports/layout/version.rb +1 -1
  85. data/lib/thinreports/report.rb +0 -1
  86. data/lib/thinreports/report/base.rb +3 -17
  87. data/lib/thinreports/report/internal.rb +13 -55
  88. data/lib/thinreports/report/page.rb +1 -1
  89. data/lib/thinreports/version.rb +1 -1
  90. data/test/data/legacy_layout/all-items.tlf +1 -0
  91. data/test/schema_helper.rb +121 -0
  92. data/test/test_helper.rb +13 -50
  93. data/test/unit/core/format/test_base.rb +35 -31
  94. data/test/unit/core/shape/base/test_internal.rb +1 -1
  95. data/test/unit/core/shape/basic/test_block_format.rb +23 -0
  96. data/test/unit/core/shape/basic/{test_basic_interface.rb → test_block_interface.rb} +1 -1
  97. data/test/unit/core/shape/basic/{test_basic_internal.rb → test_block_internal.rb} +4 -7
  98. data/test/unit/core/shape/basic/test_format.rb +25 -47
  99. data/test/unit/core/shape/basic/test_interface.rb +5 -5
  100. data/test/unit/core/shape/basic/test_internal.rb +6 -11
  101. data/test/unit/core/shape/image_block/test_interface.rb +5 -5
  102. data/test/unit/core/shape/image_block/test_internal.rb +2 -2
  103. data/test/unit/core/shape/list/test_format.rb +86 -44
  104. data/test/unit/core/shape/list/test_manager.rb +10 -65
  105. data/test/unit/core/shape/list/test_page.rb +10 -61
  106. data/test/unit/core/shape/list/test_page_state.rb +1 -1
  107. data/test/unit/core/shape/list/test_section_format.rb +19 -28
  108. data/test/unit/core/shape/list/test_section_interface.rb +14 -6
  109. data/test/unit/core/shape/list/test_section_internal.rb +17 -23
  110. data/test/unit/core/shape/manager/test_format.rb +1 -1
  111. data/test/unit/core/shape/manager/test_internal.rb +59 -98
  112. data/test/unit/core/shape/manager/test_target.rb +21 -30
  113. data/test/unit/core/shape/page_number/test_format.rb +34 -52
  114. data/test/unit/core/shape/page_number/test_interface.rb +1 -1
  115. data/test/unit/core/shape/page_number/test_internal.rb +2 -2
  116. data/test/unit/core/shape/styles/test_base.rb +16 -41
  117. data/test/unit/core/shape/styles/test_basic.rb +7 -7
  118. data/test/unit/core/shape/styles/test_graphic.rb +27 -32
  119. data/test/unit/core/shape/styles/test_text.rb +68 -311
  120. data/test/unit/core/shape/text/test_format.rb +30 -59
  121. data/test/unit/core/shape/text/test_internal.rb +5 -5
  122. data/test/unit/core/shape/text_block/formatter/test_datetime.rb +13 -13
  123. data/test/unit/core/shape/text_block/test_format.rb +145 -146
  124. data/test/unit/core/shape/text_block/test_interface.rb +9 -9
  125. data/test/unit/core/shape/text_block/test_internal.rb +9 -9
  126. data/test/unit/core/test_shape.rb +19 -31
  127. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +112 -122
  128. data/test/unit/generator/pdf/document/graphics/test_basic.rb +45 -0
  129. data/test/unit/generator/pdf/document/graphics/test_image.rb +5 -5
  130. data/test/unit/generator/pdf/document/test_font.rb +4 -10
  131. data/test/unit/generator/pdf/document/test_page.rb +13 -11
  132. data/test/unit/generator/pdf/document/test_parse_color.rb +5 -5
  133. data/test/unit/generator/test_base.rb +5 -5
  134. data/test/unit/generator/test_configuration.rb +4 -8
  135. data/test/unit/generator/test_pdf.rb +3 -2
  136. data/test/unit/layout/test_base.rb +16 -22
  137. data/test/unit/layout/test_format.rb +66 -86
  138. data/test/unit/layout/test_legacy_schema.rb +587 -0
  139. data/test/unit/layout/test_version.rb +20 -20
  140. data/test/unit/report/test_base.rb +32 -45
  141. data/test/unit/report/test_internal.rb +43 -99
  142. data/test/unit/test_config.rb +4 -2
  143. data/test/unit/test_layout.rb +1 -1
  144. metadata +20 -48
  145. data/examples/list_events/list_events_0_7_7.tlf +0 -1
  146. data/examples/list_events/list_events_0_8.tlf +0 -1
  147. data/lib/thinreports/core/events.rb +0 -69
  148. data/lib/thinreports/core/format/builder.rb +0 -62
  149. data/lib/thinreports/core/shape/list/configuration.rb +0 -54
  150. data/lib/thinreports/core/shape/list/events.rb +0 -47
  151. data/lib/thinreports/core/shape/list/store.rb +0 -33
  152. data/lib/thinreports/generator/pdf/configuration.rb +0 -33
  153. data/lib/thinreports/generator/pdf/document/parse_svg.rb +0 -104
  154. data/lib/thinreports/layout/configuration.rb +0 -29
  155. data/test/data/layout_block.tlf +0 -1
  156. data/test/data/layout_list.tlf +0 -1
  157. data/test/data/layout_list_noheader.tlf +0 -1
  158. data/test/data/layout_text1.tlf +0 -1
  159. data/test/data/layout_text2.tlf +0 -1
  160. data/test/unit/core/format/test_builder.rb +0 -109
  161. data/test/unit/core/shape/basic/test_basic_format.rb +0 -30
  162. data/test/unit/core/shape/image_block/test_format.rb +0 -58
  163. data/test/unit/core/shape/list/test_configuration.rb +0 -69
  164. data/test/unit/core/shape/list/test_events.rb +0 -36
  165. data/test/unit/core/shape/list/test_store.rb +0 -41
  166. data/test/unit/core/test_events.rb +0 -93
  167. data/test/unit/generator/pdf/document/test_draw_shape.rb +0 -44
  168. data/test/unit/generator/pdf/test_configuration.rb +0 -31
  169. data/test/unit/layout/test_configuration.rb +0 -21
  170. data/test/unit/report/test_events.rb +0 -22
@@ -18,7 +18,7 @@ class Thinreports::Generator::PDF::Document::TestPage < Minitest::Test
18
18
  def test_B4_paper_size_should_be_converted_to_B4_JIS
19
19
  create_pdf
20
20
 
21
- format = new_layout_format('layout_text1.tlf')
21
+ format = Thinreports::Layout::Format.build(layout_file.path)
22
22
  format.stubs(page_paper_type: 'B4')
23
23
 
24
24
  @pdf.start_new_page(format)
@@ -28,7 +28,7 @@ class Thinreports::Generator::PDF::Document::TestPage < Minitest::Test
28
28
  def test_B4_ISO_paper_size_should_be_converted_to_B4
29
29
  create_pdf
30
30
 
31
- format = new_layout_format('layout_text1.tlf')
31
+ format = Thinreports::Layout::Format.build(layout_file.path)
32
32
  format.stubs(page_paper_type: 'B4_ISO')
33
33
 
34
34
  @pdf.start_new_page(format)
@@ -37,14 +37,14 @@ class Thinreports::Generator::PDF::Document::TestPage < Minitest::Test
37
37
 
38
38
  def test_change_page_format_should_return_true_at_first_time
39
39
  create_pdf
40
- format = new_layout_format('layout_text1.tlf')
40
+ format = Thinreports::Layout::Format.build(layout_file.path)
41
41
 
42
42
  assert_equal @pdf.send(:change_page_format?, format), true
43
43
  end
44
44
 
45
45
  def test_change_page_format_should_return_false_when_given_the_same_format
46
46
  create_pdf
47
- format = new_layout_format('layout_text1.tlf')
47
+ format = Thinreports::Layout::Format.build(layout_file.path)
48
48
 
49
49
  @pdf.instance_variable_set(:@current_page_format, format)
50
50
  assert_equal @pdf.send(:change_page_format?, format), false
@@ -52,15 +52,15 @@ class Thinreports::Generator::PDF::Document::TestPage < Minitest::Test
52
52
 
53
53
  def test_change_page_format_should_return_true_when_given_the_other_format
54
54
  create_pdf
55
- format1 = new_layout_format('layout_text1.tlf')
56
- format2 = new_layout_format('layout_text2.tlf')
55
+ format1 = Thinreports::Layout::Format.build(layout_file.path)
56
+ format2 = Thinreports::Layout::Format.build(layout_file.path)
57
57
 
58
58
  @pdf.instance_variable_set(:@current_page_format, format1)
59
59
  assert_equal @pdf.send(:change_page_format?, format2), true
60
60
  end
61
61
 
62
62
  def test_new_basic_page_options
63
- format = new_layout_format('layout_text1.tlf')
63
+ format = Thinreports::Layout::Format.build(layout_file.path)
64
64
  options = create_pdf.send(:new_basic_page_options, format)
65
65
 
66
66
  assert_equal options[:layout], format.page_orientation.to_sym
@@ -79,7 +79,7 @@ class Thinreports::Generator::PDF::Document::TestPage < Minitest::Test
79
79
 
80
80
  def test_start_new_page_should_create_stamp
81
81
  create_pdf
82
- format = new_layout_format('layout_text1.tlf')
82
+ format = Thinreports::Layout::Format.build(layout_file.path)
83
83
  @pdf.start_new_page(format)
84
84
 
85
85
  assert_includes @pdf.send(:format_stamp_registry), format.identifier
@@ -87,7 +87,7 @@ class Thinreports::Generator::PDF::Document::TestPage < Minitest::Test
87
87
 
88
88
  def test_start_new_page_should_not_create_stamp
89
89
  create_pdf
90
- format = new_layout_format('layout_text1.tlf')
90
+ format = Thinreports::Layout::Format.build(layout_file.path)
91
91
  @pdf.start_new_page(format)
92
92
  @pdf.start_new_page(format)
93
93
 
@@ -96,7 +96,7 @@ class Thinreports::Generator::PDF::Document::TestPage < Minitest::Test
96
96
 
97
97
  def test_start_new_page_should_stamp_constantly
98
98
  create_pdf
99
- format = new_layout_format('layout_text1.tlf')
99
+ format = Thinreports::Layout::Format.build(layout_file.path)
100
100
  @pdf.expects(:stamp).with(format.identifier.to_s).times(2)
101
101
 
102
102
  @pdf.start_new_page(format)
@@ -112,7 +112,9 @@ class Thinreports::Generator::PDF::Document::TestPage < Minitest::Test
112
112
 
113
113
  def test_add_blank_page_should_call_with_no_arguments_since_second_page
114
114
  create_pdf
115
- @pdf.start_new_page(new_layout_format('layout_text1.tlf'))
115
+ format = Thinreports::Layout::Format.build(layout_file.path)
116
+
117
+ @pdf.start_new_page(format)
116
118
  @pdf.internal.expects(:start_new_page).with({}).once
117
119
 
118
120
  @pdf.add_blank_page
@@ -4,24 +4,24 @@ require 'test_helper'
4
4
 
5
5
  class Thinreports::Generator::PDF::TestParseColor < Minitest::Test
6
6
  include Thinreports::TestHelper
7
-
7
+
8
8
  class TestColorParser
9
9
  include Thinreports::Generator::PDF::ParseColor
10
10
  end
11
-
11
+
12
12
  def setup
13
13
  @parser = TestColorParser.new
14
14
  end
15
-
15
+
16
16
  def test_parse_color_with_hexcolor
17
17
  assert_equal @parser.parse_color('#ff0000'), 'ff0000'
18
18
  assert_equal @parser.parse_color('000000'), '000000'
19
19
  end
20
-
20
+
21
21
  def test_parse_color_with_colorname
22
22
  assert_equal @parser.parse_color('red'), 'ff0000'
23
23
  end
24
-
24
+
25
25
  def test_parse_color_with_colorname_raise_when_unknown_name_given
26
26
  assert_raises Thinreports::Errors::UnsupportedColorName do
27
27
  @parser.parse_color('whitesmoke')
@@ -14,7 +14,7 @@ class Thinreports::Generator::TestBase < Minitest::Test
14
14
  end
15
15
 
16
16
  def test_new
17
- report = new_report 'layout_text1.tlf'
17
+ report = Thinreports::Report.new layout: layout_file.path
18
18
 
19
19
  refute report.finalized?
20
20
  Generator::Base.new report
@@ -22,7 +22,7 @@ class Thinreports::Generator::TestBase < Minitest::Test
22
22
  end
23
23
 
24
24
  def test_generate
25
- report = new_report 'layout_text1.tlf'
25
+ report = Thinreports::Report.new layout: layout_file.path
26
26
 
27
27
  generator = Generator::Base.new report
28
28
  assert_raises NotImplementedError do
@@ -31,10 +31,10 @@ class Thinreports::Generator::TestBase < Minitest::Test
31
31
  end
32
32
 
33
33
  def test_default_layout
34
- report = new_report 'layout_text1.tlf'
34
+ layout_filename = layout_file.path
35
+ report = Thinreports::Report.new layout: layout_filename
35
36
 
36
37
  generator = Generator::Base.new report
37
- assert_equal data_file('layout_text1.tlf'),
38
- generator.default_layout.filename
38
+ assert_equal layout_filename, generator.default_layout.filename
39
39
  end
40
40
  end
@@ -4,22 +4,18 @@ require 'test_helper'
4
4
 
5
5
  class Thinreports::Generator::TestConfiguration < Minitest::Test
6
6
  include Thinreports::TestHelper
7
-
7
+
8
8
  def setup
9
9
  @config = Thinreports::Generator::Configuration.new
10
10
  end
11
-
12
- def test_pdf_should_return_configuration_of_pdf
13
- assert_instance_of Thinreports::Generator::PDF::Configuration, @config.pdf
14
- end
15
-
11
+
16
12
  def test_default_should_return_pdf_by_default
17
13
  assert_equal @config.default, :pdf
18
14
  end
19
-
15
+
20
16
  def test_default_should_raise_when_value_is_unknown_generator_type
21
17
  assert_raises Thinreports::Errors::UnknownGeneratorType do
22
18
  @config.default = :unknown
23
19
  end
24
20
  end
25
- end
21
+ end
@@ -8,7 +8,8 @@ class Thinreports::Generator::TestPDF < Minitest::Test
8
8
  PDF = Thinreports::Generator::PDF
9
9
 
10
10
  def test_new_should_set_title_as_metadata
11
- report = new_report('layout_text1.tlf') {|r| r.start_new_page }
11
+ report = Thinreports::Report.new layout: layout_file.path
12
+ report.start_new_page
12
13
 
13
14
  actual_pdf_title = nil
14
15
  PDF::Document.define_singleton_method(:new) {|_options, meta|
@@ -16,7 +17,7 @@ class Thinreports::Generator::TestPDF < Minitest::Test
16
17
  }
17
18
  PDF.new report, {}
18
19
 
19
- assert_equal 'Basic Layout', actual_pdf_title
20
+ assert_equal 'Report Title', actual_pdf_title
20
21
  ensure
21
22
  PDF::Document.singleton_class.send(:remove_method, :new)
22
23
  end
@@ -8,40 +8,34 @@ class Thinreports::Layout::TestBase < Minitest::Test
8
8
  Layout = Thinreports::Layout
9
9
 
10
10
  def test_load_format
11
- assert_instance_of Layout::Format,
12
- Layout::Base.load_format(data_file('layout_text1.tlf'))
13
- assert_instance_of Layout::Format,
14
- Layout::Base.load_format(data_file('layout_text1'))
15
-
11
+ assert_instance_of Layout::Format, Layout::Base.load_format(layout_file.path)
16
12
  assert_raises Thinreports::Errors::LayoutFileNotFound do
17
13
  Layout::Base.load_format 'unknown.tlf'
18
14
  end
19
15
  end
20
16
 
21
17
  def test_new
22
- layout = create_layout id: 'foo'
18
+ layout_filename = layout_file.path
19
+ layout = Layout::Base.new(layout_filename)
23
20
 
24
- assert_equal 'foo', layout.id
25
- assert_equal data_file('layout_text1.tlf'), layout.filename
21
+ assert_nil layout.id
22
+ assert_equal layout_filename, layout.filename
23
+ assert_instance_of Layout::Format, layout.format
26
24
  end
27
25
 
28
- def test_default?
29
- assert_equal false, create_layout(id: 'foo').default?
30
- assert_equal true, create_layout.default?
31
- end
26
+ def test_id
27
+ layout_without_id = Layout::Base.new(layout_file.path)
28
+ assert_nil layout_without_id.id
32
29
 
33
- def test_config
34
- assert_instance_of Thinreports::Layout::Configuration,
35
- create_layout.config
30
+ layout_with_id = Layout::Base.new(layout_file.path, id: 'foo')
31
+ assert_equal 'foo', layout_with_id.id
36
32
  end
37
33
 
38
- def test_new_page
39
- report = new_report 'layout_text1'
40
- assert_instance_of Thinreports::Report::Page,
41
- create_layout.new_page(report)
42
- end
34
+ def test_default?
35
+ layout_without_id = Layout::Base.new(layout_file.path)
36
+ assert_equal true, layout_without_id.default?
43
37
 
44
- def create_layout(options = {})
45
- Layout::Base.new data_file('layout_text1.tlf'), options
38
+ layout_with_id = Layout::Base.new(layout_file.path, id: 'bar')
39
+ assert_equal false, layout_with_id.default?
46
40
  end
47
41
  end
@@ -5,116 +5,96 @@ require 'test_helper'
5
5
  class Thinreports::Layout::TestFormat < Minitest::Test
6
6
  include Thinreports::TestHelper
7
7
 
8
- TEST_SIMPLE_FORMAT = <<-'EOF'
9
- {
10
- "version":"%s",
11
- "finger-print":-860627816,
12
- "config":{
13
- "title":"Sample Layout",
14
- "page":{
15
- "paper-type":"A4",
16
- "width":null,
17
- "height":null,
18
- "orientation":"portrait",
19
- "margin-top":"20",
20
- "margin-bottom":"20",
21
- "margin-left":"20",
22
- "margin-right":"20"
23
- },
24
- "option":{}
8
+ LAYOUT_SCHEMA = {
9
+ 'version' => '0.9.0',
10
+ 'title' => 'Report Title',
11
+ 'report' => {
12
+ 'paper-type' => 'A4',
13
+ 'width' => 100.0,
14
+ 'height' => 200.0,
15
+ 'orientation' => 'landscape',
16
+ 'margin' => [100.0, 200.0, 300.0, 999.9]
25
17
  },
26
- "svg":"<!--SHAPE{\"type\":\"s-rect\",\"id\":\"rect1\"}SHAPE-->
27
- <!--SHAPE{\"type\":\"s-image\",\"id\":\"image1\"}SHAPE-->
28
- <!--SHAPE{\"type\":\"s-tblock\",\"id\":\"tblock1\"}SHAPE-->
29
- <!--SHAPE{\"type\":\"s-tblock\",\"id\":\"tblock2\"}SHAPE-->",
30
- "state":{
31
- "layout-guides": [{"type":"x", "position":100}]
32
- }
18
+ 'state' => {
19
+ 'layout-guides' => [
20
+ { 'type' => 'x', 'position' => 0.1 }
21
+ ]
22
+ },
23
+ 'items' => [
24
+ { 'type'=> 'rect', 'id'=> '', 'x'=> 100.0, 'y'=> 100.0, 'width'=> 100.0, 'height'=> 100.0, 'style'=> {'stroke-width'=> 1}},
25
+ { 'type'=> 'text-block', 'id'=> 'text_block', 'x'=> 100.0, 'y'=> 100.0 },
26
+ { 'type'=> 'page-number', 'id'=> '', 'x'=> 100.0, 'y'=> 100.0 }
27
+ ]
33
28
  }
34
- EOF
35
29
 
36
- # Alias
37
30
  Shape = Thinreports::Core::Shape
38
31
  Layout = Thinreports::Layout
39
32
 
40
- def test_report_title_should_return_the_value_of_config_title_key
41
- format = Layout::Format.new('config' => {'title' => 'Title'})
42
- assert_equal format.report_title, 'Title'
43
- end
33
+ def test_attribute_readers
34
+ format = Layout::Format.new(layout_schema)
44
35
 
45
- def test_user_paper_type_asker_should_return_true_when_paper_type_is_user
46
- format = Layout::Format.new('config' => {'page' => {'paper-type' => 'user'}})
47
- assert_equal format.user_paper_type?, true
36
+ assert_equal 'Report Title', format.report_title
37
+ assert_equal Thinreports::VERSION, format.last_version
38
+ assert_equal 'A4', format.page_paper_type
39
+ assert_equal 100.0, format.page_width
40
+ assert_equal 200.0, format.page_height
41
+ assert_equal 'landscape', format.page_orientation
48
42
  end
49
43
 
50
- def test_user_paper_type_asker_should_return_false_when_paper_type_is_not_user
51
- format = Layout::Format.new('config' => {'page' => {'paper-type' => 'A4'}})
52
- assert_equal format.user_paper_type?, false
44
+ def test_user_paper_type?
45
+ format_paper_type_is_not_user = Layout::Format.new(layout_schema)
46
+ assert_equal false, format_paper_type_is_not_user.user_paper_type?
47
+
48
+ format_paper_type_is_user = Layout::Format.new(layout_schema.merge(
49
+ {
50
+ 'report' => {
51
+ 'paper-type' => 'user'
52
+ }
53
+ }
54
+ ))
55
+ assert_equal true, format_paper_type_is_user.user_paper_type?
53
56
  end
54
57
 
55
- def test_last_version_should_return_the_value_of_version_key
56
- format = Layout::Format.new('version' => '1.0')
57
- assert_equal format.last_version, '1.0'
58
- end
58
+ def test_build
59
+ compatible_layout_file = layout_file
60
+ assert_instance_of Layout::Format, Layout::Format.build(compatible_layout_file.path)
59
61
 
60
- def test_build_should_properly_build_layout_format
61
- build_format(force: true)
62
- rescue => e
63
- flunk exception_details(e, 'Faile to build.')
64
- end
65
-
66
- def test_build_should_properly_set_built_shapes_to_shapes_attributes_of_format
67
- assert_equal build_format.shapes.size, 4
62
+ incompatible_layout_file = layout_file(version: '0.0.1')
63
+ assert_raises Thinreports::Errors::IncompatibleLayoutFormat do
64
+ Layout::Format.build(incompatible_layout_file.path)
65
+ end
68
66
  end
69
67
 
70
- def test_config_attributes_of_built_format_should_not_have_unnecessary_attributes
71
- format = build_format(force: true)
72
- config = format.instance_variable_get(:@config)
68
+ def test_build_legacy_layout
69
+ format = nil
73
70
 
74
- refute %w( version finger-print state).any? {|a| config.key?(a)},
75
- 'A config attributes of built format have unnecessary attributes.'
76
- end
77
-
78
- def test_identifier_should_return_the_digest_value_of_the_raw_layout_using_sha1
79
- format = build_format
80
- expect = Digest::SHA1.hexdigest(create_raw_format)
71
+ assert_deprecated { format = Layout::Format.build(data_file('legacy_layout', 'all-items.tlf')) }
81
72
 
82
- assert_equal format.identifier, expect.to_sym
83
- ensure
84
- clear_cache_for_building
85
- end
73
+ assert_equal 'Report Title', format.report_title
74
+ assert_equal '0.8.2', format.last_version
75
+ assert_equal 'A4', format.page_paper_type
76
+ assert_equal 'portrait', format.page_orientation
86
77
 
87
- def test_build_should_always_return_the_same_result_in_cache_mode
88
- result1 = build_format
89
- result2 = build_format
78
+ item_types = format.attributes['items'].map { |items| items['type'] }
90
79
 
91
- assert_same result1, result2
92
- ensure
93
- clear_cache_for_building
80
+ assert_equal 9, item_types.count
81
+ assert_equal %w( rect ellipse line image image-block text-block list page-number text ).sort,
82
+ item_types.sort
94
83
  end
95
84
 
96
- def test_build_should_raise_when_layout_file_is_incompatible
97
- original_rules = Layout::Version::REQUIRED_RULES.dup
98
- Layout::Version::REQUIRED_RULES.replace(['>= 0.6.0.pre3', '< 0.8.0'])
85
+ def test_initialize_items
86
+ format = Layout::Format.new(layout_schema)
99
87
 
100
- assert_raises Thinreports::Errors::IncompatibleLayoutFormat do
101
- build_format(version: '0.6.0.pre2')
102
- end
103
- ensure
104
- Layout::Version::REQUIRED_RULES.replace(original_rules)
105
- clear_cache_for_building
106
- end
88
+ assert_equal 2, format.shapes.count
107
89
 
108
- def create_raw_format(version = nil)
109
- clean_whitespaces(TEST_SIMPLE_FORMAT) % (version || Thinreports::VERSION)
90
+ shape_classes = format.shapes.values.map(&:class)
91
+ assert_includes shape_classes, Shape::TextBlock::Format
92
+ assert_includes shape_classes, Shape::PageNumber::Format
110
93
  end
111
94
 
112
- def build_format(options = {})
113
- Layout::Format.stubs(read_format_file: create_raw_format(options[:version]))
114
- Layout::Format.build('dummy.tlf', force: options[:force])
115
- end
95
+ private
116
96
 
117
- def clear_cache_for_building
118
- Layout::Format.send(:built_format_registry).clear
97
+ def layout_schema(version = Thinreports::VERSION)
98
+ LAYOUT_SCHEMA.merge('version' => version)
119
99
  end
120
100
  end
@@ -0,0 +1,587 @@
1
+ # coding: utf-8
2
+ require 'test_helper'
3
+
4
+ class Thinreports::Layout::TestLegacySchema < Minitest::Test
5
+ include Thinreports::TestHelper
6
+
7
+ Layout = Thinreports::Layout
8
+
9
+ def test_upgrade
10
+ legacy_schema = {
11
+ 'version' => '0.8.2',
12
+ 'finger-print' => 'abcd',
13
+ 'config' => {
14
+ 'title' => 'Report Title',
15
+ 'page' => {
16
+ 'paper-type' => 'A4',
17
+ 'width' => '100.0',
18
+ 'height' => '200.0',
19
+ 'orientation' => 'landscape',
20
+ 'margin-top' => '0.1',
21
+ 'margin-right' => '0.2',
22
+ 'margin-bottom' => '0.3',
23
+ 'margin-left' => '0.4'
24
+ }
25
+ },
26
+ 'svg' => '<svg><g class="canvas"></g></svg>',
27
+ 'state' => {
28
+ 'layout-guide' => []
29
+ }
30
+ }
31
+
32
+ assert_equal(
33
+ {
34
+ 'version' => '0.8.2',
35
+ 'title' => 'Report Title',
36
+ 'report' => {
37
+ 'paper-type' => 'A4',
38
+ 'width' => 100.0,
39
+ 'height' => 200.0,
40
+ 'orientation' => 'landscape',
41
+ 'margin' => [0.1, 0.2, 0.3, 0.4]
42
+ },
43
+ 'items' => []
44
+ },
45
+ Layout::LegacySchema.new(legacy_schema).upgrade
46
+ )
47
+ end
48
+
49
+ def test_text_item_schema
50
+ legacy_attributes = {
51
+ 'x-id' => 'text_id',
52
+ 'x-left' => '100.1',
53
+ 'x-top' => '200.1',
54
+ 'x-width' => '300.1',
55
+ 'x-height' => '400.1',
56
+ 'x-display' => 'true',
57
+ 'font-family' => 'Helvetica',
58
+ 'font-size' => '18',
59
+ 'font-weight' => 'normal',
60
+ 'font-style' => 'normal',
61
+ 'text-decoration' => 'underline line-through',
62
+ 'fill' => 'red',
63
+ 'text-anchor' => 'start',
64
+ 'x-valign' => 'top',
65
+ 'x-line-height' => '20.1',
66
+ 'kerning' => '2.1'
67
+ }
68
+ legacy_texts = %w( line1 line2 )
69
+
70
+ assert_equal(
71
+ {
72
+ 'id' => 'text_id',
73
+ 'type' => 'text',
74
+ 'x' => 100.1,
75
+ 'y' => 200.1,
76
+ 'width' => 300.1,
77
+ 'height' => 400.1,
78
+ 'display' => true,
79
+ 'texts' => %w( line1 line2 ),
80
+ 'style' => {
81
+ 'font-family' => %w( Helvetica ),
82
+ 'font-size' => 18.0,
83
+ 'color' => 'red',
84
+ 'font-style' => %w( underline linethrough ),
85
+ 'text-align' => 'left',
86
+ 'vertical-align' => 'top',
87
+ 'line-height' => 20.1,
88
+ 'letter-spacing' => 2.1
89
+ }
90
+ },
91
+ layout_legacy_schema.text_item_schema(legacy_attributes, legacy_texts)
92
+ )
93
+ end
94
+
95
+ def test_rect_item_schema
96
+ legacy_attributes = {
97
+ 'x-id' => 'rect_id',
98
+ 'x' => '100.1',
99
+ 'y' => '200.1',
100
+ 'width' => '300.1',
101
+ 'height' => '400.1',
102
+ 'x-display' => 'false',
103
+ 'stroke-width' => '2.5',
104
+ 'stroke' => '#ff0000',
105
+ 'x-stroke-type' => 'dotted',
106
+ 'fill' => 'red'
107
+ }
108
+ assert_equal(
109
+ {
110
+ 'id' => 'rect_id',
111
+ 'type' => 'rect',
112
+ 'x' => 100.1,
113
+ 'y' => 200.1,
114
+ 'width' => 300.1,
115
+ 'height' => 400.1,
116
+ 'display' => false,
117
+ 'style' => {
118
+ 'border-width' => 2.5,
119
+ 'border-color' => '#ff0000',
120
+ 'border-style' => 'dotted',
121
+ 'fill-color' => 'red'
122
+ }
123
+ },
124
+ layout_legacy_schema.rect_item_schema(legacy_attributes)
125
+ )
126
+ end
127
+
128
+ def test_line_item_schema
129
+ legacy_attributes = {
130
+ 'x-id' => 'line_id',
131
+ 'x1' => '100.1',
132
+ 'y1' => '200.1',
133
+ 'x2' => '300.1',
134
+ 'y2' => '400.1',
135
+ 'x-display' => 'true',
136
+ 'stroke-width' => '1',
137
+ 'stroke' => 'red',
138
+ 'x-stroke-type' => 'solid'
139
+ }
140
+ assert_equal(
141
+ {
142
+ 'id' => 'line_id',
143
+ 'type' => 'line',
144
+ 'x1' => 100.1,
145
+ 'y1' => 200.1,
146
+ 'x2' => 300.1,
147
+ 'y2' => 400.1,
148
+ 'display' => true,
149
+ 'style' => {
150
+ 'border-width' => 1.0,
151
+ 'border-color' => 'red',
152
+ 'border-style' => 'solid'
153
+ }
154
+ },
155
+ layout_legacy_schema.line_item_schema(legacy_attributes)
156
+ )
157
+ end
158
+
159
+ def test_ellipse_item_schema
160
+ legacy_attributes = {
161
+ 'x-id' => 'ellipse_id',
162
+ 'cx' => '100.1',
163
+ 'cy' => '200.1',
164
+ 'rx' => '300.1',
165
+ 'ry' => '400.1',
166
+ 'x-display' => 'true',
167
+ 'stroke-width' => '1',
168
+ 'stroke' => 'red',
169
+ 'x-stroke-type' => 'solid',
170
+ 'fill' => 'blue'
171
+ }
172
+ assert_equal(
173
+ {
174
+ 'id' => 'ellipse_id',
175
+ 'type' => 'ellipse',
176
+ 'cx' => 100.1,
177
+ 'cy' => 200.1,
178
+ 'rx' => 300.1,
179
+ 'ry' => 400.1,
180
+ 'display' => true,
181
+ 'style' => {
182
+ 'border-width' => 1.0,
183
+ 'border-color' => 'red',
184
+ 'border-style' => 'solid',
185
+ 'fill-color' => 'blue'
186
+ }
187
+ },
188
+ layout_legacy_schema.ellipse_item_schema(legacy_attributes)
189
+ )
190
+ end
191
+
192
+ def test_image_item_schema
193
+ legacy_attributes = {
194
+ 'x-id' => 'image_id',
195
+ 'x' => '100.1',
196
+ 'y' => '200.1',
197
+ 'width' => '300.1',
198
+ 'height' => '400.1',
199
+ 'x-display' => 'true',
200
+ 'xlink:href' => 'data:image/png;base64,xxxxxxxxxxxxx'
201
+ }
202
+ assert_equal(
203
+ {
204
+ 'id' => 'image_id',
205
+ 'type' => 'image',
206
+ 'x' => 100.1,
207
+ 'y' => 200.1,
208
+ 'width' => 300.1,
209
+ 'height' => 400.1,
210
+ 'display' => true,
211
+ 'data' => {
212
+ 'mime-type' => 'image/png',
213
+ 'base64' => 'xxxxxxxxxxxxx'
214
+ }
215
+ },
216
+ layout_legacy_schema.image_item_schema(legacy_attributes)
217
+ )
218
+ end
219
+
220
+ def test_page_number_item_schema
221
+ legacy_attributes = {
222
+ 'x-id' => 'page_number_id',
223
+ 'x-left' => '100.1',
224
+ 'x-top' => '200.1',
225
+ 'x-width' => '300.1',
226
+ 'x-height' => '400.1',
227
+ 'x-format' => '{page}',
228
+ 'x-target' => 'report',
229
+ 'x-display' => 'true',
230
+ 'font-family' => 'IPAMincho',
231
+ 'font-size' => '18.5',
232
+ 'fill' => 'red',
233
+ 'font-weight' => 'bold',
234
+ 'font-style' => 'italic',
235
+ 'text-decoration' => '',
236
+ 'text-anchor' => 'end',
237
+ 'x-overflow' => 'fit'
238
+ }
239
+ assert_equal(
240
+ {
241
+ 'id' => 'page_number_id',
242
+ 'type' => 'page-number',
243
+ 'x' => 100.1,
244
+ 'y' => 200.1,
245
+ 'width' => 300.1,
246
+ 'height' => 400.1,
247
+ 'format' => '{page}',
248
+ 'target' => 'report',
249
+ 'display' => true,
250
+ 'style' => {
251
+ 'font-family' => %w( IPAMincho ),
252
+ 'font-size' => 18.5,
253
+ 'color' => 'red',
254
+ 'font-style' => %w( bold italic ),
255
+ 'text-align' => 'right',
256
+ 'overflow' => 'fit'
257
+ }
258
+ },
259
+ layout_legacy_schema.page_number_item_schema(legacy_attributes)
260
+ )
261
+ end
262
+
263
+ def test_image_block_item_schema
264
+ legacy_attributes = {
265
+ 'x-id' => 'image_block_id',
266
+ 'x-left' => '100.1',
267
+ 'x-top' => '200.1',
268
+ 'x-width' => '300.1',
269
+ 'x-height' => '400.1',
270
+ 'x-display' => 'false',
271
+ 'x-position-x' => 'right',
272
+ 'x-position-y' => 'bottom'
273
+ }
274
+ assert_equal(
275
+ {
276
+ 'id' => 'image_block_id',
277
+ 'type' => 'image-block',
278
+ 'x' => 100.1,
279
+ 'y' => 200.1,
280
+ 'width' => 300.1,
281
+ 'height' => 400.1,
282
+ 'display' => false,
283
+ 'style' => {
284
+ 'position-x' => 'right',
285
+ 'position-y' => 'bottom'
286
+ }
287
+ },
288
+ layout_legacy_schema.image_block_item_schema(legacy_attributes)
289
+ )
290
+ end
291
+
292
+ def test_text_block_schema
293
+ base_legacy_attributes = {
294
+ 'x-id' => 'text_block_id',
295
+ 'x-left' => '100.1',
296
+ 'x-top' => '200.1',
297
+ 'x-width' => '300.1',
298
+ 'x-height' => '400.1',
299
+ 'x-display' => 'true',
300
+ 'x-value' => 'default value',
301
+ 'x-multiple' => 'true',
302
+ 'font-family' => 'Helvetica',
303
+ 'font-size' => '18',
304
+ 'font-weight' => 'bold',
305
+ 'font-style' => 'normal',
306
+ 'text-decoration' => 'line-through',
307
+ 'fill' => 'red',
308
+ 'text-anchor' => 'start',
309
+ 'x-valign' => 'top',
310
+ 'x-line-height' => '20.1',
311
+ 'kerning' => '2.1',
312
+ 'x-overflow' => 'expand',
313
+ 'x-word-wrap' => 'break-word',
314
+ 'x-format-base' => '$ {value}',
315
+ 'x-format-type' => ''
316
+ }
317
+ assert_equal(
318
+ {
319
+ 'id' => 'text_block_id',
320
+ 'type' => 'text-block',
321
+ 'x' => 100.1,
322
+ 'y' => 200.1,
323
+ 'width' => 300.1,
324
+ 'height' => 400.1,
325
+ 'display' => true,
326
+ 'value' => 'default value',
327
+ 'multiple-line' => true,
328
+ 'format' => {
329
+ 'base' => '$ {value}',
330
+ 'type' => ''
331
+ },
332
+ 'style' => {
333
+ 'font-family' => %w( Helvetica ),
334
+ 'font-size' => 18.0,
335
+ 'color' => 'red',
336
+ 'font-style' => %w( bold linethrough ),
337
+ 'text-align' => 'left',
338
+ 'vertical-align' => 'top',
339
+ 'line-height' => 20.1,
340
+ 'letter-spacing' => 2.1,
341
+ 'overflow' => 'expand',
342
+ 'word-wrap' => 'break-word'
343
+ }
344
+ },
345
+ layout_legacy_schema.text_block_item_schema(base_legacy_attributes)
346
+ )
347
+
348
+ schema_with_datetime_format = layout_legacy_schema.text_block_item_schema(base_legacy_attributes.merge(
349
+ 'x-format-type' => 'datetime',
350
+ 'x-format-datetime-format' => '%Y'
351
+ ))
352
+ assert_equal(
353
+ {
354
+ 'base' => '$ {value}',
355
+ 'type' => 'datetime',
356
+ 'datetime' => {
357
+ 'format' => '%Y'
358
+ }
359
+ },
360
+ schema_with_datetime_format['format']
361
+ )
362
+
363
+ schema_with_number_format = layout_legacy_schema.text_block_item_schema(base_legacy_attributes.merge(
364
+ 'x-format-type' => 'number',
365
+ 'x-format-number-precision' => '1',
366
+ 'x-format-number-delimiter' => ','
367
+ ))
368
+ assert_equal(
369
+ {
370
+ 'base' => '$ {value}',
371
+ 'type' => 'number',
372
+ 'number' => {
373
+ 'delimiter' => ',',
374
+ 'precision' => 1
375
+ }
376
+ },
377
+ schema_with_number_format['format']
378
+ )
379
+
380
+ schema_with_padding_format = layout_legacy_schema.text_block_item_schema(base_legacy_attributes.merge(
381
+ 'x-format-type' => 'padding',
382
+ 'x-format-padding-char' => '0',
383
+ 'x-format-padding-length' => '10',
384
+ 'x-format-padding-direction' => 'L'
385
+ ))
386
+ assert_equal(
387
+ {
388
+ 'base' => '$ {value}',
389
+ 'type' => 'padding',
390
+ 'padding' => {
391
+ 'length' => 10,
392
+ 'char' => '0',
393
+ 'direction' => 'L'
394
+ }
395
+ },
396
+ schema_with_padding_format['format']
397
+ )
398
+ end
399
+
400
+ def test_list_item_schema
401
+ rect_item_svg = '<rect stroke="#000000" stroke-width="1" fill="#FFFFFF" class="s-rect" x-display="true" x-stroke-type="solid" stroke-dasharray="none" x-id="" rx="0" width="102.6" height="42" x="40" y="20"/>'
402
+
403
+ legacy_schema = {
404
+ 'id' => 'default',
405
+ 'type' => 's-list',
406
+ 'content-height' => '300',
407
+ 'page-break' => 'true',
408
+ 'display' => 'false',
409
+ 'header-enabled' => 'true',
410
+ 'page-footer-enabled' => 'true',
411
+ 'footer-enabled' => 'false',
412
+ 'header' => {
413
+ 'height' => '100.1',
414
+ 'translate' => {
415
+ 'x' => '100',
416
+ 'y' => '200'
417
+ },
418
+ 'svg' => { 'content' => '' }
419
+ },
420
+ 'detail' => {
421
+ 'height' => '200.1',
422
+ 'translate' => {
423
+ 'x' => '300',
424
+ 'y' => '400'
425
+ },
426
+ 'svg' => {
427
+ 'content' => rect_item_svg
428
+ }
429
+ },
430
+ 'page-footer' => {
431
+ 'height' => '300.1',
432
+ 'translate' => {
433
+ 'x' => '500',
434
+ 'y' => '600'
435
+ },
436
+ 'svg' => { 'content' => '' }
437
+ },
438
+ 'footer' => {
439
+ 'height' => '400.1',
440
+ 'translate' => {
441
+ 'x' => '700',
442
+ 'y' => '800'
443
+ },
444
+ 'svg' => { 'content' => '' }
445
+ }
446
+ }
447
+ assert_equal(
448
+ {
449
+ 'id' => 'default',
450
+ 'type' => 'list',
451
+ 'content-height' => 300.0,
452
+ 'auto-page-break' => true,
453
+ 'display' => false,
454
+ 'header' => {
455
+ 'height' => 100.1,
456
+ 'translate' => {
457
+ 'x' => 100.0,
458
+ 'y' => 200.0
459
+ },
460
+ 'items' => [],
461
+ 'enabled' => true
462
+ },
463
+ 'detail' => {
464
+ 'height' => 200.1,
465
+ 'translate' => {
466
+ 'x' => 300.0,
467
+ 'y' => 400.0
468
+ },
469
+ 'items' => [{
470
+ 'id' => '',
471
+ 'type' => 'rect',
472
+ 'x' => 40.0,
473
+ 'y' => 20.0,
474
+ 'width' => 102.6,
475
+ 'height' => 42.0,
476
+ 'display' => true,
477
+ 'style' => {
478
+ 'border-width' => 1.0,
479
+ 'border-color' => '#000000',
480
+ 'border-style' => 'solid',
481
+ 'fill-color' => '#FFFFFF'
482
+ }
483
+ }]
484
+ },
485
+ 'page-footer' => {
486
+ 'height' => 300.1,
487
+ 'translate' => {
488
+ 'x' => 500.0,
489
+ 'y' => 600.0
490
+ },
491
+ 'items' => [],
492
+ 'enabled' => true
493
+ },
494
+ 'footer' => {
495
+ 'height' => 400.1,
496
+ 'translate' => {
497
+ 'x' => 700.0,
498
+ 'y' => 800.0
499
+ },
500
+ 'items' => [],
501
+ 'enabled' => false
502
+ }
503
+ },
504
+ layout_legacy_schema.list_item_schema(legacy_schema)
505
+ )
506
+ end
507
+
508
+ def test_image_position_y
509
+ assert_equal 'top', layout_legacy_schema.image_position_y('top')
510
+ assert_equal 'middle', layout_legacy_schema.image_position_y('center')
511
+ assert_equal 'bottom', layout_legacy_schema.image_position_y('bottom')
512
+ end
513
+
514
+ def test_display
515
+ assert_equal true, layout_legacy_schema.display('true')
516
+ assert_equal false, layout_legacy_schema.display('false')
517
+ end
518
+
519
+ def test_font_style
520
+ no_style = {
521
+ 'font-weight' => 'normal',
522
+ 'font-style' => 'normal',
523
+ 'text-decoration' => 'none'
524
+ }
525
+ assert_equal [], layout_legacy_schema.font_style(no_style)
526
+ assert_equal %w( bold ), layout_legacy_schema.font_style(no_style.merge('font-weight' => 'bold'))
527
+ assert_equal %w( italic ), layout_legacy_schema.font_style(no_style.merge('font-style' => 'italic'))
528
+ assert_equal %w( underline ), layout_legacy_schema.font_style(no_style.merge('text-decoration' => 'underline'))
529
+ assert_equal %w( linethrough ), layout_legacy_schema.font_style(no_style.merge('text-decoration' => 'line-through'))
530
+ assert_equal %w( underline linethrough ), layout_legacy_schema.font_style(no_style.merge('text-decoration' => 'line-through underline'))
531
+ end
532
+
533
+ def test_text_align
534
+ assert_equal 'left', layout_legacy_schema.text_align('start')
535
+ assert_equal 'center', layout_legacy_schema.text_align('middle')
536
+ assert_equal 'right', layout_legacy_schema.text_align('end')
537
+ end
538
+
539
+ def test_vertical_align
540
+ assert_equal nil, layout_legacy_schema.vertical_align(nil)
541
+ assert_equal 'top', layout_legacy_schema.vertical_align('top')
542
+ assert_equal 'middle', layout_legacy_schema.vertical_align('center')
543
+ assert_equal 'bottom', layout_legacy_schema.vertical_align('bottom')
544
+ assert_equal 'top', layout_legacy_schema.vertical_align('')
545
+ end
546
+
547
+ def test_line_height
548
+ assert_equal '', layout_legacy_schema.line_height('')
549
+ assert_equal 20.1, layout_legacy_schema.line_height('20.1')
550
+ end
551
+
552
+ def test_letter_spacing
553
+ assert_equal '', layout_legacy_schema.letter_spacing('')
554
+ assert_equal '', layout_legacy_schema.letter_spacing('auto')
555
+ assert_equal 2.5, layout_legacy_schema.letter_spacing('2.5')
556
+ end
557
+
558
+ def test_level_symbol
559
+ assert_equal '', layout_legacy_schema.level_symbol(1)
560
+ assert_equal '-', layout_legacy_schema.level_symbol(2)
561
+ end
562
+
563
+ def test_extract_item_schemas
564
+ svg = <<-SVG
565
+ <!--SHAPE{"id":"item1"}SHAPE-->
566
+ <!--LAYOUT<rect id="item2"/>LAYOUT-->
567
+ <!--SHAPE{"id":"item3"}SHAPE-->
568
+ SVG
569
+ assert_equal(
570
+ { 'item1' => { 'id' => 'item1' }, 'item3' => { 'id' => 'item3' } },
571
+ layout_legacy_schema.extract_item_schemas(svg, 1)
572
+ )
573
+ end
574
+
575
+ def test_normalize_svg
576
+ svg = '<!---SHAPE{"id":"item1"}SHAPE---><!---LAYOUT<rect id="item2"/>LAYOUT---><!--SHAPE{"id":"item2"}SHAPE-->'
577
+ normalized_svg = '<rect id="item2"/><!--SHAPE{"id":"item2"}SHAPE-->'
578
+
579
+ assert_equal normalized_svg, layout_legacy_schema.normalize_svg(svg, 2)
580
+ end
581
+
582
+ private
583
+
584
+ def layout_legacy_schema
585
+ @layout_legacy_schema ||= Layout::LegacySchema.new({})
586
+ end
587
+ end