Skip to content

Commit 32680f6

Browse files
committed
add test for unicode escaping
1 parent 2e18159 commit 32680f6

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/ParserTests.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,36 @@ TEST(ParserTests, RejectsUnicodeEscapeWithBadChars) {
131131
expectError("{ field(arg:\"\\uXXXF\") }", "1.13-15: bad Unicode escape sequence");
132132
}
133133

134+
TEST(ParserTests, AcceptsValidUnicodeEscape) {
135+
const char *actualError = nullptr;
136+
auto ast = parseString("{ field(arg:\"\\u0009Hello\") }", &actualError);
137+
138+
EXPECT_TRUE(ast != nullptr);
139+
EXPECT_STREQ(nullptr, actualError);
140+
std::free((void *)actualError);
141+
142+
auto doc = dynamic_cast<Document *>(ast.get());
143+
ASSERT_TRUE(doc != nullptr);
144+
145+
const auto& defs = doc->getDefinitions();
146+
ASSERT_EQ(1, defs.size());
147+
148+
auto opDef = dynamic_cast<OperationDefinition *>(defs[0].get());
149+
ASSERT_TRUE(opDef != nullptr);
150+
151+
ASSERT_EQ(1, opDef->getSelectionSet().getSelections().size());
152+
153+
auto field = dynamic_cast<Field *>(opDef->getSelectionSet().getSelections()[0].get());
154+
ASSERT_TRUE(field != nullptr);
155+
156+
auto *args = field->getArguments();
157+
ASSERT_NE(nullptr, args);
158+
ASSERT_EQ(1, args->size());
159+
auto *val = dynamic_cast<const StringValue *>(&(*args)[0]->getValue());
160+
ASSERT_NE(nullptr, val);
161+
EXPECT_STREQ("\tHello", val->getValue());
162+
}
163+
134164
TEST(ParserTests, TracksLocationAcrossStrings) {
135165
expectError("{ field(arg:\"\\uFEFF\\n\") };",
136166
"1.26: unrecognized character ;");

0 commit comments

Comments
 (0)