From a19aaf0e98329e8fff4e16626c2f8212f7d87789 Mon Sep 17 00:00:00 2001 From: artyasen Date: Mon, 3 Feb 2025 15:57:35 +0300 Subject: Получение XML аттрибута без исключений MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit add no exception methods commit_hash:245a52ca795a16ad57a9ac642b0cd00ca0122a32 --- library/cpp/xml/document/xml-document_ut.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'library/cpp/xml/document/xml-document_ut.cpp') diff --git a/library/cpp/xml/document/xml-document_ut.cpp b/library/cpp/xml/document/xml-document_ut.cpp index 9f537b75c4c..0ec1fc60838 100644 --- a/library/cpp/xml/document/xml-document_ut.cpp +++ b/library/cpp/xml/document/xml-document_ut.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "xml-document.h" @@ -35,6 +36,27 @@ Y_UNIT_TEST_SUITE(TestXmlDocument) { NXml::TConstNode text = root.Node("text"); UNIT_ASSERT_EQUAL(text.Value(), "Некоторый текст"); } + Y_UNIT_TEST(GetAttributes) { + NXml::TDocument xml(R"( + + hello world + Некоторый текст + + )", + NXml::TDocument::String); + + NXml::TConstNode root = xml.Root(); + NXml::TConstNode b = root.Node("a/b"); + + UNIT_ASSERT_EXCEPTION_CONTAINS(b.Attr("unknown attrib"), yexception, "@unknown attrib"); + + const auto unknownAttr = b.TryAttr("unknown attrib"); + UNIT_ASSERT(unknownAttr.Empty()); + + const auto knownAttr = b.TryAttr("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"); -- cgit v1.3