Skip to content

Commit

Permalink
Use stricter docstring verification
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Lipt0nas committed Nov 29, 2023
1 parent a2c9acd commit 540f997
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions cpp-tests/tests/uniffi_docstring/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "test_common.hpp"

#include <fstream>
#include <regex>

#include <uniffi_docstring.hpp>

Expand Down Expand Up @@ -36,10 +37,30 @@ int main() {
auto source = std::string(std::istreambuf_iterator<char>(stream), std::istreambuf_iterator<char>());
ASSERT_FALSE(source.empty());

std::regex docstring_reg("/\\*[^*]*\\*+(?:[^/*][^*]*\\*+)*/");
std::regex docstring_inner_reg("\\<(.*?)\\>");
std::smatch matches;
std::vector<std::string> 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);
}
}
Expand Down

0 comments on commit 540f997

Please sign in to comment.