From 540f997de9b429cc9934474397904dedf63723c9 Mon Sep 17 00:00:00 2001 From: Martynas Gurskas Date: Wed, 29 Nov 2023 11:03:42 +0200 Subject: [PATCH] Use stricter docstring verification Instead of checking if a given set of docstrings exits, instead parse all present docstrings and verify that there is no more or no less than the expected entries Signed-off-by: Martynas Gurskas --- cpp-tests/tests/uniffi_docstring/main.cpp | 27 ++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/cpp-tests/tests/uniffi_docstring/main.cpp b/cpp-tests/tests/uniffi_docstring/main.cpp index 3bc4899..ce132a8 100644 --- a/cpp-tests/tests/uniffi_docstring/main.cpp +++ b/cpp-tests/tests/uniffi_docstring/main.cpp @@ -1,6 +1,7 @@ #include "test_common.hpp" #include +#include #include @@ -36,10 +37,30 @@ int main() { auto source = std::string(std::istreambuf_iterator(stream), std::istreambuf_iterator()); ASSERT_FALSE(source.empty()); + std::regex docstring_reg("/\\*[^*]*\\*+(?:[^/*][^*]*\\*+)*/"); + std::regex docstring_inner_reg("\\<(.*?)\\>"); + std::smatch matches; + std::vector extracted_docstrings; + + while (std::regex_search(source, matches, docstring_reg)) { + source = matches.suffix().str(); + + auto docstring = matches[0].str(); + if (std::regex_search(docstring, matches, docstring_inner_reg)) { + extracted_docstrings.push_back(matches[0].str()); + } + } + for (const auto& docstring : expected_docstrings) { - auto found = source.find(docstring); - if (found == std::string::npos) { - std::cerr << "Could not find docstring: " << docstring << std::endl; + if (std::find(extracted_docstrings.begin(), extracted_docstrings.end(), docstring) == extracted_docstrings.end()) { + std::cerr << "Could not find expected docstring: " << docstring << std::endl; + ASSERT_TRUE(false); + } + } + + for (const auto& docstring : extracted_docstrings) { + if (std::find(expected_docstrings.begin(), expected_docstrings.end(), docstring) == expected_docstrings.end()) { + std::cerr << "Unexpected docstring found: " << docstring << std::endl; ASSERT_TRUE(false); } }