Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: tools/gn/tokenizer_unittest.cc

Issue 595753002: gn: handle continued suffix comments (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gn-append-comment
Patch Set: only continue if at same column Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/gn/tokenizer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/input_file.h" 6 #include "tools/gn/input_file.h"
7 #include "tools/gn/token.h" 7 #include "tools/gn/token.h"
8 #include "tools/gn/tokenizer.h" 8 #include "tools/gn/tokenizer.h"
9 9
10 namespace { 10 namespace {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 { Token::LEFT_BRACE, "{" }, 173 { Token::LEFT_BRACE, "{" },
174 { Token::SUFFIX_COMMENT, "# Things" }, 174 { Token::SUFFIX_COMMENT, "# Things" },
175 { Token::LINE_COMMENT, "#Wee" }, 175 { Token::LINE_COMMENT, "#Wee" },
176 { Token::IDENTIFIER, "foo" }, 176 { Token::IDENTIFIER, "foo" },
177 { Token::EQUAL, "=" }, 177 { Token::EQUAL, "=" },
178 { Token::INTEGER, "12" }, 178 { Token::INTEGER, "12" },
179 { Token::SUFFIX_COMMENT, "#Zip" }, 179 { Token::SUFFIX_COMMENT, "#Zip" },
180 { Token::RIGHT_BRACE, "}" }, 180 { Token::RIGHT_BRACE, "}" },
181 }; 181 };
182 EXPECT_TRUE(CheckTokenizer( 182 EXPECT_TRUE(CheckTokenizer(
183 "# Stuff\nfun(\"foo\") { # Things\n#Wee\nfoo = 12 #Zip\n}", fn)); 183 "# Stuff\n"
184 "fun(\"foo\") { # Things\n"
185 "#Wee\n"
186 "foo = 12 #Zip\n"
187 "}",
188 fn));
184 } 189 }
190
191 TEST(Tokenizer, CommentsContinued) {
192 // In the first test, the comments aren't horizontally aligned, so they're
193 // considered separate. In the second test, they are, so "B" is a
194 // continuation of "A" (another SUFFIX comment).
195 TokenExpectation fn1[] = {
196 { Token::IDENTIFIER, "fun" },
197 { Token::LEFT_PAREN, "(" },
198 { Token::STRING, "\"foo\"" },
199 { Token::RIGHT_PAREN, ")" },
200 { Token::LEFT_BRACE, "{" },
201 { Token::SUFFIX_COMMENT, "# A" },
202 { Token::LINE_COMMENT, "# B" },
203 { Token::RIGHT_BRACE, "}" },
204 };
205 EXPECT_TRUE(CheckTokenizer(
206 "fun(\"foo\") { # A\n"
207 " # B\n"
208 "}",
209 fn1));
210
211 TokenExpectation fn2[] = {
212 { Token::IDENTIFIER, "fun" },
213 { Token::LEFT_PAREN, "(" },
214 { Token::STRING, "\"foo\"" },
215 { Token::RIGHT_PAREN, ")" },
216 { Token::LEFT_BRACE, "{" },
217 { Token::SUFFIX_COMMENT, "# A" },
218 { Token::SUFFIX_COMMENT, "# B" },
219 { Token::RIGHT_BRACE, "}" },
220 };
221 EXPECT_TRUE(CheckTokenizer(
222 "fun(\"foo\") { # A\n"
223 " # B\n" // Note that these are aligned, the \"s move A out.
224 "}",
225 fn2));
226 }
OLDNEW
« no previous file with comments | « tools/gn/tokenizer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698