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
|
# Tests elements with both type attributes and other attributes, including unrecognized types
module ParserMixedAttributeTests
def test_children_with_unrecognized_type_attribute_tags_on_content_nodes_first_value
xml = "<options><value type='USD'>123</value><value type='percent'>0.123</value><value currency='USD'>123</value></options>"
values = MultiXml.parse(xml)["options"]["value"]
assert_equal "123", values[0]["__content__"]
assert_equal "USD", values[0]["type"]
end
def test_children_with_unrecognized_type_attribute_tags_on_content_nodes_second_value
xml = "<options><value type='USD'>123</value><value type='percent'>0.123</value><value currency='USD'>123</value></options>"
values = MultiXml.parse(xml)["options"]["value"]
assert_equal "0.123", values[1]["__content__"]
assert_equal "percent", values[1]["type"]
end
def test_children_with_unrecognized_type_attribute_tags_on_content_nodes_third_value
xml = "<options><value type='USD'>123</value><value type='percent'>0.123</value><value currency='USD'>123</value></options>"
values = MultiXml.parse(xml)["options"]["value"]
assert_equal "123", values[2]["__content__"]
assert_equal "USD", values[2]["currency"]
end
def test_children_mixing_attributes_and_non_attributes_first_value
xml = "<options><value type='USD'>123</value><value type='percent'>0.123</value><value>123</value></options>"
assert_equal "123", MultiXml.parse(xml)["options"]["value"][0]["__content__"]
assert_equal "USD", MultiXml.parse(xml)["options"]["value"][0]["type"]
end
def test_children_mixing_attributes_and_non_attributes_second_value
xml = "<options><value type='USD'>123</value><value type='percent'>0.123</value><value>123</value></options>"
assert_equal "0.123", MultiXml.parse(xml)["options"]["value"][1]["__content__"]
assert_equal "percent", MultiXml.parse(xml)["options"]["value"][1]["type"]
end
def test_children_mixing_attributes_and_non_attributes_third_value
xml = "<options><value type='USD'>123</value><value type='percent'>0.123</value><value>123</value></options>"
assert_equal "123", MultiXml.parse(xml)["options"]["value"][2]
end
def test_children_mixing_recognized_type_attribute_and_non_type_attributes
xml = "<options><value number='USD' type='integer'>123</value></options>"
result = MultiXml.parse(xml)["options"]["value"]
assert_equal 123, result["__content__"]
assert_equal "USD", result["number"]
end
def test_children_mixing_unrecognized_type_attribute_and_non_type_attributes
xml = "<options><value number='USD' type='currency'>123</value></options>"
result = MultiXml.parse(xml)["options"]["value"]
assert_equal "123", result["__content__"]
assert_equal "USD", result["number"]
assert_equal "currency", result["type"]
end
end
|