OLD | NEW |
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 Loading... |
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 } |
OLD | NEW |