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