xmlcodec 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +2 -2
- data/Rakefile +3 -5
- data/test/partial_export_test.rb +92 -112
- data/test/test_helper.rb +20 -2
- data/test/utils_test.rb +6 -6
- metadata +63 -40
data/README
CHANGED
data/Rakefile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
PKG_NAME = 'xmlcodec'
|
2
|
-
PKG_VERSION = '0.1.
|
2
|
+
PKG_VERSION = '0.1.2'
|
3
3
|
|
4
4
|
require 'rake'
|
5
5
|
require 'rake/testtask'
|
@@ -25,13 +25,13 @@ RDOC_EXTRA_FILES = ['README']
|
|
25
25
|
spec = Gem::Specification.new do |s|
|
26
26
|
s.platform = Gem::Platform::RUBY
|
27
27
|
s.summary = "Generic Importer/Exporter of XML formats"
|
28
|
+
s.homepage = "http://github.com/pedrocr/xmlcodec"
|
28
29
|
s.name = PKG_NAME
|
29
30
|
s.version = PKG_VERSION
|
30
31
|
s.author = 'Pedro Côrte-Real'
|
31
|
-
s.email = 'pedrocr
|
32
|
+
s.email = 'pedro@pedrocr.net'
|
32
33
|
s.requirements << 'none'
|
33
34
|
s.require_path = 'lib'
|
34
|
-
s.autorequire = 'rake'
|
35
35
|
s.files = PKG_FILES
|
36
36
|
s.has_rdoc = true
|
37
37
|
s.rdoc_options = RDOC_OPTIONS
|
@@ -42,8 +42,6 @@ EOF
|
|
42
42
|
end
|
43
43
|
|
44
44
|
Rake::GemPackageTask.new(spec) do |pkg|
|
45
|
-
pkg.need_zip = true
|
46
|
-
pkg.need_tar = true
|
47
45
|
end
|
48
46
|
|
49
47
|
Rake::TestTask.new do |t|
|
data/test/partial_export_test.rb
CHANGED
@@ -1,107 +1,92 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper'
|
2
2
|
|
3
3
|
class TestPartialExport < Test::Unit::TestCase
|
4
|
-
def validate_well_formed(filename)
|
5
|
-
assert(system("rxp", "-xs", filename))
|
6
|
-
end
|
7
|
-
|
8
|
-
def compare_xpath(value, filename, path)
|
9
|
-
assert_equal(value.strip, XMLUtils::select_path(path, filename).strip)
|
10
|
-
end
|
11
|
-
|
12
4
|
def test_simple
|
13
|
-
@filename = 'test_partial_export_simple.xml'
|
14
5
|
value = "somevalue"
|
15
6
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
validate_well_formed
|
22
|
-
compare_xpath(value,
|
7
|
+
with_temp_file do |file|
|
8
|
+
sel = SimpleElement.new(value)
|
9
|
+
sel.partial_export(file)
|
10
|
+
end
|
11
|
+
|
12
|
+
validate_well_formed
|
13
|
+
compare_xpath(value, "/abc")
|
23
14
|
end
|
24
15
|
|
25
16
|
def test_double
|
26
17
|
value = 'somevalue'
|
27
|
-
@filename = 'test_partial_export_double.xml'
|
28
18
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
validate_well_formed
|
39
|
-
compare_xpath(value,
|
19
|
+
with_temp_file do |file|
|
20
|
+
sel = SimpleElement.new(value)
|
21
|
+
el = TestElement.new
|
22
|
+
el.abc = sel
|
23
|
+
|
24
|
+
sel.partial_export(file)
|
25
|
+
el.end_partial_export(file)
|
26
|
+
end
|
27
|
+
|
28
|
+
validate_well_formed
|
29
|
+
compare_xpath(value, "/subel/abc")
|
40
30
|
end
|
41
31
|
|
42
32
|
def test_triple
|
43
33
|
value = 'somevalue'
|
44
|
-
@filename = 'test_partial_export_double.xml'
|
45
|
-
|
46
|
-
file = File.open(filepath, "w")
|
47
|
-
sel = SimpleElement.new(value)
|
48
|
-
el1 = TestElement.new
|
49
|
-
el2 = TestElement.new
|
50
|
-
el1.subel = el2
|
51
|
-
el2.abc = sel
|
52
34
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
35
|
+
with_temp_file do |file|
|
36
|
+
sel = SimpleElement.new(value)
|
37
|
+
el1 = TestElement.new
|
38
|
+
el2 = TestElement.new
|
39
|
+
el1.subel = el2
|
40
|
+
el2.abc = sel
|
41
|
+
|
42
|
+
sel.partial_export(file)
|
43
|
+
el1.end_partial_export(file)
|
44
|
+
end
|
45
|
+
|
46
|
+
validate_well_formed
|
47
|
+
compare_xpath(value, "/subel/subel/abc")
|
59
48
|
end
|
60
49
|
|
61
50
|
def test_attr
|
62
51
|
value = 'somevalue'
|
63
|
-
@filename = 'test_partial_export_double.xml'
|
64
|
-
|
65
|
-
file = File.open(filepath, "w")
|
66
|
-
el = TestElement.new
|
67
|
-
el.someattr = value
|
68
52
|
|
69
|
-
|
70
|
-
|
53
|
+
with_temp_file do |file|
|
54
|
+
el = TestElement.new
|
55
|
+
el.someattr = value
|
56
|
+
|
57
|
+
el.partial_export(file)
|
58
|
+
end
|
71
59
|
|
72
|
-
compare_xpath(value,
|
60
|
+
compare_xpath(value, "/subel/@someattr")
|
73
61
|
end
|
74
62
|
|
75
63
|
def test_mult
|
76
64
|
value1 = 'somevalue1'
|
77
65
|
value2 = 'somevalue2'
|
78
|
-
@filename = 'test_partial_export_mult.xml'
|
79
|
-
|
80
|
-
file = File.open(filepath, "w")
|
81
|
-
sel1 = SimpleElement.new(value1)
|
82
|
-
sel2 = SimpleElement.new(value2)
|
83
|
-
|
84
|
-
el = SubelMultElement.new
|
85
|
-
el.abc << sel1
|
86
|
-
sel1.partial_export(file)
|
87
|
-
|
88
|
-
el.abc << sel2
|
89
|
-
sel2.partial_export(file)
|
90
|
-
el.end_partial_export(file)
|
91
|
-
|
92
|
-
file.close
|
93
66
|
|
94
|
-
|
95
|
-
|
96
|
-
|
67
|
+
with_temp_file do |file|
|
68
|
+
sel1 = SimpleElement.new(value1)
|
69
|
+
sel2 = SimpleElement.new(value2)
|
70
|
+
|
71
|
+
el = SubelMultElement.new
|
72
|
+
el.abc << sel1
|
73
|
+
sel1.partial_export(file)
|
74
|
+
|
75
|
+
el.abc << sel2
|
76
|
+
sel2.partial_export(file)
|
77
|
+
el.end_partial_export(file)
|
78
|
+
end
|
79
|
+
|
80
|
+
validate_well_formed
|
81
|
+
compare_xpath(value1, "/mult/abc[1]")
|
82
|
+
compare_xpath(value2, "/mult/abc[2]")
|
97
83
|
end
|
98
84
|
|
99
85
|
def test_subelements
|
100
86
|
value1 = 'somevalue1'
|
101
87
|
value2 = 'somevalue2'
|
102
|
-
@filename = 'test_partial_export_subelements.xml'
|
103
88
|
|
104
|
-
|
89
|
+
with_temp_file do |file|
|
105
90
|
sel1 = SimpleElement.new(value1)
|
106
91
|
sel2 = SimpleElement.new(value2)
|
107
92
|
|
@@ -113,58 +98,53 @@ class TestPartialExport < Test::Unit::TestCase
|
|
113
98
|
sel2.partial_export(file)
|
114
99
|
el.end_partial_export(file)
|
115
100
|
|
116
|
-
|
101
|
+
end
|
117
102
|
|
118
|
-
validate_well_formed
|
119
|
-
compare_xpath(value1,
|
120
|
-
compare_xpath(value2,
|
103
|
+
validate_well_formed
|
104
|
+
compare_xpath(value1, "/subels/abc[1]")
|
105
|
+
compare_xpath(value2, "/subels/abc[2]")
|
121
106
|
end
|
122
107
|
|
123
108
|
def test_subelements_multiple
|
124
109
|
value1 = 'somevalue1'
|
125
110
|
value2 = 'somevalue2'
|
126
|
-
@filename = 'test_partial_export_subelements2.xml'
|
127
|
-
|
128
|
-
file = File.open(filepath, "w")
|
129
|
-
sel1 = SimpleElement.new(value1)
|
130
|
-
sel2 = SimpleElement.new(value2)
|
131
|
-
|
132
|
-
el = SubelElement.new
|
133
|
-
el.subelements << sel1
|
134
|
-
el.subelements << sel2
|
135
|
-
el.partial_export(file)
|
136
|
-
|
137
|
-
file.close
|
138
111
|
|
139
|
-
|
140
|
-
|
141
|
-
|
112
|
+
with_temp_file do |file|
|
113
|
+
sel1 = SimpleElement.new(value1)
|
114
|
+
sel2 = SimpleElement.new(value2)
|
115
|
+
|
116
|
+
el = SubelElement.new
|
117
|
+
el.subelements << sel1
|
118
|
+
el.subelements << sel2
|
119
|
+
el.partial_export(file)
|
120
|
+
end
|
121
|
+
|
122
|
+
validate_well_formed
|
123
|
+
compare_xpath(value1, "/subels/abc[1]")
|
124
|
+
compare_xpath(value2, "/subels/abc[2]")
|
142
125
|
end
|
143
126
|
|
144
127
|
def test_recursive
|
145
|
-
@filename = 'test_partial_export_recursive.xml'
|
146
|
-
file = File.open(filepath, "w")
|
147
|
-
|
148
128
|
value = 'somevalue'
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
validate_well_formed
|
129
|
+
|
130
|
+
with_temp_file do |file|
|
131
|
+
rec1 = Recursive.new
|
132
|
+
rec1.start_partial_export(file)
|
133
|
+
|
134
|
+
rec2 = Recursive.new
|
135
|
+
rec1.recursive << rec2
|
136
|
+
rec2.start_partial_export(file)
|
137
|
+
|
138
|
+
rec3 = Recursive.new
|
139
|
+
rec2.recursive << rec3
|
140
|
+
rec3.start_partial_export(file)
|
141
|
+
|
142
|
+
sel = SimpleElement.new(value)
|
143
|
+
sel.start_partial_export(file)
|
144
|
+
rec3.abc = sel
|
145
|
+
|
146
|
+
rec1.end_partial_export(file)
|
147
|
+
end
|
148
|
+
validate_well_formed
|
169
149
|
end
|
170
150
|
end
|
data/test/test_helper.rb
CHANGED
@@ -5,7 +5,25 @@ require File.dirname(__FILE__) + '/simple_objects'
|
|
5
5
|
|
6
6
|
|
7
7
|
class Test::Unit::TestCase
|
8
|
-
def
|
9
|
-
|
8
|
+
def with_temp_file
|
9
|
+
callname = Regexp.new("`(.*?)'").match(caller[0])[1]
|
10
|
+
@temp_path = File.join(Dir::tmpdir, callname+".xml")
|
11
|
+
File.open(@temp_path, "w") do |file|
|
12
|
+
yield file
|
13
|
+
end
|
10
14
|
end
|
15
|
+
|
16
|
+
def validate_well_formed
|
17
|
+
filename = filename || @temp_path
|
18
|
+
assert(system("xmllint --version > /dev/null 2>&1"),
|
19
|
+
"xmllint utility not installed"+
|
20
|
+
"(on ubuntu/debian install package libxml2-utils)")
|
21
|
+
assert(system("xmllint #{filename} >/dev/null"),
|
22
|
+
"Validation failed for #{filename}")
|
23
|
+
end
|
24
|
+
|
25
|
+
def compare_xpath(value, path)
|
26
|
+
filename = filename || @temp_path
|
27
|
+
assert_equal(value.strip, XMLUtils::select_path(path, filename).strip)
|
28
|
+
end
|
11
29
|
end
|
data/test/utils_test.rb
CHANGED
@@ -16,29 +16,29 @@ class TestXMLUtils < Test::Unit::TestCase
|
|
16
16
|
|
17
17
|
def test_get_xpath
|
18
18
|
opts = {}
|
19
|
-
assert_xpath_equal('abc', '//xpto', '<xpto>abc
|
19
|
+
assert_xpath_equal('abc', '//xpto', '<xpto>abc</xpto>')
|
20
20
|
|
21
|
-
assert_xpath_equal('abc', '//xpto', '<xpto>abc<xpto2>foo</xpto2
|
21
|
+
assert_xpath_equal('abc', '//xpto', '<xpto>abc<xpto2>foo</xpto2></xpto>')
|
22
22
|
|
23
23
|
opts[:with_attrs] = true
|
24
24
|
opts[:recursive] = false
|
25
25
|
opts[:multiple] = false
|
26
|
-
assert_xpath_equal('attr1 abc', '//xpto', '<xpto attr1="attr1">abc<xpto2>foo</xpto2
|
26
|
+
assert_xpath_equal('attr1 abc', '//xpto', '<xpto attr1="attr1">abc<xpto2>foo</xpto2></xpto>', opts)
|
27
27
|
|
28
28
|
opts[:with_attrs] = false
|
29
29
|
opts[:recursive] = true
|
30
30
|
opts[:multiple] = false
|
31
|
-
assert_xpath_equal('abc foo', '//xpto', '<xpto>abc<xpto2 attr1="attr1">foo</xpto2
|
31
|
+
assert_xpath_equal('abc foo', '//xpto', '<xpto>abc<xpto2 attr1="attr1">foo</xpto2></xpto>', opts)
|
32
32
|
|
33
33
|
opts[:with_attrs] = true
|
34
34
|
opts[:recursive] = true
|
35
35
|
opts[:multiple] = false
|
36
|
-
assert_xpath_equal('abc attr1 foo', '//xpto', '<xpto>abc<xpto2 attr1="attr1">foo</xpto2
|
36
|
+
assert_xpath_equal('abc attr1 foo', '//xpto', '<xpto>abc<xpto2 attr1="attr1">foo</xpto2></xpto>', opts)
|
37
37
|
|
38
38
|
opts[:with_attrs] = false
|
39
39
|
opts[:recursive] = false
|
40
40
|
opts[:multiple] = true
|
41
|
-
assert_xpath_equal('abc foo', '//xpto', '<xpto>abc<xpto attr1="attr1">foo</xpto
|
41
|
+
assert_xpath_equal('abc foo', '//xpto', '<xpto>abc<xpto attr1="attr1">foo</xpto></xpto>', opts)
|
42
42
|
end
|
43
43
|
|
44
44
|
def assert_xpath_equal(result, path, xml, opts={})
|
metadata
CHANGED
@@ -1,65 +1,88 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.0
|
3
|
-
specification_version: 1
|
4
2
|
name: xmlcodec
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
-
|
11
|
-
|
12
|
-
|
13
|
-
rubyforge_project:
|
14
|
-
description: A library that eases the creation of XML importers and exporters for ruby.
|
15
|
-
autorequire: rake
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
hash: 31
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
25
11
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
12
|
authors:
|
30
13
|
- "Pedro C\xC3\xB4rte-Real"
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-09-14 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: |
|
23
|
+
A library that eases the creation of XML importers and exporters for ruby.
|
24
|
+
|
25
|
+
email: pedro@pedrocr.net
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- README
|
31
32
|
files:
|
32
|
-
- test/
|
33
|
+
- test/partial_export_test.rb
|
34
|
+
- test/subelements_test.rb
|
33
35
|
- test/utils_test.rb
|
36
|
+
- test/test_helper.rb
|
37
|
+
- test/multi_format_test.rb
|
34
38
|
- test/stream_parser_test.rb
|
35
39
|
- test/element_test.rb
|
36
|
-
- test/partial_export_test.rb
|
37
40
|
- test/simple_objects.rb
|
38
41
|
- test/stream_object_parser_test.rb
|
39
|
-
- test/test_helper.rb
|
40
|
-
- test/subelements_test.rb
|
41
|
-
- lib/stream_parser.rb
|
42
|
-
- lib/XMLUtils.rb
|
43
|
-
- lib/subelements.rb
|
44
42
|
- lib/element.rb
|
45
|
-
- lib/
|
43
|
+
- lib/subelements.rb
|
44
|
+
- lib/XMLUtils.rb
|
46
45
|
- lib/xmlcodec.rb
|
46
|
+
- lib/stream_object_parser.rb
|
47
|
+
- lib/stream_parser.rb
|
47
48
|
- README
|
48
49
|
- LICENSE
|
49
50
|
- Rakefile
|
50
|
-
|
51
|
+
has_rdoc: true
|
52
|
+
homepage: http://github.com/pedrocr/xmlcodec
|
53
|
+
licenses: []
|
51
54
|
|
55
|
+
post_install_message:
|
52
56
|
rdoc_options:
|
53
57
|
- -S
|
54
58
|
- -w 2
|
55
59
|
- -N
|
56
|
-
|
57
|
-
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
hash: 3
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
version: "0"
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
62
80
|
requirements:
|
63
81
|
- none
|
64
|
-
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.3.7
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: Generic Importer/Exporter of XML formats
|
87
|
+
test_files: []
|
65
88
|
|