rd2odt 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/FUTURE +63 -0
- data/LICENSE +21 -0
- data/NEWS +42 -0
- data/README +78 -0
- data/Rakefile +51 -0
- data/bin/rd2odt +4 -0
- data/doc/sample/body-text.rd +5 -0
- data/doc/sample/enum-list-over-headline-multi-level.rd +10 -0
- data/doc/sample/enum-list-over-headline.rd +9 -0
- data/doc/sample/enum-list-over-item-list-multi-level-2.rd +9 -0
- data/doc/sample/enum-list-over-item-list-multi-level.rd +8 -0
- data/doc/sample/enum-list-over-item-list.rd +7 -0
- data/doc/sample/headline.rd +60 -0
- data/doc/sample/include-file-figure.odt +0 -0
- data/doc/sample/include-file-ole-object.odt +0 -0
- data/doc/sample/include-file-original-styled-text.odt +0 -0
- data/doc/sample/include-file-shape.odt +0 -0
- data/doc/sample/include-file-simple-styled-text.odt +0 -0
- data/doc/sample/include-file-simple-text.odt +0 -0
- data/doc/sample/include-file-table.odt +0 -0
- data/doc/sample/include.rd +21 -0
- data/doc/sample/list.rd +22 -0
- data/doc/sample/multi-paragraph.rd +12 -0
- data/doc/sample/page-break.odt +0 -0
- data/doc/sample/verbatim.rd +8 -0
- data/doc/sample.rd.ja +75 -0
- data/doc/sample.rd.ja.ott +0 -0
- data/doc/sample.rd.ja.pdf +0 -0
- data/doc/specification.ja.rd +35 -0
- data/lib/rd2odt/rdtool/NOTICE.rd2odt +8 -0
- data/lib/rd2odt/rdtool/README.rd +50 -0
- data/lib/rd2odt/rdtool/README.rd.ja +53 -0
- data/lib/rd2odt/rdtool/rd/block-element.rb +114 -0
- data/lib/rd2odt/rdtool/rd/complex-list-item.rb +65 -0
- data/lib/rd2odt/rdtool/rd/desclist.rb +55 -0
- data/lib/rd2odt/rdtool/rd/document-struct.rb +46 -0
- data/lib/rd2odt/rdtool/rd/element.rb +160 -0
- data/lib/rd2odt/rdtool/rd/filter.rb +255 -0
- data/lib/rd2odt/rdtool/rd/inline-element.rb +233 -0
- data/lib/rd2odt/rdtool/rd/labeled-element.rb +14 -0
- data/lib/rd2odt/rdtool/rd/list.rb +57 -0
- data/lib/rd2odt/rdtool/rd/loose-struct.rb +11 -0
- data/lib/rd2odt/rdtool/rd/methodlist.rb +57 -0
- data/lib/rd2odt/rdtool/rd/output-format-visitor.rb +28 -0
- data/lib/rd2odt/rdtool/rd/package.rb +4 -0
- data/lib/rd2odt/rdtool/rd/parser-util.rb +14 -0
- data/lib/rd2odt/rdtool/rd/rbl-file.rb +69 -0
- data/lib/rd2odt/rdtool/rd/rbl-suite.rb +37 -0
- data/lib/rd2odt/rdtool/rd/rd-struct.rb +86 -0
- data/lib/rd2odt/rdtool/rd/rd2html-lib.rb +490 -0
- data/lib/rd2odt/rdtool/rd/rd2html-opt.rb +67 -0
- data/lib/rd2odt/rdtool/rd/rd2man-lib.rb +241 -0
- data/lib/rd2odt/rdtool/rd/rd2rdo-lib.rb +19 -0
- data/lib/rd2odt/rdtool/rd/rd2rmi-lib.rb +32 -0
- data/lib/rd2odt/rdtool/rd/rdblockparser.tab.rb +1050 -0
- data/lib/rd2odt/rdtool/rd/rdfmt.rb +15 -0
- data/lib/rd2odt/rdtool/rd/rdinlineparser.tab.rb +1243 -0
- data/lib/rd2odt/rdtool/rd/rdvisitor.rb +214 -0
- data/lib/rd2odt/rdtool/rd/reference-resolver.rb +114 -0
- data/lib/rd2odt/rdtool/rd/search-file.rb +14 -0
- data/lib/rd2odt/rdtool/rd/tree.rb +103 -0
- data/lib/rd2odt/rdtool/rd/version.rb +39 -0
- data/lib/rd2odt/rdtool/rd/visitor.rb +86 -0
- data/lib/rd2odt.rb +603 -0
- data/rd2odt.gemspec +108 -0
- data/setup.rb +1585 -0
- data/test/functional/rd2odt-spec.rb +733 -0
- data/test/test-helper.rb +93 -0
- data/test/unit/rd2odt-spec.rb +831 -0
- metadata +122 -0
data/test/test-helper.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
$top_srcdir = File.join(File.dirname(__FILE__), "..")
|
4
|
+
$LOAD_PATH << File.join($top_srcdir, "lib")
|
5
|
+
|
6
|
+
$KCODE = "u" if RUBY_VERSION < "1.9.0"
|
7
|
+
|
8
|
+
require "rd2odt"
|
9
|
+
require "tempfile"
|
10
|
+
|
11
|
+
module XmlMatchers
|
12
|
+
class BeSameAsThisXml
|
13
|
+
def initialize(expected)
|
14
|
+
@expected = expected
|
15
|
+
if String === expected || Symbol === expected
|
16
|
+
@expected_dom = to_dom(expected.to_s)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def matches?(actual)
|
21
|
+
@actual = actual
|
22
|
+
if String === actual || Symbol === actual
|
23
|
+
@actual_dom = to_dom(actual.to_s)
|
24
|
+
end
|
25
|
+
return expected_dom.to_s == actual_dom.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
def failure_message
|
29
|
+
return "difference: #{diff}"
|
30
|
+
end
|
31
|
+
|
32
|
+
alias negative_failure_message failure_message
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
DOM_PREFIX = <<EOF
|
37
|
+
<?xml version='1.0' encoding='UTF-8'?>
|
38
|
+
|
39
|
+
<office:document-content xmlns:script='urn:oasis:names:tc:opendocument:xmlns:script:1.0' xmlns:oooc='http://openoffice.org/2004/calc' xmlns:number='urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0' xmlns:dr3d='urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0' xmlns:math='http://www.w3.org/1998/Math/MathML' xmlns:dom='http://www.w3.org/2001/xml-events' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:text='urn:oasis:names:tc:opendocument:xmlns:text:1.0' xmlns:svg='urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0' xmlns:ooo='http://openoffice.org/2004/office' xmlns:xforms='http://www.w3.org/2002/xforms' xmlns:table='urn:oasis:names:tc:opendocument:xmlns:table:1.0' xmlns:meta='urn:oasis:names:tc:opendocument:xmlns:meta:1.0' xmlns:form='urn:oasis:names:tc:opendocument:xmlns:form:1.0' xmlns:field='urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:field:1.0' xmlns:draw='urn:oasis:names:tc:opendocument:xmlns:drawing:1.0' office:version='1.1' xmlns:office='urn:oasis:names:tc:opendocument:xmlns:office:1.0' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:fo='urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:style='urn:oasis:names:tc:opendocument:xmlns:style:1.0' xmlns:ooow='http://openoffice.org/2004/writer' xmlns:chart='urn:oasis:names:tc:opendocument:xmlns:chart:1.0'>
|
40
|
+
|
41
|
+
|
42
|
+
EOF
|
43
|
+
|
44
|
+
DOM_SUFFIX = <<EOF
|
45
|
+
|
46
|
+
|
47
|
+
</office:document-content>
|
48
|
+
EOF
|
49
|
+
|
50
|
+
def expected_dom
|
51
|
+
return (@expected_dom ||= to_dom(RD2ODT.ah_to_xml(@expected)))
|
52
|
+
end
|
53
|
+
|
54
|
+
def actual_dom
|
55
|
+
return (@actual_dom ||= to_dom(RD2ODT.ah_to_xml(@expected)))
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_dom(s)
|
59
|
+
root = REXML::Document.new(DOM_PREFIX + s + DOM_SUFFIX)
|
60
|
+
result = root[2][1] # `result' is only XML from `s'.
|
61
|
+
return result
|
62
|
+
end
|
63
|
+
|
64
|
+
def diff
|
65
|
+
Tempfile.open("rd2odt-test") do |expected_file|
|
66
|
+
Tempfile.open("rd2odt-test") do |actual_file|
|
67
|
+
expected_file.puts(expected_dom.to_s)
|
68
|
+
expected_file.close
|
69
|
+
actual_file.puts(actual_dom.to_s)
|
70
|
+
actual_file.close
|
71
|
+
|
72
|
+
result = `docdiff --utf8 --char --tty #{expected_file.path} #{actual_file.path}`
|
73
|
+
return result
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def be_same_as_this_xml(expected)
|
80
|
+
return BeSameAsThisXml.new(expected)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# for test on Ruby 1.8.6.
|
85
|
+
if RUBY_VERSION < "1.8.7"
|
86
|
+
class Hash
|
87
|
+
def each
|
88
|
+
keys.sort.each do |k|
|
89
|
+
yield(k, self[k])
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|