summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/gn/c_include_iterator.cc2
-rw-r--r--tools/gn/c_include_iterator_unittest.cc23
2 files changed, 25 insertions, 0 deletions
diff --git a/tools/gn/c_include_iterator.cc b/tools/gn/c_include_iterator.cc
index 9e719c7..120295e 100644
--- a/tools/gn/c_include_iterator.cc
+++ b/tools/gn/c_include_iterator.cc
@@ -48,6 +48,8 @@ base::StringPiece TrimLeadingWhitespace(const base::StringPiece& str) {
bool ShouldCountTowardNonIncludeLines(const base::StringPiece& line) {
if (StartsWith(line, "//"))
return false; // Don't count comments.
+ if (StartsWith(line, "/*") || StartsWith(line, " *"))
+ return false; // C-style comment blocks with stars along the left side.
if (StartsWith(line, "#"))
return false; // Don't count preprocessor.
if (base::ContainsOnlyChars(line, base::kWhitespaceASCII))
diff --git a/tools/gn/c_include_iterator_unittest.cc b/tools/gn/c_include_iterator_unittest.cc
index 11fa991..1add29b5 100644
--- a/tools/gn/c_include_iterator_unittest.cc
+++ b/tools/gn/c_include_iterator_unittest.cc
@@ -132,3 +132,26 @@ TEST(CIncludeIterator, TolerateNonIncludes) {
}
EXPECT_FALSE(iter.GetNextIncludeString(&contents, &range));
}
+
+// Tests that comments of the form
+// /*
+// *
+// */
+// are not counted toward the non-include line count.
+TEST(CIncludeIterator, CStyleComments) {
+ std::string buffer("/*");
+ for (size_t i = 0; i < 1000; i++)
+ buffer.append(" *\n");
+ buffer.append(" */\n\n");
+ buffer.append("#include \"foo/bar.h\"\n");
+
+ InputFile file(SourceFile("//foo.cc"));
+ file.SetContents(buffer);
+
+ base::StringPiece contents;
+ LocationRange range;
+
+ CIncludeIterator iter(&file);
+ EXPECT_TRUE(iter.GetNextIncludeString(&contents, &range));
+ EXPECT_EQ("foo/bar.h", contents);
+}