|
|
|
@ -147,6 +147,16 @@ class ParserTest : public testing::Test { |
|
|
|
|
EXPECT_EQ(io::Tokenizer::TYPE_END, input_->current().type); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Parse the text and expect that the given warnings are reported.
|
|
|
|
|
void ExpectHasWarnings(const char* text, const char* expected_warnings) { |
|
|
|
|
SetupParser(text); |
|
|
|
|
FileDescriptorProto file; |
|
|
|
|
parser_->Parse(input_.get(), &file); |
|
|
|
|
EXPECT_EQ(io::Tokenizer::TYPE_END, input_->current().type); |
|
|
|
|
ASSERT_EQ("", error_collector_.text_); |
|
|
|
|
EXPECT_EQ(expected_warnings, error_collector_.warning_); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Same as above but does not expect that the parser parses the complete
|
|
|
|
|
// input.
|
|
|
|
|
void ExpectHasEarlyExitErrors(const char* text, const char* expected_errors) { |
|
|
|
@ -1676,12 +1686,14 @@ TEST_F(ParseErrorTest, EnumReservedMissingQuotes) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(ParseErrorTest, EnumReservedInvalidIdentifier) { |
|
|
|
|
ExpectHasErrors( |
|
|
|
|
"enum TestEnum {\n" |
|
|
|
|
" FOO = 1;\n" |
|
|
|
|
" reserved \"foo bar\";\n" |
|
|
|
|
"}\n", |
|
|
|
|
"2:11: Reserved name \"foo bar\" is not a valid identifier.\n"); |
|
|
|
|
ExpectHasWarnings( |
|
|
|
|
R"pb( |
|
|
|
|
enum TestEnum { |
|
|
|
|
FOO = 1; |
|
|
|
|
reserved "foo bar"; |
|
|
|
|
} |
|
|
|
|
)pb", |
|
|
|
|
"3:17: Reserved name \"foo bar\" is not a valid identifier.\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
@ -1712,11 +1724,13 @@ TEST_F(ParseErrorTest, ReservedMissingQuotes) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(ParseErrorTest, ReservedInvalidIdentifier) { |
|
|
|
|
ExpectHasErrors( |
|
|
|
|
"message Foo {\n" |
|
|
|
|
" reserved \"foo bar\";\n" |
|
|
|
|
"}\n", |
|
|
|
|
"1:11: Reserved name \"foo bar\" is not a valid identifier.\n"); |
|
|
|
|
ExpectHasWarnings( |
|
|
|
|
R"pb( |
|
|
|
|
message Foo { |
|
|
|
|
reserved "foo bar"; |
|
|
|
|
} |
|
|
|
|
)pb", |
|
|
|
|
"2:17: Reserved name \"foo bar\" is not a valid identifier.\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(ParseErrorTest, ReservedNegativeNumber) { |
|
|
|
|