diff options
author | artyasen <artyasen@yandex-team.com> | 2025-02-03 15:57:35 +0300 |
---|---|---|
committer | artyasen <artyasen@yandex-team.com> | 2025-02-03 16:35:09 +0300 |
commit | a19aaf0e98329e8fff4e16626c2f8212f7d87789 (patch) | |
tree | b262bcd535c5f29e36b701c95fa91c8beb32fcb6 /library/cpp/xml/document/xml-document_ut.cpp | |
parent | cafd6740c55721b602590b6371e271bb41355e36 (diff) | |
download | ydb-a19aaf0e98329e8fff4e16626c2f8212f7d87789.tar.gz |
Получение XML аттрибута без исключений
add no exception methods
commit_hash:245a52ca795a16ad57a9ac642b0cd00ca0122a32
Diffstat (limited to 'library/cpp/xml/document/xml-document_ut.cpp')
-rw-r--r-- | library/cpp/xml/document/xml-document_ut.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/library/cpp/xml/document/xml-document_ut.cpp b/library/cpp/xml/document/xml-document_ut.cpp index 9f537b75c4..0ec1fc6083 100644 --- a/library/cpp/xml/document/xml-document_ut.cpp +++ b/library/cpp/xml/document/xml-document_ut.cpp @@ -1,5 +1,6 @@ #include <library/cpp/testing/unittest/registar.h> #include <util/generic/map.h> +#include <util/generic/yexception.h> #include "xml-document.h" @@ -35,6 +36,27 @@ Y_UNIT_TEST_SUITE(TestXmlDocument) { NXml::TConstNode text = root.Node("text"); UNIT_ASSERT_EQUAL(text.Value<TString>(), "Некоторый текст"); } + Y_UNIT_TEST(GetAttributes) { + NXml::TDocument xml(R"(<?xml version="1.0"?> + <root> + <a><b len="15" correct="1">hello world</b></a> + <text>Некоторый текст</text> + </root> + )", + NXml::TDocument::String); + + NXml::TConstNode root = xml.Root(); + NXml::TConstNode b = root.Node("a/b"); + + UNIT_ASSERT_EXCEPTION_CONTAINS(b.Attr<int>("unknown attrib"), yexception, "@unknown attrib"); + + const auto unknownAttr = b.TryAttr<int>("unknown attrib"); + UNIT_ASSERT(unknownAttr.Empty()); + + const auto knownAttr = b.TryAttr<int>("len"); + UNIT_ASSERT(knownAttr.Defined()); + UNIT_ASSERT_EQUAL(knownAttr.GetRef(), 15); + } Y_UNIT_TEST(SerializeString) { NXml::TDocument xml("frob", NXml::TDocument::RootName); xml.Root().SetAttr("xyzzy", "Frobozz"); |