|
| 1 | +// Copyright 2023 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#include "docfx/linked_text_type.h" |
| 16 | +#include <gmock/gmock.h> |
| 17 | + |
| 18 | +namespace docfx { |
| 19 | +namespace { |
| 20 | + |
| 21 | +TEST(LinkedTextType, Basic) { |
| 22 | + auto constexpr kXml = R"xml(<?xml version="1.0" standalone="yes"?> |
| 23 | + <doxygen version="1.9.1" xml:lang="en-US"> |
| 24 | + <type id="001"><ref refid="classgoogle_1_1cloud_1_1ErrorInfo" kindref="compound">ErrorInfo</ref> const &</type> |
| 25 | + <type id="002">std::string</type> |
| 26 | + </doxygen>)xml"; |
| 27 | + pugi::xml_document doc; |
| 28 | + doc.load_string(kXml); |
| 29 | + |
| 30 | + struct TestCase { |
| 31 | + std::string id; |
| 32 | + std::string expected; |
| 33 | + } const cases[] = { |
| 34 | + {"001", "ErrorInfo const &"}, |
| 35 | + {"002", "std::string"}, |
| 36 | + }; |
| 37 | + |
| 38 | + auto vars = pugi::xpath_variable_set(); |
| 39 | + vars.add("id", pugi::xpath_type_string); |
| 40 | + auto query = pugi::xpath_query("//*[@id = string($id)]", &vars); |
| 41 | + for (auto const& test : cases) { |
| 42 | + SCOPED_TRACE("Running with id=" + test.id); |
| 43 | + vars.set("id", test.id.c_str()); |
| 44 | + auto selected = doc.select_node(query); |
| 45 | + ASSERT_TRUE(selected); |
| 46 | + EXPECT_EQ(test.expected, LinkedTextType(selected.node())); |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +} // namespace |
| 51 | +} // namespace docfx |
0 commit comments