Empact-roxml 2.3.1 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -39,11 +39,11 @@ module ROXML
39
39
  class Parser
40
40
  class << self
41
41
  def parse(string)
42
- REXML::Document.new(string)
42
+ REXML::Document.new(string, :ignore_whitespace_nodes => :all)
43
43
  end
44
44
 
45
45
  def parse_file(path)
46
- REXML::Document.new(open(path), :ignore_whitespace_nodes => :all)
46
+ parse(open(path))
47
47
  end
48
48
 
49
49
  def register_error_handler(&block)
data/roxml.gemspec CHANGED
@@ -1,105 +1,44 @@
1
+ # -*- encoding: utf-8 -*-
2
+
1
3
  Gem::Specification.new do |s|
2
- s.name = "roxml"
3
- s.summary = "Ruby Object to XML mapping library"
4
- s.version = "2.3.1"
5
- s.homepage = "http://roxml.rubyforge.org"
6
- s.platform = Gem::Platform::RUBY
4
+ s.name = %q{roxml}
5
+ s.version = "2.4.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
7
8
  s.authors = ["Ben Woosley", "Zak Mandhro", "Anders Engstrom", "Russ Olsen"]
8
- s.email = "ben.woosley@gmail.com"
9
- s.rubyforge_project = 'roxml'
10
- s.files = [
11
- 'README.rdoc',
12
- 'MIT-LICENSE',
13
- 'Rakefile',
14
- 'roxml.gemspec',
15
- 'lib/roxml.rb',
16
- 'lib/roxml/extensions/active_support.rb',
17
- 'lib/roxml/extensions/array.rb',
18
- 'lib/roxml/extensions/array/conversions.rb',
19
- 'lib/roxml/extensions/string.rb',
20
- 'lib/roxml/extensions/string/conversions.rb',
21
- 'lib/roxml/extensions/string/iterators.rb',
22
- 'lib/roxml/extensions/deprecation.rb',
23
- 'lib/roxml/options.rb',
24
- 'lib/roxml/xml.rb',
25
- 'lib/roxml/xml/libxml.rb',
26
- 'lib/roxml/xml/rexml.rb',
27
- 'test/fixtures/book_malformed.xml',
28
- 'test/fixtures/book_pair.xml',
29
- 'test/fixtures/book_text_with_attribute.xml',
30
- 'test/fixtures/book_valid.xml',
31
- 'test/fixtures/book_with_authors.xml',
32
- 'test/fixtures/book_with_contributions.xml',
33
- 'test/fixtures/book_with_contributors_attrs.xml',
34
- 'test/fixtures/book_with_contributors.xml',
35
- 'test/fixtures/book_with_default_namespace.xml',
36
- 'test/fixtures/book_with_depth.xml',
37
- 'test/fixtures/book_with_publisher.xml',
38
- 'test/fixtures/book_with_wrapped_attr.xml',
39
- 'test/fixtures/dictionary_of_attrs.xml',
40
- 'test/fixtures/dictionary_of_attr_name_clashes.xml',
41
- 'test/fixtures/dictionary_of_guarded_names.xml',
42
- 'test/fixtures/dictionary_of_mixeds.xml',
43
- 'test/fixtures/dictionary_of_names.xml',
44
- 'test/fixtures/dictionary_of_name_clashes.xml',
45
- 'test/fixtures/dictionary_of_texts.xml',
46
- 'test/fixtures/library_uppercase.xml',
47
- 'test/fixtures/library.xml',
48
- 'test/fixtures/muffins.xml',
49
- 'test/fixtures/node_with_attr_name_conflicts.xml',
50
- 'test/fixtures/node_with_name_conflicts.xml',
51
- 'test/fixtures/nameless_ageless_youth.xml',
52
- 'test/fixtures/numerology.xml',
53
- 'test/fixtures/person_with_guarded_mothers.xml',
54
- 'test/fixtures/person_with_mothers.xml',
55
- 'test/fixtures/person.xml',
56
- 'test/mocks/mocks.rb',
57
- 'test/mocks/dictionaries.rb',
58
- 'test/release/dependencies_test.rb',
59
- 'test/test_helper.rb',
60
- 'test/unit/inheritance_test.rb',
61
- 'test/unit/options_test.rb',
62
- 'test/unit/roxml_test.rb',
63
- 'test/unit/string_test.rb',
64
- 'test/unit/to_xml_test.rb',
65
- 'test/unit/xml_attribute_test.rb',
66
- 'test/unit/xml_block_test.rb',
67
- 'test/unit/xml_bool_test.rb',
68
- 'test/unit/xml_construct_test.rb',
69
- 'test/unit/xml_hash_test.rb',
70
- 'test/unit/xml_initialize_test.rb',
71
- 'test/unit/xml_name_test.rb',
72
- 'test/unit/xml_namespace_test.rb',
73
- 'test/unit/xml_object_test.rb',
74
- 'test/unit/xml_required_test.rb',
75
- 'test/unit/xml_text_test.rb']
76
- s.requirements << 'none'
77
- s.add_dependency 'extensions', '>= 0.6.0'
78
- s.add_dependency 'activesupport', '>= 2.0.0'
79
- s.require_path = 'lib'
80
- s.test_files = [
81
- 'test/unit/inheritance_test.rb',
82
- 'test/unit/options_test.rb',
83
- 'test/unit/roxml_test.rb',
84
- 'test/unit/string_test.rb',
85
- 'test/unit/to_xml_test.rb',
86
- 'test/unit/xml_attribute_test.rb',
87
- 'test/unit/xml_block_test.rb',
88
- 'test/unit/xml_bool_test.rb',
89
- 'test/unit/xml_construct_test.rb',
90
- 'test/unit/xml_hash_test.rb',
91
- 'test/unit/xml_initialize_test.rb',
92
- 'test/unit/xml_name_test.rb',
93
- 'test/unit/xml_namespace_test.rb',
94
- 'test/unit/xml_object_test.rb',
95
- 'test/unit/xml_required_test.rb',
96
- 'test/unit/xml_text_test.rb']
9
+ s.date = %q{2009-01-15}
10
+ s.description = %q{ROXML is a Ruby library designed to make it easier for Ruby developers to work with XML. Using simple annotations, it enables Ruby classes to be mapped to XML. ROXML takes care of the marshalling and unmarshalling of mapped attributes so that developers can focus on building first-class Ruby classes. As a result, ROXML simplifies the development of RESTful applications, Web Services, and XML-RPC.}
11
+ s.email = %q{ben.woosley@gmail.com}
12
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
13
+ s.files = ["History.txt", "MIT-LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "TODO", "html/index.html", "html/style.css", "lib/roxml.rb", "lib/roxml/extensions/active_support.rb", "lib/roxml/extensions/array.rb", "lib/roxml/extensions/array/conversions.rb", "lib/roxml/extensions/deprecation.rb", "lib/roxml/extensions/string.rb", "lib/roxml/extensions/string/conversions.rb", "lib/roxml/extensions/string/iterators.rb", "lib/roxml/options.rb", "lib/roxml/xml.rb", "lib/roxml/xml/libxml.rb", "lib/roxml/xml/rexml.rb", "roxml.gemspec", "tasks/rspec.rake", "test/bugs/rexml_bugs.rb", "test/fixtures/book_malformed.xml", "test/fixtures/book_pair.xml", "test/fixtures/book_text_with_attribute.xml", "test/fixtures/book_valid.xml", "test/fixtures/book_with_authors.xml", "test/fixtures/book_with_contributions.xml", "test/fixtures/book_with_contributors.xml", "test/fixtures/book_with_contributors_attrs.xml", "test/fixtures/book_with_default_namespace.xml", "test/fixtures/book_with_depth.xml", "test/fixtures/book_with_octal_pages.xml", "test/fixtures/book_with_publisher.xml", "test/fixtures/book_with_wrapped_attr.xml", "test/fixtures/dictionary_of_attr_name_clashes.xml", "test/fixtures/dictionary_of_attrs.xml", "test/fixtures/dictionary_of_guarded_names.xml", "test/fixtures/dictionary_of_mixeds.xml", "test/fixtures/dictionary_of_name_clashes.xml", "test/fixtures/dictionary_of_names.xml", "test/fixtures/dictionary_of_texts.xml", "test/fixtures/library.xml", "test/fixtures/library_uppercase.xml", "test/fixtures/muffins.xml", "test/fixtures/nameless_ageless_youth.xml", "test/fixtures/node_with_attr_name_conflicts.xml", "test/fixtures/node_with_name_conflicts.xml", "test/fixtures/numerology.xml", "test/fixtures/person.xml", "test/fixtures/person_with_guarded_mothers.xml", "test/fixtures/person_with_mothers.xml", "test/mocks/dictionaries.rb", "test/mocks/mocks.rb", "test/release/dependencies_test.rb", "test/test_helper.rb", "test/unit/array_test.rb", "test/unit/freeze_test.rb", "test/unit/inheritance_test.rb", "test/unit/options_test.rb", "test/unit/overriden_output_test.rb", "test/unit/roxml_test.rb", "test/unit/string_test.rb", "test/unit/to_xml_test.rb", "test/unit/xml_attribute_test.rb", "test/unit/xml_block_test.rb", "test/unit/xml_bool_test.rb", "test/unit/xml_construct_test.rb", "test/unit/xml_convention_test.rb", "test/unit/xml_hash_test.rb", "test/unit/xml_initialize_test.rb", "test/unit/xml_name_test.rb", "test/unit/xml_namespace_test.rb", "test/unit/xml_object_test.rb", "test/unit/xml_required_test.rb", "test/unit/xml_text_test.rb"]
97
14
  s.has_rdoc = true
98
- s.description = <<EOF
99
- ROXML is a Ruby library designed to make it easier for Ruby developers to work with XML.
100
- Using simple annotations, it enables Ruby classes to be mapped to XML. ROXML takes care
101
- of the marshalling and unmarshalling of mapped attributes so that developers can focus on
102
- building first-class Ruby classes. As a result, ROXML simplifies the development of
103
- RESTful applications, Web Services, and XML-RPC.
104
- EOF
15
+ s.homepage = %q{http://roxml.rubyforge.org}
16
+ s.rdoc_options = ["--main", "README.rdoc"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{roxml}
19
+ s.rubygems_version = %q{1.3.1.xported}
20
+ s.summary = %q{Ruby Object to XML mapping library}
21
+ s.test_files = ["test/unit/freeze_test.rb", "test/unit/array_test.rb", "test/unit/xml_convention_test.rb", "test/unit/xml_object_test.rb", "test/unit/xml_required_test.rb", "test/unit/xml_bool_test.rb", "test/unit/roxml_test.rb", "test/unit/xml_name_test.rb", "test/unit/xml_construct_test.rb", "test/unit/options_test.rb", "test/unit/string_test.rb", "test/unit/xml_namespace_test.rb", "test/unit/xml_text_test.rb", "test/unit/overriden_output_test.rb", "test/unit/xml_block_test.rb", "test/unit/xml_attribute_test.rb", "test/unit/inheritance_test.rb", "test/unit/xml_initialize_test.rb", "test/unit/xml_hash_test.rb", "test/unit/to_xml_test.rb"]
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 2
26
+
27
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ s.add_runtime_dependency(%q<activesupport>, [">= 2.1.0"])
29
+ s.add_runtime_dependency(%q<extensions>, [">= 0.6.0"])
30
+ s.add_development_dependency(%q<newgem>, [">= 1.2.3"])
31
+ s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
32
+ else
33
+ s.add_dependency(%q<activesupport>, [">= 2.1.0"])
34
+ s.add_dependency(%q<extensions>, [">= 0.6.0"])
35
+ s.add_dependency(%q<newgem>, [">= 1.2.3"])
36
+ s.add_dependency(%q<hoe>, [">= 1.8.0"])
37
+ end
38
+ else
39
+ s.add_dependency(%q<activesupport>, [">= 2.1.0"])
40
+ s.add_dependency(%q<extensions>, [">= 0.6.0"])
41
+ s.add_dependency(%q<newgem>, [">= 1.2.3"])
42
+ s.add_dependency(%q<hoe>, [">= 1.8.0"])
43
+ end
105
44
  end
@@ -0,0 +1,15 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class RexmlBugs < Test::Unit::TestCase
4
+ def test_that_some_illegal_chars_are_parsed_without_complaint
5
+ p "REXML ignores illegal ']]>' brackets in xml content"
6
+ assert_nothing_raised do
7
+ # The right angle bracket (>) may be represented using the string "&gt;", and MUST, for compatibility,
8
+ # be escaped using either "&gt;" or a character reference when it appears in the string "]]>" in content,
9
+ # when that string is not marking the end of a CDATA section.
10
+ # - http://www.w3.org/TR/xml11/#syntax
11
+ xml = "<title>The Big Book of ]]> everything more</title>"
12
+ assert_equal xml, REXML::Document.new(xml).to_s
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ <bookwithoctalpages>
2
+ <pages_with_to_xml_proc>0357</pages_with_to_xml_proc>
3
+ <pages_with_type>0357</pages_with_type>
4
+ </bookwithoctalpages>
data/test/mocks/mocks.rb CHANGED
@@ -105,10 +105,6 @@ class BookWithDepth
105
105
  xml_reader :depth, Measurement
106
106
  end
107
107
 
108
- class InheritedBookWithDepth < Book
109
- xml_reader :depth, Measurement
110
- end
111
-
112
108
  class Author
113
109
  include ROXML
114
110
 
data/test/test_helper.rb CHANGED
@@ -12,4 +12,33 @@ end
12
12
 
13
13
  def fixture_path(name)
14
14
  "test/fixtures/#{name}.xml"
15
+ end
16
+
17
+ def to_xml_test(*names)
18
+ names = names.only if names.one? && names.only.is_a?(Hash)
19
+ names.each do |name, xml_name|
20
+ xml_name ||= name
21
+
22
+ define_method "test_#{name}" do
23
+ klass = name.is_a?(Symbol) ? name.to_s.camelize.constantize : name
24
+ xml = xml_name.is_a?(Symbol) ? xml_fixture(xml_name) : xml_name
25
+
26
+ dict = klass.from_xml(xml)
27
+ xml = remove_children(xml)
28
+ assert_equal xml, dict.to_xml
29
+ end
30
+ end
31
+ end
32
+
33
+ def remove_children(xml)
34
+ xml = ROXML::XML::Parser.parse(xml).root if xml.is_a?(String)
35
+ return unless xml.respond_to? :children
36
+ xml.children.each do |child|
37
+ if child.to_s.blank?
38
+ child.remove!
39
+ else
40
+ remove_children(child)
41
+ end
42
+ end
43
+ xml
15
44
  end
@@ -0,0 +1,16 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class TestXmlArray < Test::Unit::TestCase
4
+ def test_as_array_with_auto_guard
5
+ result = BookWithContributors.from_xml(%{
6
+ <book isbn="0974514055">
7
+ <contributors>
8
+ <contributor role="author"><name>David Thomas</name></contributor>
9
+ <contributor role="supporting author"><name>Andrew Hunt</name></contributor>
10
+ <contributor role="supporting author"><name>Chad Fowler</name></contributor>
11
+ </contributors>
12
+ </book>
13
+ }).contributors.map(&:name).sort
14
+ assert_equal ["David Thomas","Andrew Hunt","Chad Fowler"].sort, result
15
+ end
16
+ end
@@ -0,0 +1,71 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class DescriptionReadonly
4
+ include ROXML
5
+
6
+ xml_reader :writable, :content
7
+ xml_reader :readonly, :content, :frozen => true
8
+ end
9
+
10
+ class BookWithContributionsReadonly
11
+ include ROXML
12
+
13
+ xml_name :book
14
+ xml_reader :isbn, :attr, :frozen => true
15
+ xml_reader :title, :frozen => true
16
+ xml_reader :description, DescriptionReadonly, :frozen => true
17
+ xml_reader :contributions, [Contributor], :from => 'contributor', :in => "contributions", :frozen => true
18
+ end
19
+
20
+ class DictionaryOfGuardedNamesReadonly
21
+ include ROXML
22
+
23
+ xml_name :dictionary
24
+ xml_reader :definitions, {:key => :name,
25
+ :value => :content}, :in => :definitions, :frozen => true
26
+ end
27
+
28
+ class TestFreeze < Test::Unit::TestCase
29
+ def setup
30
+ @writable = BookWithContributions.from_xml(fixture(:book_with_contributions))
31
+ @readonly = BookWithContributionsReadonly.from_xml(fixture(:book_with_contributions))
32
+ @dict_readonly = DictionaryOfGuardedNamesReadonly.from_xml(fixture(:dictionary_of_guarded_names))
33
+ end
34
+
35
+ def test_attr_is_unmodifiable
36
+ assert !@writable.isbn.frozen?
37
+ assert @readonly.isbn.frozen?
38
+ end
39
+
40
+ def test_text_is_unmodifiable
41
+ assert !@writable.title.frozen?
42
+ assert @readonly.title.frozen?
43
+ end
44
+
45
+ def test_objects_are_unmodifiable
46
+ assert @readonly.description.frozen?
47
+ end
48
+
49
+ def test_indirect_attrs_can_be_frozen_or_not
50
+ assert @readonly.description.readonly.frozen?
51
+ assert !@readonly.description.writable.frozen?
52
+ end
53
+
54
+ def test_arrays_are_unmodifiable
55
+ assert !@writable.contributions.frozen?
56
+ assert @readonly.contributions.frozen?
57
+ end
58
+
59
+ def test_array_elements_are_unmodifiable
60
+ assert @readonly.contributions.all?(&:frozen?)
61
+ end
62
+
63
+ def test_hashes_are_unmodifiable
64
+ assert @dict_readonly.definitions.frozen?
65
+ end
66
+
67
+ def test_hash_keys_and_values_are_unmodifiable
68
+ assert @dict_readonly.definitions.keys.all?(&:frozen?)
69
+ assert @dict_readonly.definitions.values.all?(&:frozen?)
70
+ end
71
+ end
@@ -1,11 +1,25 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
2
 
3
+ class InheritedBookWithDepth < Book
4
+ xml_reader :depth, Measurement
5
+ end
6
+
3
7
  class TestInheritance < Test::Unit::TestCase
4
8
  def setup
5
- @b = InheritedBookWithDepth.from_xml(fixture(:book_with_depth))
9
+ @book_xml = %{
10
+ <book ISBN="0201710897">
11
+ <title>The PickAxe</title>
12
+ <description><![CDATA[Probably the best Ruby book out there]]></description>
13
+ <author>David Thomas, Andrew Hunt, Dave Thomas</author>
14
+ <depth units="hundredths-meters">1130</depth>
15
+ <publisher>Pragmattic Programmers</publisher>
16
+ </book>
17
+ }
18
+
19
+ @b = InheritedBookWithDepth.from_xml(@book_xml)
6
20
  end
7
21
 
8
- def test_inherited_object_should_include_parents_attributes
22
+ def test_it_should_include_parents_attributes
9
23
  assert_equal '0201710897', @b.isbn
10
24
  assert_equal 'The PickAxe', @b.title
11
25
  assert_equal 'Probably the best Ruby book out there', @b.description
@@ -13,7 +27,16 @@ class TestInheritance < Test::Unit::TestCase
13
27
  assert_equal 0, @b.pages
14
28
  end
15
29
 
16
- def test_inherited_object_should_include_its_own_attributes
30
+ def test_it_should_include_its_own_attributes
17
31
  assert_equal '11.3 meters', @b.depth.to_s
18
32
  end
33
+
34
+ def test_it_should_include_parent_attributes_added_after_the_childs_definition
35
+ Book.class_eval do
36
+ xml_reader :publisher, :require => true
37
+ end
38
+
39
+ book = InheritedBookWithDepth.from_xml(@book_xml)
40
+ assert_equal "Pragmattic Programmers", book.publisher
41
+ end
19
42
  end
@@ -1,6 +1,13 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
2
 
3
3
  class TestOptions < Test::Unit::TestCase
4
+ def assert_hash(opts, kvp)
5
+ assert opts.hash?
6
+ assert !opts.array?
7
+ assert_equal kvp, {opts.hash.key.type => opts.hash.key.name,
8
+ opts.hash.value.type => opts.hash.value.name}
9
+ end
10
+
4
11
  def test_text_in_array_means_as_array_for_text
5
12
  opts = ROXML::Opts.new(:authors, [:text])
6
13
  assert opts.array?
@@ -33,44 +40,38 @@ class TestOptions < Test::Unit::TestCase
33
40
  assert_raise ArgumentError do
34
41
  ROXML::Opts.new(:author, :content, :required => true, :else => 'Johnny')
35
42
  end
36
- ROXML::Opts.new(:author, :content, :required => false, :else => 'Johnny')
43
+ assert_nothing_raised do
44
+ ROXML::Opts.new(:author, :content, :required => false, :else => 'Johnny')
45
+ end
37
46
  end
38
47
 
39
48
  def test_hash_of_attrs
40
49
  opts = ROXML::Opts.new(:attributes, {:attrs => [:name, :value]})
41
- assert opts.hash?
42
- assert !opts.array?
43
- assert_equal [ROXML::XMLAttributeRef, ROXML::XMLAttributeRef], opts.hash.types
44
- assert_equal ['name', 'value'], opts.hash.names
50
+ assert_hash(opts, :attr => 'name', :attr => 'value')
45
51
  end
46
52
 
47
53
  def test_hash_with_attr_key_and_text_val
48
54
  opts = ROXML::Opts.new(:attributes, {:key => {:attr => :name},
49
55
  :value => :value})
50
- assert opts.hash?
51
- assert !opts.array?
52
- assert_equal [ROXML::XMLAttributeRef, ROXML::XMLTextRef], opts.hash.types
53
- assert_equal ['name', 'value'], opts.hash.names
56
+ assert_hash(opts, :attr => 'name', :text => 'value')
57
+ end
58
+
59
+ def test_hash_with_string_class_for_type
60
+ opts = ROXML::Opts.new(:attributes, {:key => {String => 'name'},
61
+ :value => {String => 'value'}})
62
+ assert_hash(opts, :text => 'name', :text => 'value')
54
63
  end
55
64
 
56
65
  def test_hash_with_attr_key_and_content_val
57
66
  opts = ROXML::Opts.new(:attributes, {:key => {:attr => :name},
58
67
  :value => :content})
59
- assert opts.hash?
60
- assert !opts.array?
61
- assert opts.hash.value.content?
62
- assert_equal [ROXML::XMLAttributeRef, ROXML::XMLTextRef], opts.hash.types
63
- assert_equal ['name', ''], opts.hash.names
68
+ assert_hash(opts, :attr => 'name', :content => '')
64
69
  end
65
70
 
66
71
  def test_hash_with_options
67
72
  opts = ROXML::Opts.new(:definitions, {:attrs => [:dt, :dd]},
68
73
  :in => :definitions)
69
-
70
- assert opts.hash?
71
- assert !opts.array?
72
- assert_equal [ROXML::XMLAttributeRef, ROXML::XMLAttributeRef], opts.hash.types
73
- assert_equal ['dt', 'dd'], opts.hash.names
74
+ assert_hash(opts, :attr => 'dt', :attr => 'dd')
74
75
  end
75
76
 
76
77
  def test_no_block_shorthand_means_no_block
@@ -0,0 +1,33 @@
1
+ class OctalInteger
2
+ def self.from_xml(val)
3
+ new(Integer(val.content))
4
+ end
5
+
6
+ def initialize(value)
7
+ @val = value
8
+ end
9
+
10
+ def ==(other)
11
+ @val == other
12
+ end
13
+
14
+ def to_xml
15
+ sprintf("%#o", @val)
16
+ end
17
+ end
18
+
19
+ class BookWithOctalPages
20
+ include ROXML
21
+
22
+ xml_accessor :pages_with_to_xml_proc, :as => Integer, :to_xml => proc {|val| sprintf("%#o", val) }, :required => true
23
+ xml_accessor :pages_with_type, OctalInteger, :required => true
24
+ end
25
+
26
+ class TestToXmlWithOverriddenOutput < Test::Unit::TestCase
27
+ to_xml_test :book_with_octal_pages
28
+ def test_padded_numbers_read_properly
29
+ b = BookWithOctalPages.from_xml(fixture(:book_with_octal_pages))
30
+ assert_equal 239, b.pages_with_type
31
+ assert_equal 239, b.pages_with_to_xml_proc
32
+ end
33
+ end