[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cfe-commits
Subject:    [PATCH] D138402: [clang-format] Correctly count a tab's width in a comment
From:       Björn_Schäpers_via_Phabricator via cfe-commits <cfe-commit
Date:       2022-11-30 21:11:58
Message-ID: w8ozkHevRvyYvxKyKHtGmg () geopod-ismtpd-2-4
[Download RAW message or body]

HazardyKnusperkeks updated this revision to Diff 479054.
HazardyKnusperkeks marked an inline comment as done.
HazardyKnusperkeks added a reviewer: klimek.
HazardyKnusperkeks added a comment.

Pulled the `verifyFormat` into this change.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138402/new/

https://reviews.llvm.org/D138402

Files:
  clang/lib/Format/BreakableToken.cpp
  clang/unittests/Format/FormatTestComments.cpp


Index: clang/unittests/Format/FormatTestComments.cpp
===================================================================
--- clang/unittests/Format/FormatTestComments.cpp
+++ clang/unittests/Format/FormatTestComments.cpp
@@ -67,6 +67,13 @@
     EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
   }
 
+  void verifyFormat(llvm::StringRef Expected, llvm::StringRef Code,
+                    const FormatStyle &Style = getLLVMStyle()) {
+    EXPECT_EQ(Expected.str(), format(Expected, Style))
+        << "Expected code is not stable";
+    EXPECT_EQ(Expected.str(), format(test::messUp(Code), Style));
+  }
+
   void verifyGoogleFormat(llvm::StringRef Code) {
     verifyFormat(Code, getGoogleStyle());
   }
@@ -715,6 +722,11 @@
             "//: one line",
             format("//: A comment that doesn't fit on one line",
                    getLLVMStyleWithColumns(20)));
+
+  verifyFormat(
+      "//\t\t\t\tofMap(message.velocity, 0, 127, 0, ofGetWidth()\n"
+      "//* 0.2)",
+      "//\t\t\t\tofMap(message.velocity, 0, 127, 0, ofGetWidth() * 0.2)");
 }
 
 TEST_F(FormatTestComments, PreservesHangingIndentInCxxComments) {
Index: clang/lib/Format/BreakableToken.cpp
===================================================================
--- clang/lib/Format/BreakableToken.cpp
+++ clang/lib/Format/BreakableToken.cpp
@@ -82,9 +82,9 @@
        NumChars < MaxSplit && MaxSplitBytes < Text.size();) {
     unsigned BytesInChar =
         encoding::getCodePointNumBytes(Text[MaxSplitBytes], Encoding);
-    NumChars +=
-        encoding::columnWidthWithTabs(Text.substr(MaxSplitBytes, BytesInChar),
-                                      ContentStartColumn, TabWidth, Encoding);
+    NumChars += encoding::columnWidthWithTabs(
+        Text.substr(MaxSplitBytes, BytesInChar), ContentStartColumn + NumChars,
+        TabWidth, Encoding);
     MaxSplitBytes += BytesInChar;
   }
 



["D138402.479054.patch" (D138402.479054.patch)]

Index: clang/unittests/Format/FormatTestComments.cpp
===================================================================
--- clang/unittests/Format/FormatTestComments.cpp
+++ clang/unittests/Format/FormatTestComments.cpp
@@ -67,6 +67,13 @@
     EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
   }
 
+  void verifyFormat(llvm::StringRef Expected, llvm::StringRef Code,
+                    const FormatStyle &Style = getLLVMStyle()) {
+    EXPECT_EQ(Expected.str(), format(Expected, Style))
+        << "Expected code is not stable";
+    EXPECT_EQ(Expected.str(), format(test::messUp(Code), Style));
+  }
+
   void verifyGoogleFormat(llvm::StringRef Code) {
     verifyFormat(Code, getGoogleStyle());
   }
@@ -715,6 +722,11 @@
             "//: one line",
             format("//: A comment that doesn't fit on one line",
                    getLLVMStyleWithColumns(20)));
+
+  verifyFormat(
+      "//\t\t\t\tofMap(message.velocity, 0, 127, 0, ofGetWidth()\n"
+      "//* 0.2)",
+      "//\t\t\t\tofMap(message.velocity, 0, 127, 0, ofGetWidth() * 0.2)");
 }
 
 TEST_F(FormatTestComments, PreservesHangingIndentInCxxComments) {
Index: clang/lib/Format/BreakableToken.cpp
===================================================================
--- clang/lib/Format/BreakableToken.cpp
+++ clang/lib/Format/BreakableToken.cpp
@@ -82,9 +82,9 @@
        NumChars < MaxSplit && MaxSplitBytes < Text.size();) {
     unsigned BytesInChar =
         encoding::getCodePointNumBytes(Text[MaxSplitBytes], Encoding);
-    NumChars +=
-        encoding::columnWidthWithTabs(Text.substr(MaxSplitBytes, BytesInChar),
-                                      ContentStartColumn, TabWidth, Encoding);
+    NumChars += encoding::columnWidthWithTabs(
+        Text.substr(MaxSplitBytes, BytesInChar), ContentStartColumn + NumChars,
+        TabWidth, Encoding);
     MaxSplitBytes += BytesInChar;
   }
 

[Attachment #4 (text/plain)]

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic