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 { |
11 | 11 |
12 bool RangeIs(const LocationRange& range, | 12 bool RangeIs(const LocationRange& range, |
13 int line, int begin_char, int end_char) { | 13 int line, int begin_char, int end_char) { |
14 return range.begin().line_number() == line && | 14 return range.begin().line_number() == line && |
15 range.end().line_number() == line && | 15 range.end().line_number() == line && |
16 range.begin().char_offset() == begin_char && | 16 range.begin().column_number() == begin_char && |
17 range.end().char_offset() == end_char; | 17 range.end().column_number() == end_char; |
18 } | 18 } |
19 | 19 |
20 } // namespace | 20 } // namespace |
21 | 21 |
22 TEST(CIncludeIterator, Basic) { | 22 TEST(CIncludeIterator, Basic) { |
23 std::string buffer; | 23 std::string buffer; |
24 buffer.append("// Some comment\n"); | 24 buffer.append("// Some comment\n"); |
25 buffer.append("\n"); | 25 buffer.append("\n"); |
26 buffer.append("#include \"foo/bar.h\"\n"); | 26 buffer.append("#include \"foo/bar.h\"\n"); |
27 buffer.append("\n"); | 27 buffer.append("\n"); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 InputFile file(SourceFile("//foo.cc")); | 148 InputFile file(SourceFile("//foo.cc")); |
149 file.SetContents(buffer); | 149 file.SetContents(buffer); |
150 | 150 |
151 base::StringPiece contents; | 151 base::StringPiece contents; |
152 LocationRange range; | 152 LocationRange range; |
153 | 153 |
154 CIncludeIterator iter(&file); | 154 CIncludeIterator iter(&file); |
155 EXPECT_TRUE(iter.GetNextIncludeString(&contents, &range)); | 155 EXPECT_TRUE(iter.GetNextIncludeString(&contents, &range)); |
156 EXPECT_EQ("foo/bar.h", contents); | 156 EXPECT_EQ("foo/bar.h", contents); |
157 } | 157 } |
OLD | NEW |