nishidayuya-rd2odt 0.0.0 → 0.0.1

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.
@@ -0,0 +1,829 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.join(File.dirname(__FILE__), "..", "test-helper")
4
+
5
+ describe RD2ODT, "ah_to_xml" do
6
+ # not supported.
7
+ # it "returns empty string if empty array" do
8
+ # RD2ODT.ah_to_xml([]).should == nil
9
+ # end
10
+
11
+ it "returns xml document" do
12
+ RD2ODT.ah_to_xml([:br]).should == "<br />"
13
+ RD2ODT.ah_to_xml([:text__p]).should == "<text:p />"
14
+ RD2ODT.ah_to_xml([:text__style_name]).should == "<text:style-name />"
15
+ RD2ODT.ah_to_xml([:text__sequence_decl,
16
+ {
17
+ :text__display_outline_level => "0",
18
+ :text__name => "Table",
19
+ },
20
+ ]).should ==
21
+ '<text:sequence-decl text:display-outline-level="0" text:name="Table" />'
22
+ RD2ODT.ah_to_xml([:text__p, "this is a pen."]).should ==
23
+ "<text:p>this is a pen.</text:p>"
24
+ RD2ODT.ah_to_xml([:text__p, '&"><']).should ==
25
+ "<text:p>&amp;&quot;&gt;&lt;</text:p>"
26
+ RD2ODT.ah_to_xml([:text__p,
27
+ %Q'Lo<text:s text:c="2" />ok&gt;'.to_sym]).should ==
28
+ %Q'<text:p>Lo<text:s text:c="2" />ok&gt;</text:p>'
29
+ RD2ODT.ah_to_xml([:text__p,
30
+ {:text__style_name => "Text_20_body"},
31
+ "this is a pen.",
32
+ ]).should ==
33
+ '<text:p text:style-name="Text_20_body">this is a pen.</text:p>'
34
+ RD2ODT.ah_to_xml([:office__text,
35
+ [:text__p,
36
+ {:text__style_name => "Text_20_body"},
37
+ "this is a pen.",
38
+ ],
39
+ ]).should ==
40
+ <<EOF.gsub(/\n\z/, "")
41
+ <office:text>
42
+ <text:p text:style-name="Text_20_body">this is a pen.</text:p>
43
+ </office:text>
44
+ EOF
45
+ RD2ODT.ah_to_xml([:office__body,
46
+ {
47
+ :abc__def_ghi => "123",
48
+ :jkl_mno__pqr => "456",
49
+ },
50
+ [:office__text,
51
+ [:text__p,
52
+ {:text__style_name => "Text_20_body"},
53
+ "this is a pen.",
54
+ ],
55
+ ],
56
+ ]).should ==
57
+ <<EOF.gsub(/\n\z/, "")
58
+ <office:body abc:def-ghi="123" jkl-mno:pqr="456">
59
+ <office:text>
60
+ <text:p text:style-name="Text_20_body">this is a pen.</text:p>
61
+ </office:text>
62
+ </office:body>
63
+ EOF
64
+ RD2ODT.ah_to_xml([
65
+ [:text__p,
66
+ {:text__style_name => "Preformatted_20_Text"},
67
+ "text-1",
68
+ ],
69
+ [:text__p,
70
+ {:text__style_name => "Preformatted_20_Text"},
71
+ "text-2",
72
+ ],
73
+ ]).should ==
74
+ <<EOF.gsub(/\n\z/, "")
75
+ <text:p text:style-name="Preformatted_20_Text">text-1</text:p>
76
+ <text:p text:style-name="Preformatted_20_Text">text-2</text:p>
77
+ EOF
78
+ end
79
+ end
80
+
81
+ def str_to_treat_input_ary(s)
82
+ ary = s.split("\n").map { |l|
83
+ l + "\n"
84
+ }
85
+
86
+ # last line does not have "\n" case.
87
+ if !/\n\z/.match(s)
88
+ ary.last.chomp!
89
+ end
90
+
91
+ return ary
92
+ end
93
+
94
+ describe RD2ODT, "treat_input" do
95
+ it "adds '=begin' to first line and adds '=end' to last line if both lines is
96
+ not exist." do
97
+ actual_str = <<ACTUAL
98
+ foo
99
+ bar
100
+ ACTUAL
101
+ expected = str_to_treat_input_ary(<<EXPECTED)
102
+ =begin
103
+ foo
104
+ bar
105
+ =end
106
+ EXPECTED
107
+
108
+ actual_1 = str_to_treat_input_ary(actual_str)
109
+ RD2ODT.treat_input(actual_1).should == expected
110
+
111
+ actual_2 = str_to_treat_input_ary(actual_str.chomp)
112
+ RD2ODT.treat_input(actual_2).should == expected
113
+ end
114
+
115
+ it "does not add '=begin' to first line if it is exist." do
116
+ ary = str_to_treat_input_ary(<<EOF)
117
+ foo
118
+ =begin
119
+ bar
120
+ EOF
121
+ RD2ODT.treat_input(ary.dup).should == ary.dup
122
+ end
123
+
124
+ it "does not add '=end' to last line if it is exist." do
125
+ ary = str_to_treat_input_ary(<<EOF)
126
+ foo
127
+ =end
128
+ bar
129
+ EOF
130
+ RD2ODT.treat_input(ary.dup).should == ary.dup
131
+ end
132
+ end
133
+
134
+ describe RD2ODT::RD2ODTVisitor, "apply_to_DocumentElement" do
135
+ before do
136
+ @visitor = RD2ODT::RD2ODTVisitor.new
137
+ end
138
+
139
+ it "returns top level document structure" do
140
+ sub_content = [:text__p,
141
+ {:text__style_name => "Text_20_body"},
142
+ "本文",
143
+ ]
144
+ result = @visitor.apply_to_DocumentElement(nil,
145
+ [sub_content,
146
+ sub_content])
147
+ result.should ==
148
+ [:office__document_content,
149
+ {
150
+ :xmlns__office => "urn:oasis:names:tc:opendocument:xmlns:office:1.0",
151
+ :xmlns__style => "urn:oasis:names:tc:opendocument:xmlns:style:1.0",
152
+ :xmlns__text => "urn:oasis:names:tc:opendocument:xmlns:text:1.0",
153
+ :xmlns__table => "urn:oasis:names:tc:opendocument:xmlns:table:1.0",
154
+ :xmlns__draw => "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0",
155
+ :xmlns__fo =>
156
+ "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0",
157
+ :xmlns__xlink => "http://www.w3.org/1999/xlink",
158
+ :xmlns__dc => "http://purl.org/dc/elements/1.1/",
159
+ :xmlns__meta => "urn:oasis:names:tc:opendocument:xmlns:meta:1.0",
160
+ :xmlns__number =>
161
+ "urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0",
162
+ :xmlns__svg =>
163
+ "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0",
164
+ :xmlns__chart => "urn:oasis:names:tc:opendocument:xmlns:chart:1.0",
165
+ :xmlns__dr3d => "urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0",
166
+ :xmlns__math => "http://www.w3.org/1998/Math/MathML",
167
+ :xmlns__form => "urn:oasis:names:tc:opendocument:xmlns:form:1.0",
168
+ :xmlns__script => "urn:oasis:names:tc:opendocument:xmlns:script:1.0",
169
+ :xmlns__ooo => "http://openoffice.org/2004/office",
170
+ :xmlns__ooow => "http://openoffice.org/2004/writer",
171
+ :xmlns__oooc => "http://openoffice.org/2004/calc",
172
+ :xmlns__dom => "http://www.w3.org/2001/xml-events",
173
+ :xmlns__xforms => "http://www.w3.org/2002/xforms",
174
+ :xmlns__xsd => "http://www.w3.org/2001/XMLSchema",
175
+ :xmlns__xsi => "http://www.w3.org/2001/XMLSchema-instance",
176
+ :xmlns__field =>
177
+ "urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:field:1.0",
178
+ :office__version => "1.1",
179
+ },
180
+ [:office__scripts],
181
+ [:office__font_face_decls,
182
+ [:style__font_face,
183
+ {
184
+ :style__name => "さざなみ明朝",
185
+ :svg__font_family => "さざなみ明朝",
186
+ :style__font_family_generic => "roman",
187
+ :style__font_pitch => "variable",
188
+ }],
189
+ [:style__font_face,
190
+ {
191
+ :style__name => "IPAゴシック",
192
+ :svg__font_family => "IPAゴシック",
193
+ :style__font_family_generic => "swiss",
194
+ :style__font_pitch => "variable",
195
+ }],
196
+ [:style__font_face,
197
+ {
198
+ :style__name => "IPAゴシック1",
199
+ :svg__font_family => "IPAゴシック",
200
+ :style__font_family_generic => "system",
201
+ :style__font_pitch => "variable",
202
+ }],
203
+ ], # :office__font_face_decls
204
+ [:office__automatic_styles],
205
+ [:office__body,
206
+ [:office__text,
207
+ [:text__sequence_decls,
208
+ [:text__sequence_decl,
209
+ {
210
+ :text__display_outline_level => "0",
211
+ :text__name => "Illustration",
212
+ }],
213
+ [:text__sequence_decl,
214
+ {
215
+ :text__display_outline_level => "0",
216
+ :text__name => "Table",
217
+ }],
218
+ [:text__sequence_decl,
219
+ {
220
+ :text__display_outline_level => "0",
221
+ :text__name => "Text",
222
+ }],
223
+ [:text__sequence_decl,
224
+ {
225
+ :text__display_outline_level => "0",
226
+ :text__name => "Drawing",
227
+ }],
228
+ ], # :text__sequence_decls
229
+ sub_content,
230
+ sub_content,
231
+ ], # :office__text
232
+ ], # :office__body
233
+ ] # :office__document_content
234
+ end
235
+
236
+ it "returns top level document structure with office:automatic-styles" do
237
+ sub_content = [:text__p,
238
+ {:text__style_name => "Text_20_body"},
239
+ "本文",
240
+ ]
241
+ styles = []
242
+ styles << "<a><b/></a>"
243
+ styles << "<c d='e'><f/></c>"
244
+ styles.each do |s|
245
+ @visitor.automatic_styles << REXML::Document.new(s)
246
+ end
247
+ result = @visitor.apply_to_DocumentElement(nil,
248
+ [sub_content,
249
+ sub_content])
250
+ result.should ==
251
+ [:office__document_content,
252
+ {
253
+ :xmlns__office => "urn:oasis:names:tc:opendocument:xmlns:office:1.0",
254
+ :xmlns__style => "urn:oasis:names:tc:opendocument:xmlns:style:1.0",
255
+ :xmlns__text => "urn:oasis:names:tc:opendocument:xmlns:text:1.0",
256
+ :xmlns__table => "urn:oasis:names:tc:opendocument:xmlns:table:1.0",
257
+ :xmlns__draw => "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0",
258
+ :xmlns__fo =>
259
+ "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0",
260
+ :xmlns__xlink => "http://www.w3.org/1999/xlink",
261
+ :xmlns__dc => "http://purl.org/dc/elements/1.1/",
262
+ :xmlns__meta => "urn:oasis:names:tc:opendocument:xmlns:meta:1.0",
263
+ :xmlns__number =>
264
+ "urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0",
265
+ :xmlns__svg =>
266
+ "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0",
267
+ :xmlns__chart => "urn:oasis:names:tc:opendocument:xmlns:chart:1.0",
268
+ :xmlns__dr3d => "urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0",
269
+ :xmlns__math => "http://www.w3.org/1998/Math/MathML",
270
+ :xmlns__form => "urn:oasis:names:tc:opendocument:xmlns:form:1.0",
271
+ :xmlns__script => "urn:oasis:names:tc:opendocument:xmlns:script:1.0",
272
+ :xmlns__ooo => "http://openoffice.org/2004/office",
273
+ :xmlns__ooow => "http://openoffice.org/2004/writer",
274
+ :xmlns__oooc => "http://openoffice.org/2004/calc",
275
+ :xmlns__dom => "http://www.w3.org/2001/xml-events",
276
+ :xmlns__xforms => "http://www.w3.org/2002/xforms",
277
+ :xmlns__xsd => "http://www.w3.org/2001/XMLSchema",
278
+ :xmlns__xsi => "http://www.w3.org/2001/XMLSchema-instance",
279
+ :xmlns__field =>
280
+ "urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:field:1.0",
281
+ :office__version => "1.1",
282
+ },
283
+ [:office__scripts],
284
+ [:office__font_face_decls,
285
+ [:style__font_face,
286
+ {
287
+ :style__name => "さざなみ明朝",
288
+ :svg__font_family => "さざなみ明朝",
289
+ :style__font_family_generic => "roman",
290
+ :style__font_pitch => "variable",
291
+ }],
292
+ [:style__font_face,
293
+ {
294
+ :style__name => "IPAゴシック",
295
+ :svg__font_family => "IPAゴシック",
296
+ :style__font_family_generic => "swiss",
297
+ :style__font_pitch => "variable",
298
+ }],
299
+ [:style__font_face,
300
+ {
301
+ :style__name => "IPAゴシック1",
302
+ :svg__font_family => "IPAゴシック",
303
+ :style__font_family_generic => "system",
304
+ :style__font_pitch => "variable",
305
+ }],
306
+ ], # :office__font_face_decls
307
+ [:office__automatic_styles,
308
+ *styles.map { |s|
309
+ s.to_sym
310
+ }
311
+ ],
312
+ [:office__body,
313
+ [:office__text,
314
+ [:text__sequence_decls,
315
+ [:text__sequence_decl,
316
+ {
317
+ :text__display_outline_level => "0",
318
+ :text__name => "Illustration",
319
+ }],
320
+ [:text__sequence_decl,
321
+ {
322
+ :text__display_outline_level => "0",
323
+ :text__name => "Table",
324
+ }],
325
+ [:text__sequence_decl,
326
+ {
327
+ :text__display_outline_level => "0",
328
+ :text__name => "Text",
329
+ }],
330
+ [:text__sequence_decl,
331
+ {
332
+ :text__display_outline_level => "0",
333
+ :text__name => "Drawing",
334
+ }],
335
+ ], # :text__sequence_decls
336
+ sub_content,
337
+ sub_content,
338
+ ], # :office__text
339
+ ], # :office__body
340
+ ] # :office__document_content
341
+ end
342
+ end
343
+
344
+ describe RD2ODT::RD2ODTVisitor, "apply_to_StringElement" do
345
+ before do
346
+ @visitor = RD2ODT::RD2ODTVisitor.new
347
+ end
348
+
349
+ it "returns text:p element" do
350
+ element = RD::StringElement.new("本文\n")
351
+ result = @visitor.apply_to_StringElement(element)
352
+ result.should == "本文"
353
+ end
354
+
355
+ it "remove \\r and \\n charactor" do
356
+ element = RD::StringElement.new("本文1\n本文2\n本文3\n")
357
+ result = @visitor.apply_to_StringElement(element)
358
+ result.should == "本文1本文2本文3"
359
+
360
+ element = RD::StringElement.new("本文1\r\n本文2\r\n本文3\r\n")
361
+ result = @visitor.apply_to_StringElement(element)
362
+ result.should == "本文1本文2本文3"
363
+ end
364
+ end
365
+
366
+ describe RD2ODT::RD2ODTVisitor, "apply_to_TextBlock" do
367
+ before do
368
+ @visitor = RD2ODT::RD2ODTVisitor.new
369
+ end
370
+
371
+ it "returns text:p element" do
372
+ sub_content = "本文"
373
+ result = @visitor.apply_to_TextBlock(nil, [sub_content])
374
+ result.should == [:text__p,
375
+ {:text__style_name => "Text_20_body"},
376
+ sub_content,
377
+ ]
378
+ end
379
+ end
380
+
381
+ describe RD2ODT::RD2ODTVisitor, "apply_to_Headline" do
382
+ before do
383
+ @visitor = RD2ODT::RD2ODTVisitor.new
384
+ end
385
+
386
+ it "returns text:list element in '=' level without text:continue-numbering when first '='" do
387
+ level = 1
388
+ title = "見出し1"
389
+ element = RD::Headline.new(level)
390
+ element.title << title
391
+ result = @visitor.apply_to_Headline(element, element.title)
392
+ result.should == [:text__list,
393
+ {:text__style_name => "Numbering_20_2"},
394
+ [:text__list_item,
395
+ [:text__p,
396
+ {:text__style_name => "Heading_20_1"},
397
+ "見出し1"
398
+ ],
399
+ ],
400
+ ]
401
+ @visitor.continue_numbering_headline.should == true
402
+ end
403
+
404
+ it "returns text:list element in '=' level with text:continue-numbering when not first '='" do
405
+ level = 1
406
+ title = "見出し2"
407
+ element = RD::Headline.new(level)
408
+ element.title << title
409
+ @visitor.continue_numbering_headline = true
410
+ result = @visitor.apply_to_Headline(element, element.title)
411
+ result.should == [:text__list,
412
+ {
413
+ :text__style_name => "Numbering_20_2",
414
+ :text__continue_numbering => "true",
415
+ },
416
+ [:text__list_item,
417
+ [:text__p,
418
+ {:text__style_name => "Heading_20_1"},
419
+ "見出し2"
420
+ ],
421
+ ],
422
+ ]
423
+ @visitor.continue_numbering_headline.should == true
424
+ end
425
+
426
+ it "returns text:list element in '==' level" do
427
+ level = 2
428
+ title = "見出し2"
429
+ element = RD::Headline.new(level)
430
+ element.title << title
431
+ result = @visitor.apply_to_Headline(element, element.title)
432
+ result.should == [:text__list,
433
+ {
434
+ :text__style_name => "Numbering_20_2",
435
+ :text__continue_numbering => "true",
436
+ },
437
+ [:text__list_item,
438
+ [:text__list,
439
+ {:text__continue_numbering => "true"},
440
+ [:text__list_item,
441
+ [:text__p,
442
+ {:text__style_name => "Heading_20_2"},
443
+ "見出し2",
444
+ ],
445
+ ],
446
+ ],
447
+ ],
448
+ ]
449
+ end
450
+
451
+ it "returns text:list element in '===' level" do
452
+ level = 3
453
+ title = "見出し3"
454
+ element = RD::Headline.new(level)
455
+ element.title << title
456
+ result = @visitor.apply_to_Headline(element, element.title)
457
+ result.should == [:text__list,
458
+ {
459
+ :text__style_name => "Numbering_20_2",
460
+ :text__continue_numbering => "true",
461
+ },
462
+ [:text__list_item,
463
+ [:text__list,
464
+ {:text__continue_numbering => "true"},
465
+ [:text__list_item,
466
+ [:text__list,
467
+ {:text__continue_numbering => "true"},
468
+ [:text__list_item,
469
+ [:text__p,
470
+ {:text__style_name => "Heading_20_3"},
471
+ "見出し3",
472
+ ],
473
+ ],
474
+ ],
475
+ ],
476
+ ],
477
+ ],
478
+ ]
479
+ end
480
+ end
481
+
482
+ describe RD2ODT::RD2ODTVisitor, "apply_to_EnumListItem" do
483
+ before do
484
+ @visitor = RD2ODT::RD2ODTVisitor.new
485
+ end
486
+
487
+ it "returns text:list-item element" do
488
+ result = @visitor.apply_to_EnumListItem(nil, [:sub_content_1,
489
+ :sub_content_2])
490
+ result.should == [:text__list_item,
491
+ :sub_content_1,
492
+ :sub_content_2,
493
+ ]
494
+ end
495
+ end
496
+
497
+ describe RD2ODT::RD2ODTVisitor, "apply_to_EnumList" do
498
+ before do
499
+ @visitor = RD2ODT::RD2ODTVisitor.new
500
+ end
501
+
502
+ it "returns text:list element" do
503
+ result = @visitor.apply_to_EnumList(nil, [:sub_content_1,
504
+ :sub_content_2])
505
+ result.should == [:text__list,
506
+ {
507
+ :text__style_name => "Numbering_20_1",
508
+ :text__continue_numbering => "false",
509
+ },
510
+ :sub_content_1,
511
+ :sub_content_2,
512
+ ]
513
+ end
514
+ end
515
+
516
+ describe RD2ODT::RD2ODTVisitor, "apply_to_ItemListItem" do
517
+ before do
518
+ @visitor = RD2ODT::RD2ODTVisitor.new
519
+ end
520
+
521
+ # same as apply_to_EnumListItem
522
+ it "returns text:list-item element" do
523
+ result = @visitor.apply_to_ItemListItem(nil, [:sub_content_1,
524
+ :sub_content_2])
525
+ result.should == [:text__list_item,
526
+ :sub_content_1,
527
+ :sub_content_2,
528
+ ]
529
+ end
530
+ end
531
+
532
+ describe RD2ODT::RD2ODTVisitor, "apply_to_ItemList" do
533
+ before do
534
+ @visitor = RD2ODT::RD2ODTVisitor.new
535
+ end
536
+
537
+ it "returns text:list element" do
538
+ result = @visitor.apply_to_ItemList(nil, [:sub_content_1,
539
+ :sub_content_2])
540
+ result.should == [:text__list,
541
+ {:text__style_name => "List_20_1"},
542
+ :sub_content_1,
543
+ :sub_content_2,
544
+ ]
545
+ end
546
+ end
547
+
548
+ describe RD2ODT::RD2ODTVisitor, "apply_to_Verbatim" do
549
+ before do
550
+ @visitor = RD2ODT::RD2ODTVisitor.new
551
+ end
552
+
553
+ it "returns text:list element" do
554
+ content_strings = [
555
+ "This is verbatim element.\n",
556
+ " " * 2 + "Lo" + " " * 5 + "ok!\n",
557
+ "\tLo" + "\t\t" + "ok!\n",
558
+ "In the last line, text:line-break is not exist.\n",
559
+ ]
560
+ element = RD::Verbatim.new(content_strings)
561
+ result = @visitor.apply_to_Verbatim(element)
562
+ result.should == [:text__p,
563
+ {:text__style_name => "Preformatted_20_Text"},
564
+ [
565
+ "This is verbatim element.",
566
+ '<text:s text:c="2" />Lo<text:s text:c="5" />ok!<text:line-break /><text:tab />Lo<text:tab /><text:tab />ok!',
567
+ "In the last line, text:line-break is not exist.",
568
+ ].join("<text:line-break />").to_sym,
569
+ ]
570
+ end
571
+ end
572
+
573
+ describe RD2ODT::RD2ODTVisitor, "apply_to_Include" do
574
+ before do
575
+ class Time
576
+ class << self
577
+ alias orig_now now
578
+
579
+ def now
580
+ return Time.mktime(2008, 12, 30, 12, 34, 56, 78901)
581
+ end
582
+ end
583
+ end
584
+
585
+ @name_prefix = sprintf("rd2odt:%d:%06d:%d:",
586
+ Time.now.tv_sec, Time.now.tv_usec, 1)
587
+
588
+ @visitor = RD2ODT::RD2ODTVisitor.new
589
+
590
+ sample_dir_path = File.join($top_srcdir, "doc", "sample")
591
+ tree_mock = Struct.new(:include_paths).new([sample_dir_path])
592
+ @parent_element = Struct.new(:tree).new(tree_mock)
593
+ end
594
+
595
+ after do
596
+ class Time
597
+ class << self
598
+ alias now orig_now
599
+ end
600
+ end
601
+ end
602
+
603
+ it "includes other document" do
604
+ element = RD::Include.new("include-file-simple-text.odt")
605
+ element.parent = @parent_element
606
+ result = @visitor.apply_to_Include(element)
607
+ result[0].should == <<EOF.chomp.to_sym
608
+ <text:p text:style-name='#{@name_prefix}Standard'>これは&lt;&lt;&lt;のサンプルです.</text:p>
609
+ EOF
610
+ result[1].should == <<EOF.chomp.to_sym
611
+ <text:p text:style-name='#{@name_prefix}Standard'>単純なテキストのincludeサンプルです.</text:p>
612
+ EOF
613
+ result[2].should == <<EOF.chomp.to_sym
614
+ <text:p text:style-name='#{@name_prefix}Standard'/>
615
+ EOF
616
+ result.length.should == 3
617
+ result.class.should == Array
618
+ @visitor.number_of_include_files.should == 1
619
+ @visitor.additional_styles[0].to_s.should == <<EOF.chomp
620
+ <style:style style:name='#{@name_prefix}Standard' style:class='text' style:family='paragraph'/>
621
+ EOF
622
+ @visitor.additional_styles[1].to_s.should == <<EOF.chomp
623
+ <style:style style:name='#{@name_prefix}Text_20_body' style:class='text' style:parent-style-name='#{@name_prefix}Standard' style:display-name='#{@name_prefix}Text body' style:family='paragraph'>
624
+ <style:paragraph-properties fo:margin-bottom='0.212cm' fo:margin-top='0cm'/>
625
+ </style:style>
626
+ EOF
627
+ # additional_styles[2..6] test is omitted.
628
+ @visitor.additional_styles.length.should == 7
629
+ @visitor.additional_styles.class == Array
630
+ end
631
+
632
+ =begin
633
+ it "includes other document" do
634
+ element = RD::Include.new("include-file-simple-styled-text.odt")
635
+ element.parent = @parent_element
636
+ result = @visitor.apply_to_Include(element)
637
+ result[0].should == <<EOF.chomp.to_sym
638
+ <text:p text:style-name='Standard'>これは&lt;&lt;&lt;のサンプルです.</text:p>
639
+ EOF
640
+ result[1].should == <<EOF.chomp.to_sym
641
+ <text:p text:style-name='Standard'>標準: 単純なテキストのincludeサンプルです.</text:p>
642
+ EOF
643
+ result[2].should == <<EOF.chomp.to_sym
644
+ <text:p text:style-name='Standard'/>
645
+ EOF
646
+ result[3].should == <<EOF.chomp.to_sym
647
+ <text:h text:outline-level='1' text:style-name='Heading_20_1'>見出し1</text:h>
648
+ EOF
649
+ result[4].should == <<EOF.chomp.to_sym
650
+ <text:h text:outline-level='2' text:style-name='Heading_20_2'>見出し1.1</text:h>
651
+ EOF
652
+ result[5].should == <<EOF.chomp.to_sym
653
+ <text:p text:style-name='Text_20_body'>本文</text:p>
654
+ EOF
655
+ result[6].should == <<EOF.chomp.to_sym
656
+ <text:p text:style-name='Standard'/>
657
+ EOF
658
+ result[7].should == <<EOF.chomp.to_sym
659
+ <text:p text:style-name='Preformatted_20_Text'>書式設定前テキスト</text:p>
660
+ EOF
661
+ result[8].should == <<EOF.chomp.to_sym
662
+ <text:p text:style-name='Standard'/>
663
+ EOF
664
+ result[9].should == <<EOF.chomp.to_sym
665
+ <text:p text:style-name='Standard'>文字用書式スタイルのincludeテスト</text:p>
666
+ EOF
667
+ result[10].should == <<EOF.chomp.to_sym
668
+ <text:p text:style-name='Standard'><text:span text:style-name='Emphasis'>強調</text:span>標準</text:p>
669
+ EOF
670
+ result[11].should == <<EOF.chomp.to_sym
671
+ <text:p text:style-name='Standard'><text:span text:style-name='Variable'>変数</text:span>標準</text:p>
672
+ EOF
673
+ result[12].should == <<EOF.chomp.to_sym
674
+ <text:p text:style-name='Standard'><text:span text:style-name='Teletype'>等幅フォント</text:span>標準</text:p>
675
+ EOF
676
+ result[13].should == <<EOF.chomp.to_sym
677
+ <text:p text:style-name='Standard'/>
678
+ EOF
679
+ result.length.should == 14
680
+ result.class.should == Array
681
+ end
682
+ =end
683
+
684
+ it "includes other document which containts table:table" do
685
+ element = RD::Include.new("include-file-table.odt")
686
+ element.parent = @parent_element
687
+ result = @visitor.apply_to_Include(element)
688
+ result[0].should == <<EOF.chomp.to_sym
689
+ <text:p text:style-name='#{@name_prefix}Standard'>これは&lt;&lt;&lt;のサンプルです.</text:p>
690
+ EOF
691
+ result[1].should == <<EOF.chomp.to_sym
692
+ <table:table table:name='#{@name_prefix}表1' table:style-name='#{@name_prefix}表1'>
693
+ <table:table-column table:number-columns-repeated='3' table:style-name='#{@name_prefix}表1.A'/>
694
+ <table:table-row>
695
+ <table:table-cell office:value-type='string' table:style-name='#{@name_prefix}表1.A1'>
696
+ <text:p text:style-name='#{@name_prefix}Table_20_Contents'>表つき文書の</text:p>
697
+ </table:table-cell>
698
+ <table:table-cell office:value-type='string' table:style-name='#{@name_prefix}表1.A1'>
699
+ <text:p text:style-name='#{@name_prefix}Table_20_Contents'>埋め込み</text:p>
700
+ </table:table-cell>
701
+ <table:table-cell office:value-type='string' table:style-name='#{@name_prefix}表1.C1'>
702
+ <text:p text:style-name='#{@name_prefix}Table_20_Contents'>サンプル</text:p>
703
+ </table:table-cell>
704
+ </table:table-row>
705
+ <table:table-row>
706
+ <table:table-cell office:value-type='string' table:style-name='#{@name_prefix}表1.A2'>
707
+ <text:p text:style-name='#{@name_prefix}Table_20_Contents'>1</text:p>
708
+ </table:table-cell>
709
+ <table:table-cell office:value-type='string' table:style-name='#{@name_prefix}表1.A2'>
710
+ <text:p text:style-name='#{@name_prefix}Table_20_Contents'>2</text:p>
711
+ </table:table-cell>
712
+ <table:table-cell office:value-type='string' table:style-name='#{@name_prefix}表1.C2'>
713
+ <text:p text:style-name='#{@name_prefix}Table_20_Contents'>3</text:p>
714
+ </table:table-cell>
715
+ </table:table-row>
716
+ </table:table>
717
+ EOF
718
+ result[2].should == <<EOF.chomp.to_sym
719
+ <text:p text:style-name='#{@name_prefix}Standard'/>
720
+ EOF
721
+ result.length.should == 3
722
+ result.class.should == Array
723
+ @visitor.automatic_styles[0].to_s.should == <<EOF.chomp
724
+ <style:style style:name='#{@name_prefix}表1' style:family='table'>
725
+ <style:table-properties table:align='margins' style:width='16.999cm'/>
726
+ </style:style>
727
+ EOF
728
+ @visitor.automatic_styles[1].to_s.should == <<EOF.chomp
729
+ <style:style style:name='#{@name_prefix}表1.A' style:family='table-column'>
730
+ <style:table-column-properties style:column-width='5.666cm' style:rel-column-width='21845*'/>
731
+ </style:style>
732
+ EOF
733
+ # automatic_styles[2..5] test is omitted.
734
+ @visitor.automatic_styles.length.should == 6
735
+ @visitor.automatic_styles.class.should == Array
736
+ end
737
+
738
+ it "includes other document which containts draw:*" do
739
+ element = RD::Include.new("include-file-shape.odt")
740
+ element.parent = @parent_element
741
+ result = @visitor.apply_to_Include(element)
742
+ result[0].should == <<EOF.chomp.to_sym
743
+ <text:p text:style-name='#{@name_prefix}Standard'>これは&lt;&lt;&lt;のサンプルです.</text:p>
744
+ EOF
745
+ result[1].should == <<EOF.chomp.to_sym
746
+ <text:p text:style-name='#{@name_prefix}Standard'><draw:g text:anchor-type='paragraph' draw:z-index='0' draw:style-name='#{@name_prefix}gr1'><draw:custom-shape svg:x='3.348cm' svg:y='0.088cm' svg:height='3.911cm' draw:style-name='#{@name_prefix}gr2' svg:width='3.887cm'>
747
+ <text:p/>
748
+ <draw:enhanced-geometry draw:glue-points='10800 0 3160 3160 0 10800 3160 18440 10800 21600 18440 18440 21600 10800 18440 3160' draw:type='smiley' draw:enhanced-path='U 10800 10800 10800 10800 0 23592960 Z N U 7305 7515 1165 1165 0 23592960 Z N U 14295 7515 1165 1165 0 23592960 Z N M 4870 ?f1 C 8680 ?f2 12920 ?f2 16730 ?f1 F N' draw:modifiers='17520' draw:text-areas='3200 3200 18400 18400' svg:viewBox='0 0 21600 21600'>
749
+ <draw:equation draw:name='f0' draw:formula='$0 -15510'/>
750
+ <draw:equation draw:name='f1' draw:formula='17520-?f0 '/>
751
+ <draw:equation draw:name='f2' draw:formula='15510+?f0 '/>
752
+ <draw:handle draw:handle-range-y-maximum='17520' draw:handle-range-y-minimum='15510' draw:handle-position='10800 $0'/>
753
+ </draw:enhanced-geometry>
754
+ </draw:custom-shape><draw:custom-shape svg:x='8.225cm' svg:y='0.873cm' draw:text-style-name='P1' svg:height='1.881cm' draw:style-name='#{@name_prefix}gr3' svg:width='3.303cm'>
755
+ <text:p text:style-name='#{@name_prefix}P1'>Yes,</text:p>
756
+ <text:p text:style-name='#{@name_prefix}P1'>This is the sample!</text:p>
757
+ <draw:enhanced-geometry draw:type='round-rectangular-callout' draw:enhanced-path='M 3590 0 X 0 3590 L ?f2 ?f3 0 8970 0 12630 ?f4 ?f5 0 18010 Y 3590 21600 L ?f6 ?f7 8970 21600 12630 21600 ?f8 ?f9 18010 21600 X 21600 18010 L ?f10 ?f11 21600 12630 21600 8970 ?f12 ?f13 21600 3590 Y 18010 0 L ?f14 ?f15 12630 0 8970 0 ?f16 ?f17 Z N' draw:modifiers='-7311.47891083823 20689.0346766635' draw:text-areas='800 800 20800 20800' svg:viewBox='0 0 21600 21600'>
758
+ <draw:equation draw:name='f0' draw:formula='$0 -10800'/>
759
+ <draw:equation draw:name='f1' draw:formula='$1 -10800'/>
760
+ <draw:equation draw:name='f2' draw:formula='if(?f18 ,$0 ,0)'/>
761
+ <draw:equation draw:name='f3' draw:formula='if(?f18 ,$1 ,6280)'/>
762
+ <draw:equation draw:name='f4' draw:formula='if(?f23 ,$0 ,0)'/>
763
+ <draw:equation draw:name='f5' draw:formula='if(?f23 ,$1 ,15320)'/>
764
+ <draw:equation draw:name='f6' draw:formula='if(?f26 ,$0 ,6280)'/>
765
+ <draw:equation draw:name='f7' draw:formula='if(?f26 ,$1 ,21600)'/>
766
+ <draw:equation draw:name='f8' draw:formula='if(?f29 ,$0 ,15320)'/>
767
+ <draw:equation draw:name='f9' draw:formula='if(?f29 ,$1 ,21600)'/>
768
+ <draw:equation draw:name='f10' draw:formula='if(?f32 ,$0 ,21600)'/>
769
+ <draw:equation draw:name='f11' draw:formula='if(?f32 ,$1 ,15320)'/>
770
+ <draw:equation draw:name='f12' draw:formula='if(?f34 ,$0 ,21600)'/>
771
+ <draw:equation draw:name='f13' draw:formula='if(?f34 ,$1 ,6280)'/>
772
+ <draw:equation draw:name='f14' draw:formula='if(?f36 ,$0 ,15320)'/>
773
+ <draw:equation draw:name='f15' draw:formula='if(?f36 ,$1 ,0)'/>
774
+ <draw:equation draw:name='f16' draw:formula='if(?f38 ,$0 ,6280)'/>
775
+ <draw:equation draw:name='f17' draw:formula='if(?f38 ,$1 ,0)'/>
776
+ <draw:equation draw:name='f18' draw:formula='if($0 ,-1,?f19 )'/>
777
+ <draw:equation draw:name='f19' draw:formula='if(?f1 ,-1,?f22 )'/>
778
+ <draw:equation draw:name='f20' draw:formula='abs(?f0 )'/>
779
+ <draw:equation draw:name='f21' draw:formula='abs(?f1 )'/>
780
+ <draw:equation draw:name='f22' draw:formula='?f20 -?f21 '/>
781
+ <draw:equation draw:name='f23' draw:formula='if($0 ,-1,?f24 )'/>
782
+ <draw:equation draw:name='f24' draw:formula='if(?f1 ,?f22 ,-1)'/>
783
+ <draw:equation draw:name='f25' draw:formula='$1 -21600'/>
784
+ <draw:equation draw:name='f26' draw:formula='if(?f25 ,?f27 ,-1)'/>
785
+ <draw:equation draw:name='f27' draw:formula='if(?f0 ,-1,?f28 )'/>
786
+ <draw:equation draw:name='f28' draw:formula='?f21 -?f20 '/>
787
+ <draw:equation draw:name='f29' draw:formula='if(?f25 ,?f30 ,-1)'/>
788
+ <draw:equation draw:name='f30' draw:formula='if(?f0 ,?f28 ,-1)'/>
789
+ <draw:equation draw:name='f31' draw:formula='$0 -21600'/>
790
+ <draw:equation draw:name='f32' draw:formula='if(?f31 ,?f33 ,-1)'/>
791
+ <draw:equation draw:name='f33' draw:formula='if(?f1 ,?f22 ,-1)'/>
792
+ <draw:equation draw:name='f34' draw:formula='if(?f31 ,?f35 ,-1)'/>
793
+ <draw:equation draw:name='f35' draw:formula='if(?f1 ,-1,?f22 )'/>
794
+ <draw:equation draw:name='f36' draw:formula='if($1 ,-1,?f37 )'/>
795
+ <draw:equation draw:name='f37' draw:formula='if(?f0 ,?f28 ,-1)'/>
796
+ <draw:equation draw:name='f38' draw:formula='if($1 ,-1,?f39 )'/>
797
+ <draw:equation draw:name='f39' draw:formula='if(?f0 ,-1,?f28 )'/>
798
+ <draw:equation draw:name='f40' draw:formula='$0 '/>
799
+ <draw:equation draw:name='f41' draw:formula='$1 '/>
800
+ <draw:handle draw:handle-position='$0 $1'/>
801
+ </draw:enhanced-geometry>
802
+ </draw:custom-shape>
803
+ </draw:g>シェイプ付きのOpen Documentファイルです.</text:p>
804
+ EOF
805
+ result[2].should == <<EOF.chomp.to_sym
806
+ <text:p text:style-name='#{@name_prefix}Standard'/>
807
+ EOF
808
+ result.length.should == 3
809
+ result.class.should == Array
810
+ @visitor.automatic_styles[0].to_s.should == <<EOF.chomp
811
+ <style:style style:name='#{@name_prefix}P1' style:family='paragraph'>
812
+ <style:paragraph-properties fo:text-align='center'/>
813
+ </style:style>
814
+ EOF
815
+ @visitor.automatic_styles[1].to_s.should == <<EOF.chomp
816
+ <style:style style:name='#{@name_prefix}gr1' style:family='graphic'>
817
+ <style:graphic-properties style:flow-with-text='false' style:horizontal-pos='from-left' style:wrap='none' style:vertical-rel='paragraph' draw:wrap-influence-on-position='once-concurrent' style:horizontal-rel='paragraph' style:run-through='foreground' style:vertical-pos='from-top'/>
818
+ </style:style>
819
+ EOF
820
+ @visitor.automatic_styles[2].to_s.should == <<EOF.chomp
821
+ <style:style style:name='#{@name_prefix}gr2' style:family='graphic'>
822
+ <style:graphic-properties draw:textarea-vertical-align='middle' draw:auto-grow-height='false' style:run-through='foreground' draw:textarea-horizontal-align='justify'/>
823
+ </style:style>
824
+ EOF
825
+ # automatic_styles[3] test is omitted.
826
+ @visitor.automatic_styles.length.should == 4
827
+ @visitor.automatic_styles.class.should == Array
828
+ end
829
+ end