diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2013-03-15 08:22:58 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2013-03-15 08:22:58 +0200 |
commit | 927b97baaaf69e318ff7a0ce76d096375ec09da2 (patch) | |
tree | 074d633c92c99ec541e7f0631c2fd2a6c5378689 /tests/xml/parser | |
parent | 6664a24b003f3959e2efe2893628f725a5f6746f (diff) |
Add support for returning XML attributes as map
Diffstat (limited to 'tests/xml/parser')
-rw-r--r-- | tests/xml/parser/driver.cxx | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/tests/xml/parser/driver.cxx b/tests/xml/parser/driver.cxx index 787da50..4c85b77 100644 --- a/tests/xml/parser/driver.cxx +++ b/tests/xml/parser/driver.cxx @@ -81,11 +81,56 @@ main () // cerr << e.what () << endl; } + // Test attribute maps. + // + { + istringstream is ("<root a='a' b='b' d='123' t='true'/>"); + parser p (is, "test"); + p.next_expect (parser::start_element, "root"); + + assert (p.attribute ("a") == "a"); + assert (p.attribute ("b", "B") == "b"); + assert (p.attribute ("c", "C") == "C"); + assert (p.attribute<int> ("d") == 123); + assert (p.attribute<bool> ("t") == true); + assert (p.attribute ("f", false) == false); + + p.next_expect (parser::end_element); + } + + try + { + istringstream is ("<root a='a' b='b'/>"); + parser p (is, "test"); + p.next_expect (parser::start_element, "root"); + assert (p.attribute ("a") == "a"); + p.next_expect (parser::end_element); + assert (false); + } + catch (const xml::exception& e) + { + // cerr << e.what () << endl; + } + + try + { + istringstream is ("<root a='abc'/>"); + parser p (is, "test"); + p.next_expect (parser::start_element, "root"); + p.attribute<int> ("a"); + assert (false); + } + catch (const xml::exception& e) + { + // cerr << e.what () << endl; + } + // Test peeking and getting the current event. // { istringstream is ("<root x='x'>x<nested/></root>"); - parser p (is, "peek"); + parser p (is, "peek", + parser::receive_default | parser::receive_attributes_event); assert (p.event () == parser::eof); @@ -133,7 +178,8 @@ main () // { istringstream is ("<root x=' x '> \n\t </root>"); - parser p (is, "empty"); + parser p (is, "empty", + parser::receive_default | parser::receive_attributes_event); assert (p.next () == parser::start_element); p.content (parser::empty); @@ -197,7 +243,8 @@ main () " <inner> X </inner>\n" " </nested>\n" "</root>\n"); - parser p (is, "complex"); + parser p (is, "complex", + parser::receive_default | parser::receive_attributes_event); assert (p.next () == parser::start_element); // root p.content (parser::complex); |