From 94d3f676c69e5004b22c5baff65156316753247f Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 22 Oct 2020 08:38:59 +1000 Subject: [PATCH] introspection: update name tests for clang-11 --- test/introspection.cpp | 44 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/test/introspection.cpp b/test/introspection.cpp index 216862f1..13b9ee5c 100644 --- a/test/introspection.cpp +++ b/test/introspection.cpp @@ -72,6 +72,40 @@ equal (A &&a, B &&b) } +///---------------------------------------------------------------------------- +/// Returns true if the two strings are equal except for any embedded +/// whitespace. +static bool +whitespace_equal (std::string_view a, std::string_view b) +{ + auto const a_size = std::ssize (a); + auto const b_size = std::ssize (b); + + int a_cursor = 0; + int b_cursor = 0; + + while (a_cursor < a_size && b_cursor < b_size) { + if (a[a_cursor] == ' ') { + ++a_cursor; + continue; + } + + if (b[b_cursor] == ' ') { + ++b_cursor; + continue; + } + + if (a[a_cursor] != b[b_cursor]) + return false; + + ++a_cursor; + ++b_cursor; + } + + return a_cursor == a_size && b_cursor == b_size; +} + + //----------------------------------------------------------------------------- int main () { @@ -139,9 +173,13 @@ int main () "templated_with_type" ); - tap.expect_eq ( - cruft::introspection::name::full>> (), - std::string_view {"templated_with_type >"}, + // The trailing '>' characters are separated by whitespace in GCC, and + // Clang<11, but aren't meaningfully different in user interpretation. + tap.expect ( + whitespace_equal ( + cruft::introspection::name::full>> (), + std::string_view {"templated_with_type>"} + ), "templated_with_type" );