OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 #include "tools/gn/c_include_iterator.h" | 6 #include "tools/gn/c_include_iterator.h" |
7 #include "tools/gn/input_file.h" | 7 #include "tools/gn/input_file.h" |
8 #include "tools/gn/location.h" | 8 #include "tools/gn/location.h" |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 base::StringPiece contents; | 125 base::StringPiece contents; |
126 LocationRange range; | 126 LocationRange range; |
127 | 127 |
128 CIncludeIterator iter(&file); | 128 CIncludeIterator iter(&file); |
129 for (size_t group = 0; group < kGroupCount; group++) { | 129 for (size_t group = 0; group < kGroupCount; group++) { |
130 EXPECT_TRUE(iter.GetNextIncludeString(&contents, &range)); | 130 EXPECT_TRUE(iter.GetNextIncludeString(&contents, &range)); |
131 EXPECT_EQ(include, contents.as_string()); | 131 EXPECT_EQ(include, contents.as_string()); |
132 } | 132 } |
133 EXPECT_FALSE(iter.GetNextIncludeString(&contents, &range)); | 133 EXPECT_FALSE(iter.GetNextIncludeString(&contents, &range)); |
134 } | 134 } |
| 135 |
| 136 // Tests that comments of the form |
| 137 // /* |
| 138 // * |
| 139 // */ |
| 140 // are not counted toward the non-include line count. |
| 141 TEST(CIncludeIterator, CStyleComments) { |
| 142 std::string buffer("/*"); |
| 143 for (size_t i = 0; i < 1000; i++) |
| 144 buffer.append(" *\n"); |
| 145 buffer.append(" */\n\n"); |
| 146 buffer.append("#include \"foo/bar.h\"\n"); |
| 147 |
| 148 InputFile file(SourceFile("//foo.cc")); |
| 149 file.SetContents(buffer); |
| 150 |
| 151 base::StringPiece contents; |
| 152 LocationRange range; |
| 153 |
| 154 CIncludeIterator iter(&file); |
| 155 EXPECT_TRUE(iter.GetNextIncludeString(&contents, &range)); |
| 156 EXPECT_EQ("foo/bar.h", contents); |
| 157 } |
OLD | NEW |