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

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

Issue 1525183002: tools/gn: rename char_offset to column_number (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix indentation Created 5 years 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/parse_tree_unittest.cc ('k') | tools/gn/string_utils.cc » ('j') | 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 <iostream> 5 #include <iostream>
6 #include <sstream> 6 #include <sstream>
7 7
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "tools/gn/input_file.h" 9 #include "tools/gn/input_file.h"
10 #include "tools/gn/parser.h" 10 #include "tools/gn/parser.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 61
62 Err err; 62 Err err;
63 std::vector<Token> tokens = Tokenizer::Tokenize(&input_file, &err); 63 std::vector<Token> tokens = Tokenizer::Tokenize(&input_file, &err);
64 if (!err.has_error()) { 64 if (!err.has_error()) {
65 scoped_ptr<ParseNode> result = Parser::Parse(tokens, &err); 65 scoped_ptr<ParseNode> result = Parser::Parse(tokens, &err);
66 ASSERT_FALSE(result); 66 ASSERT_FALSE(result);
67 ASSERT_TRUE(err.has_error()); 67 ASSERT_TRUE(err.has_error());
68 } 68 }
69 69
70 EXPECT_EQ(err_line, err.location().line_number()); 70 EXPECT_EQ(err_line, err.location().line_number());
71 EXPECT_EQ(err_char, err.location().char_offset()); 71 EXPECT_EQ(err_char, err.location().column_number());
72 } 72 }
73 73
74 // Expects the tokenizer or parser to identify an error at the given line and 74 // Expects the tokenizer or parser to identify an error at the given line and
75 // character. 75 // character.
76 void DoExpressionErrorTest(const char* input, int err_line, int err_char) { 76 void DoExpressionErrorTest(const char* input, int err_line, int err_char) {
77 InputFile input_file(SourceFile("/test")); 77 InputFile input_file(SourceFile("/test"));
78 input_file.SetContents(input); 78 input_file.SetContents(input);
79 79
80 Err err; 80 Err err;
81 std::vector<Token> tokens = Tokenizer::Tokenize(&input_file, &err); 81 std::vector<Token> tokens = Tokenizer::Tokenize(&input_file, &err);
82 if (!err.has_error()) { 82 if (!err.has_error()) {
83 scoped_ptr<ParseNode> result = Parser::ParseExpression(tokens, &err); 83 scoped_ptr<ParseNode> result = Parser::ParseExpression(tokens, &err);
84 ASSERT_FALSE(result); 84 ASSERT_FALSE(result);
85 ASSERT_TRUE(err.has_error()); 85 ASSERT_TRUE(err.has_error());
86 } 86 }
87 87
88 EXPECT_EQ(err_line, err.location().line_number()); 88 EXPECT_EQ(err_line, err.location().line_number());
89 EXPECT_EQ(err_char, err.location().char_offset()); 89 EXPECT_EQ(err_char, err.location().column_number());
90 } 90 }
91 91
92 } // namespace 92 } // namespace
93 93
94 TEST(Parser, Literal) { 94 TEST(Parser, Literal) {
95 DoExpressionPrintTest("5", "LITERAL(5)\n"); 95 DoExpressionPrintTest("5", "LITERAL(5)\n");
96 DoExpressionPrintTest("\"stuff\"", "LITERAL(\"stuff\")\n"); 96 DoExpressionPrintTest("\"stuff\"", "LITERAL(\"stuff\")\n");
97 } 97 }
98 98
99 TEST(Parser, BinaryOp) { 99 TEST(Parser, BinaryOp) {
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 // freestanding block. 702 // freestanding block.
703 TEST(Parser, StandaloneBlock) { 703 TEST(Parser, StandaloneBlock) {
704 DoParserErrorTest( 704 DoParserErrorTest(
705 "if (true) {\n" 705 "if (true) {\n"
706 "}\n" 706 "}\n"
707 "{\n" 707 "{\n"
708 " assert(false)\n" 708 " assert(false)\n"
709 "}\n", 709 "}\n",
710 3, 1); 710 3, 1);
711 } 711 }
OLDNEW
« no previous file with comments | « tools/gn/parse_tree_unittest.cc ('k') | tools/gn/string_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698