- 
                Notifications
    You must be signed in to change notification settings 
- Fork 15k
          [libc++][test][NFC] Clang-format <regex> tests
          #164367
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
  
    [libc++][test][NFC] Clang-format <regex> tests
  
  #164367
              Conversation
There is possibly upcoming overhaul for `<regex>`. It would be easier to modify the test files if they are clang-formatted. Some files are manually adjusted. Adds clang-format off/on comments to avoid line break: - libcxx/test/std/re/re.regex/re.regex.construct/awk_oct.pass.cpp - libcxx/test/std/re/re.regex/re.regex.construct/deduct.verify.cpp Adds new lines to avoid ugly grouping for `=`: - libcxx/test/std/re/re.const/re.matchflag/match_flag_type.pass.cpp - libcxx/test/std/re/re.const/re.synopt/syntax_option_type.pass.cpp
| @llvm/pr-subscribers-libcxx Author: A. Jiang (frederick-vs-ja) ChangesThere is possibly upcoming overhaul for  Some files are manually adjusted. Adds clang-format off/on comments to avoid line break: 
 Adds new lines to avoid ugly grouping for  
 Patch is 1.23 MiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/164367.diff 173 Files Affected: 
 diff --git a/libcxx/test/std/re/re.alg/re.alg.match/awk.pass.cpp b/libcxx/test/std/re/re.alg/re.alg.match/awk.pass.cpp
index 024738258c050..ef906ff21d3f1 100644
--- a/libcxx/test/std/re/re.alg/re.alg.match/awk.pass.cpp
+++ b/libcxx/test/std/re/re.alg/re.alg.match/awk.pass.cpp
@@ -21,1336 +21,1289 @@
 #include "test_macros.h"
 #include "test_iterators.h"
 
