1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
require_relative './../test_helper'
require 'minitest/autorun'
class TestHashToXml < Minitest::Test
to_xml_test :dictionary_of_attrs,
:dictionary_of_mixeds,
:dictionary_of_texts,
:dictionary_of_names,
:dictionary_of_guarded_names,
:dictionary_of_name_clashes,
:dictionary_of_attr_name_clashes
end
class TestOtherToXml < Minitest::Test
to_xml_test :book => :book_valid,
:book_with_author_text_attribute => :book_text_with_attribute,
:uppercase_library => :library_uppercase
to_xml_test :book_with_authors,
:book_with_contributors,
:book_with_contributions,
:library,
:node_with_name_conflicts,
:node_with_attr_name_conflicts
to_xml_test :person_with_mother => :person_with_mothers,
:person_with_guarded_mother => :person_with_guarded_mothers
to_xml_test :book_with_wrapped_attr
end
class TestToXmlWithDefaults < Minitest::Test
def test_content_and_attr_defaults_are_represented_in_output
dict = Person.from_xml(fixture(:nameless_ageless_youth))
xml = '<person age="21">Unknown</person>'
assert_equal ROXML::XML.parse_string(xml).root.to_s, dict.to_xml.to_s
end
end
class TestToXmlWithBlocks < Minitest::Test
def test_pagecount_serialized_properly_after_modification
b = Book.from_xml(fixture(:book_valid))
xml = xml_fixture(:book_valid)
assert_equal '357', ROXML::XML.search(xml, 'pagecount').first.content
assert_equal 357, b.pages
b.pages = 500
doc = ROXML::XML::Document.new()
doc.root = b.to_xml
assert_equal '500', ROXML::XML.search(doc, 'pagecount').first.content
end
end
class OctalInteger
def self.from_xml(val)
new(Integer(val.content))
end
def initialize(value)
@val = value
end
def ==(other)
@val == other
end
def to_xml
sprintf("%#o", @val)
end
end
class BookWithOctalPages
include ROXML
xml_accessor :pages, :as => OctalInteger, :required => true
end
class TestToXmlWithOverriddenOutput < Minitest::Test
to_xml_test :book_with_octal_pages
end
|