Skip to content

Commit 548a3e3

Browse files
committed
Add a unit test for #222
1 parent 4784cad commit 548a3e3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

test/PegtlExecutableTests.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,30 @@ TEST(PegtlExecutableCase, AnalyzeExecutableGrammar)
139139
ASSERT_EQ(size_t { 0 }, analyze<executable_document>(true))
140140
<< "there shouldn't be any infinite loops in the PEG version of the grammar";
141141
}
142+
143+
TEST(PegtlExecutableCase, InvalidStringEscapeSequence)
144+
{
145+
bool parsedQuery = false;
146+
bool caughtException = false;
147+
148+
try
149+
{
150+
memory_input<> input(R"gql(query { foo @something(arg: "\.") })gql",
151+
"InvalidStringEscapeSequence");
152+
parsedQuery = parse<executable_document>(input);
153+
}
154+
catch (const peg::parse_error& e)
155+
{
156+
using namespace std::literals;
157+
158+
ASSERT_NE(nullptr, e.what());
159+
EXPECT_EQ("InvalidStringEscapeSequence:1:31: parse error matching struct "
160+
"graphql::peg::string_escape_sequence_content"sv,
161+
e.what())
162+
<< "should get an appropriate parser error message";
163+
caughtException = true;
164+
}
165+
166+
EXPECT_TRUE(caughtException) << "should catch a parse exception";
167+
EXPECT_FALSE(parsedQuery) << "should not successfully parse the query";
168+
}

0 commit comments

Comments
 (0)