-int main(int, char**)
-{
-    {
-        std::cmatch m;
-        const char s[] = "a";
-        assert(std::regex_match(s, m, std::regex("a", std::regex_constants::awk)));
-        assert(m.size() == 1);
-        assert(!m.empty());
-        assert(!m.prefix().matched);
-        assert(m.prefix().first == s);
-        assert(m.prefix().second == m[0].first);
-        assert(!m.suffix().matched);
-        assert(m.suffix().first == m[0].second);
-        assert(m.suffix().second == s+1);
-        assert(m.length(0) == 1);
-        assert(m.position(0) == 0);
-        assert(m.str(0) == "a");
-    }
-    {
-        std::cmatch m;
-        const char s[] = "ab";
-        assert(std::regex_match(s, m, std::regex("ab", std::regex_constants::awk)));
-        assert(m.size() == 1);
-        assert(!m.prefix().matched);
-        assert(m.prefix().first == s);
-        assert(m.prefix().second == m[0].first);
-        assert(!m.suffix().matched);
-        assert(m.suffix().first == m[0].second);
-        assert(m.suffix().second == s+2);
-        assert(m.length(0) == 2);
-        assert(m.position(0) == 0);
-        assert(m.str(0) == "ab");
-    }
-    {
-        std::cmatch m;
-        const char s[] = "ab";
-        assert(!std::regex_match(s, m, std::regex("ba", std::regex_constants::awk)));
-        assert(m.size() == 0);
-        assert(m.empty());
-    }
-    {
-        std::cmatch m;
-        const char s[] = "aab";
-        assert(!std::regex_match(s, m, std::regex("ab", std::regex_constants::awk)));
-        assert(m.size() == 0);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "aab";
-        assert(!std::regex_match(s, m, std::regex("ab", std::regex_constants::awk),
-                                            std::regex_constants::match_continuous));
-        assert(m.size() == 0);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "abcd";
-        assert(!std::regex_match(s, m, std::regex("bc", std::regex_constants::awk)));
-        assert(m.size() == 0);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "abbc";
-        assert(std::regex_match(s, m, std::regex("ab*c", std::regex_constants::awk)));
-        assert(m.size() == 1);
-        assert(!m.prefix().matched);
-        assert(m.prefix().first == s);
-        assert(m.prefix().second == m[0].first);
-        assert(!m.suffix().matched);
-        assert(m.suffix().first == m[0].second);
-        assert(m.suffix().second == s+4);
-        assert(m.length(0) == 4);
-        assert(m.position(0) == 0);
-        assert(m.str(0) == s);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "ababc";
-        assert(std::regex_match(s, m, std::regex("(ab)*c", std::regex_constants::awk)));
-        assert(m.size() == 2);
-        assert(!m.prefix().matched);
-        assert(m.prefix().first == s);
-        assert(m.prefix().second == m[0].first);
-        assert(!m.suffix().matched);
-        assert(m.suffix().first == m[0].second);
-        assert(m.suffix().second == s+5);
-        assert(m.length(0) == 5);
-        assert(m.position(0) == 0);
-        assert(m.str(0) == s);
-        assert(m.length(1) == 2);
-        assert(m.position(1) == 2);
-        assert(m.str(1) == "ab");
-    }
-    {
-        std::cmatch m;
-        const char s[] = "abcdefghijk";
-        assert(!std::regex_match(s, m, std::regex("cd((e)fg)hi",
-                                 std::regex_constants::awk)));
-        assert(m.size() == 0);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "abc";
-        assert(std::regex_match(s, m, std::regex("^abc", std::regex_constants::awk)));
-        assert(m.size() == 1);
-        assert(!m.prefix().matched);
-        assert(m.prefix().first == s);
-        assert(m.prefix().second == m[0].first);
-        assert(!m.suffix().matched);
-        assert(m.suffix().first == m[0].second);
-        assert(m.suffix().second == s+3);
-        assert(m.length(0) == 3);
-        assert(m.position(0) == 0);
-        assert(m.str(0) == s);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "abcd";
-        assert(!std::regex_match(s, m, std::regex("^abc", std::regex_constants::awk)));
-        assert(m.size() == 0);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "aabc";
-        assert(!std::regex_match(s, m, std::regex("^abc", std::regex_constants::awk)));
-        assert(m.size() == 0);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "abc";
-        assert(std::regex_match(s, m, std::regex("abc$", std::regex_constants::awk)));
-        assert(m.size() == 1);
-        assert(!m.prefix().matched);
-        assert(m.prefix().first == s);
-        assert(m.prefix().second == m[0].first);
-        assert(!m.suffix().matched);
-        assert(m.suffix().first == m[0].second);
-        assert(m.suffix().second == s+3);
-        assert(m.length(0) == 3);
-        assert(m.position(0) == 0);
-        assert(m.str(0) == s);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "efabc";
-        assert(!std::regex_match(s, m, std::regex("abc$", std::regex_constants::awk)));
-        assert(m.size() == 0);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "efabcg";
-        assert(!std::regex_match(s, m, std::regex("abc$", std::regex_constants::awk)));
-        assert(m.size() == 0);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "abc";
-        assert(std::regex_match(s, m, std::regex("a.c", std::regex_constants::awk)));
-        assert(m.size() == 1);
-        assert(!m.prefix().matched);
-        assert(m.prefix().first == s);
-        assert(m.prefix().second == m[0].first);
-        assert(!m.suffix().matched);
-        assert(m.suffix().first == m[0].second);
-        assert(m.suffix().second == s+3);
-        assert(m.length(0) == 3);
-        assert(m.position(0) == 0);
-        assert(m.str(0) == s);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "acc";
-        assert(std::regex_match(s, m, std::regex("a.c", std::regex_constants::awk)));
-        assert(m.size() == 1);
-        assert(!m.prefix().matched);
-        assert(m.prefix().first == s);
-        assert(m.prefix().second == m[0].first);
-        assert(!m.suffix().matched);
-        assert(m.suffix().first == m[0].second);
-        assert(m.suffix().second == s+3);
-        assert(m.length(0) == 3);
-        assert(m.position(0) == 0);
-        assert(m.str(0) == s);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "acc";
-        assert(std::regex_match(s, m, std::regex("a.c", std::regex_constants::awk)));
-        assert(m.size() == 1);
-        assert(!m.prefix().matched);
-        assert(m.prefix().first == s);
-        assert(m.prefix().second == m[0].first);
-        assert(!m.suffix().matched);
-        assert(m.suffix().first == m[0].second);
-        assert(m.suffix().second == s+3);
-        assert(m.length(0) == 3);
-        assert(m.position(0) == 0);
-        assert(m.str(0) == s);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "abcdef";
-        assert(std::regex_match(s, m, std::regex("(.*).*", std::regex_constants::awk)));
-        assert(m.size() == 2);
-        assert(!m.prefix().matched);
-        assert(m.prefix().first == s);
-        assert(m.prefix().second == m[0].first);
-        assert(!m.suffix().matched);
-        assert(m.suffix().first == m[0].second);
-        assert(m.suffix().second == s+6);
-        assert(m.length(0) == 6);
-        assert(m.position(0) == 0);
-        assert(m.str(0) == s);
-        assert(m.length(1) == 6);
-        assert(m.position(1) == 0);
-        assert(m.str(1) == s);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "bc";
-        assert(!std::regex_match(s, m, std::regex("(a*)*", std::regex_constants::awk)));
-        assert(m.size() == 0);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "abbc";
-        assert(!std::regex_match(s, m, std::regex("ab{3,5}c", std::regex_constants::awk)));
-        assert(m.size() == 0);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "abbbc";
-        assert(std::regex_match(s, m, std::regex("ab{3,5}c", std::regex_constants::awk)));
-        assert(m.size() == 1);
-        assert(!m.prefix().matched);
-        assert(m.prefix().first == s);
-        assert(m.prefix().second == m[0].first);
-        assert(!m.suffix().matched);
-        assert(m.suffix().first == m[0].second);
-        assert(m.suffix().second == m[0].second);
-        assert((std::size_t)m.length(0) == std::char_traits<char>::length(s));
-        assert(m.position(0) == 0);
-        assert(m.str(0) == s);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "abbbbc";
-        assert(std::regex_match(s, m, std::regex("ab{3,5}c", std::regex_constants::awk)));
-        assert(m.size() == 1);
-        assert(!m.prefix().matched);
-        assert(m.prefix().first == s);
-        assert(m.prefix().second == m[0].first);
-        assert(!m.suffix().matched);
-        assert(m.suffix().first == m[0].second);
-        assert(m.suffix().second == m[0].second);
-        assert((std::size_t)m.length(0) == std::char_traits<char>::length(s));
-        assert(m.position(0) == 0);
-        assert(m.str(0) == s);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "abbbbbc";
-        assert(std::regex_match(s, m, std::regex("ab{3,5}c", std::regex_constants::awk)));
-        assert(m.size() == 1);
-        assert(!m.prefix().matched);
-        assert(m.prefix().first == s);
-        assert(m.prefix().second == m[0].first);
-        assert(!m.suffix().matched);
-        assert(m.suffix().first == m[0].second);
-        assert(m.suffix().second == m[0].second);
-        assert((std::size_t)m.length(0) == std::char_traits<char>::length(s));
-        assert(m.position(0) == 0);
-        assert(m.str(0) == s);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "adefc";
-        assert(!std::regex_match(s, m, std::regex("ab{3,5}c", std::regex_constants::awk)));
-        assert(m.size() == 0);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "abbbbbbc";
-        assert(!std::regex_match(s, m, std::regex("ab{3,5}c", std::regex_constants::awk)));
-        assert(m.size() == 0);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "adec";
-        assert(!std::regex_match(s, m, std::regex("a.{3,5}c", std::regex_constants::awk)));
-        assert(m.size() == 0);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "adefc";
-        assert(std::regex_match(s, m, std::regex("a.{3,5}c", std::regex_constants::awk)));
-        assert(m.size() == 1);
-        assert(!m.prefix().matched);
-        assert(m.prefix().first == s);
-        assert(m.prefix().second == m[0].first);
-        assert(!m.suffix().matched);
-        assert(m.suffix().first == m[0].second);
-        assert(m.suffix().second == m[0].second);
-        assert((std::size_t)m.length(0) == std::char_traits<char>::length(s));
-        assert(m.position(0) == 0);
-        assert(m.str(0) == s);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "adefgc";
-        assert(std::regex_match(s, m, std::regex("a.{3,5}c", std::regex_constants::awk)));
-        assert(m.size() == 1);
-        assert(!m.prefix().matched);
-        assert(m.prefix().first == s);
-        assert(m.prefix().second == m[0].first);
-        assert(!m.suffix().matched);
-        assert(m.suffix().first == m[0].second);
-        assert(m.suffix().second == m[0].second);
-        assert((std::size_t)m.length(0) == std::char_traits<char>::length(s));
-        assert(m.position(0) == 0);
-        assert(m.str(0) == s);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "adefghc";
-        assert(std::regex_match(s, m, std::regex("a.{3,5}c", std::regex_constants::awk)));
-        assert(m.size() == 1);
-        assert(!m.prefix().matched);
-        assert(m.prefix().first == s);
-        assert(m.prefix().second == m[0].first);
-        assert(!m.suffix().matched);
-        assert(m.suffix().first == m[0].second);
-        assert(m.suffix().second == m[0].second);
-        assert((std::size_t)m.length(0) == std::char_traits<char>::length(s));
-        assert(m.position(0) == 0);
-        assert(m.str(0) == s);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "adefghic";
-        assert(!std::regex_match(s, m, std::regex("a.{3,5}c", std::regex_constants::awk)));
-        assert(m.size() == 0);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "tournament";
-        assert(std::regex_match(s, m, std::regex("tour|to|tournament",
-                                              std::regex_constants::awk)));
-        assert(m.size() == 1);
-        assert(!m.prefix().matched);
-        assert(m.prefix().first == s);
-        assert(m.prefix().second == m[0].first);
-        assert(!m.suffix().matched);
-        assert(m.suffix().first == m[0].second);
-        assert(m.suffix().second == m[0].second);
-        assert((std::size_t)m.length(0) == std::char_traits<char>::length(s));
-        assert(m.position(0) == 0);
-        assert(m.str(0) == s);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "tournamenttotour";
-        assert(std::regex_match(s, m, std::regex("(tour|to|tournament)+",
-               std::regex_constants::awk | std::regex_constants::nosubs)));
-        assert(m.size() == 1);
-        assert(!m.prefix().matched);
-        assert(m.prefix().first == s);
-        assert(m.prefix().second == m[0].first);
-        assert(!m.suffix().matched);
-        assert(m.suffix().first == m[0].second);
-        assert(m.suffix().second == m[0].second);
-        assert((std::size_t)m.length(0) == std::char_traits<char>::length(s));
-        assert(m.position(0) == 0);
-        assert(m.str(0) == s);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "ttotour";
-        assert(std::regex_match(s, m, std::regex("(tour|to|t)+",
-                                              std::regex_constants::awk)));
-        assert(m.size() == 2);
-        assert(!m.prefix().matched);
-        assert(m.prefix().first == s);
-        assert(m.prefix().second == m[0].first);
-        assert(!m.suffix().matched);
-        assert(m.suffix().first == m[0].second);
-        assert(m.suffix().second == m[0].second);
-        assert((std::size_t)m.length(0) == std::char_traits<char>::length(s));
-        assert(m.position(0) == 0);
-        assert(m.str(0) == s);
-        assert(m.length(1) == 4);
-        assert(m.position(1) == 3);
-        assert(m.str(1) == "tour");
-    }
-    {
-        std::cmatch m;
-        const char s[] = "-ab,ab-";
-        assert(!std::regex_match(s, m, std::regex("-(.*),\1-", std::regex_constants::awk)));
-        assert(m.size() == 0);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "-ab,ab-";
-        assert(std::regex_match(s, m, std::regex("-.*,.*-", std::regex_constants::awk)));
-        assert(m.size() == 1);
-        assert(!m.prefix().matched);
-        assert(m.prefix().first == s);
-        assert(m.prefix().second == m[0].first);
-        assert(!m.suffix().matched);
-        assert(m.suffix().first == m[0].second);
-        assert(m.suffix().second == m[0].second);
-        assert((std::size_t)m.length(0) == std::char_traits<char>::length(s));
-        assert(m.position(0) == 0);
-        assert(m.str(0) == s);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "a";
-        assert(std::regex_match(s, m, std::regex("^[a]$",
-                                                 std::regex_constants::awk)));
-        assert(m.size() == 1);
-        assert(!m.prefix().matched);
-        assert(m.prefix().first == s);
-        assert(m.prefix().second == m[0].first);
-        assert(!m.suffix().matched);
-        assert(m.suffix().first == m[0].second);
-        assert(m.suffix().second == m[0].second);
-        assert(m.length(0) == 1);
-        assert(m.position(0) == 0);
-        assert(m.str(0) == "a");
-    }
-    {
-        std::cmatch m;
-        const char s[] = "a";
-        assert(std::regex_match(s, m, std::regex("^[ab]$",
-                                                 std::regex_constants::awk)));
-        assert(m.size() == 1);
-        assert(!m.prefix().matched);
-        assert(m.prefix().first == s);
-        assert(m.prefix().second == m[0].first);
-        assert(!m.suffix().matched);
-        assert(m.suffix().first == m[0].second);
-        assert(m.suffix().second == m[0].second);
-        assert(m.length(0) == 1);
-        assert(m.position(0) == 0);
-        assert(m.str(0) == "a");
-    }
-    {
-        std::cmatch m;
-        const char s[] = "c";
-        assert(std::regex_match(s, m, std::regex("^[a-f]$",
-                                                 std::regex_constants::awk)));
-        assert(m.size() == 1);
-        assert(!m.prefix().matched);
-        assert(m.prefix().first == s);
-        assert(m.prefix().second == m[0].first);
-        assert(!m.suffix().matched);
-        assert(m.suffix().first == m[0].second);
-        assert(m.suffix().second == m[0].second);
-        assert(m.length(0) == 1);
-        assert(m.position(0) == 0);
-        assert(m.str(0) == s);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "g";
-        assert(!std::regex_match(s, m, std::regex("^[a-f]$",
-                                                 std::regex_constants::awk)));
-        assert(m.size() == 0);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "Iraqi";
-        assert(!std::regex_match(s, m, std::regex("q[^u]",
-                                                 std::regex_constants::awk)));
-        assert(m.size() == 0);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "Iraq";
-        assert(!std::regex_match(s, m, std::regex("q[^u]",
-                                                 std::regex_constants::awk)));
-        assert(m.size() == 0);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "AmB";
-        assert(std::regex_match(s, m, std::regex("A[[:lower:]]B",
-                                                 std::regex_constants::awk)));
-        assert(m.size() == 1);
-        assert(!m.prefix().matched);
-        assert(m.prefix().first == s);
-        assert(m.prefix().second == m[0].first);
-        assert(!m.suffix().matched);
-        assert(m.suffix().first == m[0].second);
-        assert(m.suffix().second == m[0].second);
-        assert((std::size_t)m.length(0) == std::char_traits<char>::length(s));
-        assert(m.position(0) == 0);
-        assert(m.str(0) == s);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "AMB";
-        assert(!std::regex_match(s, m, std::regex("A[[:lower:]]B",
-                                                 std::regex_constants::awk)));
-        assert(m.size() == 0);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "AMB";
-        assert(std::regex_match(s, m, std::regex("A[^[:lower:]]B",
-                                                 std::regex_constants::awk)));
-        assert(m.size() == 1);
-        assert(!m.prefix().matched);
-        assert(m.prefix().first == s);
-        assert(m.prefix().second == m[0].first);
-        assert(!m.suffix().matched);
-        assert(m.suffix().first == m[0].second);
-        assert(m.suffix().second == m[0].second);
-        assert((std::size_t)m.length(0) == std::char_traits<char>::length(s));
-        assert(m.position(0) == 0);
-        assert(m.str(0) == s);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "AmB";
-        assert(!std::regex_match(s, m, std::regex("A[^[:lower:]]B",
-                                                 std::regex_constants::awk)));
-        assert(m.size() == 0);
-    }
-    {
-        std::cmatch m;
-        const char s[] = "A5B";
-        assert(!std::regex_match(s, m, std::regex("A[^[:lower:]0-9]B",
-                                                 std::regex...
[truncated]
 | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't format all the tests just because there might be something coming up. If there is actually something we can do that in a targeted manner instead.
| 
 Hmm, previous we formatted container tests in #126499... I think it's reasonable to format all regex tests for a similar reason too. | 
| 
 I don't know why we did that, but IMO that wasn't a good choice from what I can tell. | 
| @philnik777 Really, we should be formatting the whole code base. It's just that the patch that does that is going to be humongous, not even reviewable on Github. There's too much code. As a result, we've been reformatting smaller bits and pieces from time to time, and I think that's acceptable, if done as their own separate patch (which can then be added to  | 
| 
 I don't disagree. I do think that we should require a clear intent to modify the code in the near future though. Otherwise there isn't much of a difference between a single patch and someone feeling like formatting entire test suite. "There might be a patch at some point in the future modifying this code" IMO doesn't reach the bar of "this is reasonable to format". Re. the Container formatting, I can't remember what went on in February, so with the current information I have I don't think it was a good idea. If we were actually modifying a significant amount of tests then sure - if we only modified one or two of the tests then IMO it was too broad of a formatting. I'm not convinced that we got anywhere near modifying 1300 tests - an NFC patch to format the tests that we were actually modifying would have been the better alternative IMO. | 
| With the ongoing work in making the containers constexpr compatible, I find it was good that it was already formatted, as several new contributors joined in. | 
There is possibly upcoming overhaul for
<regex>. It would be easier to modify the test files if they are clang-formatted.Some files are manually adjusted.
Adds clang-format off/on comments to avoid line break:
Adds new lines to avoid ugly grouping for
=: