summaryrefslogtreecommitdiff
path: root/xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp')
-rw-r--r--xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp35
1 files changed, 34 insertions, 1 deletions
diff --git a/xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp b/xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp
index 7ca12d2fad..5a8139d416 100644
--- a/xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp
@@ -208,7 +208,7 @@ TEST(CXFA_FMLexerTest, Comments) {
EXPECT_EQ(TOKeof, token->m_type);
}
-TEST(CXFA_FMLexerTest, Identifiers) {
+TEST(CXFA_FMLexerTest, ValidIdentifiers) {
std::vector<const wchar_t*> identifiers = {
L"a", L"an_identifier", L"_ident", L"$ident", L"!ident", L"GetAddr"};
for (const auto* ident : identifiers) {
@@ -219,6 +219,39 @@ TEST(CXFA_FMLexerTest, Identifiers) {
}
}
+TEST(CXFA_FMLexerTest, InvalidIdentifiers) {
+ auto lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"#a");
+ lexer->NextToken();
+ // TODO(rharrison): Add an expects for the return being nullptr here.
+ // See https://crbug.com/pdfium/814
+ EXPECT_TRUE(lexer->HasError());
+
+ lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"1a");
+ lexer->NextToken();
+ // TODO(rharrison): Add an expects for the return being nullptr here.
+ // See https://crbug.com/pdfium/814
+ EXPECT_TRUE(lexer->HasError());
+
+ lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"an@identifier");
+ lexer->NextToken();
+ EXPECT_FALSE(lexer->HasError());
+ lexer->NextToken();
+ // TODO(rharrison): Add an expects for the return being nullptr here.
+ // See https://crbug.com/pdfium/814
+ EXPECT_TRUE(lexer->HasError());
+ // TODO(rharrison): Add a test for if an another call to NextToken occurs,
+ // the error state will be retained, instead of continuing the parse.
+ // See https://crbug.com/pdfium/814
+
+ lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"_ident@");
+ lexer->NextToken();
+ EXPECT_FALSE(lexer->HasError());
+ lexer->NextToken();
+ // TODO(rharrison): Add an expects for the return being nullptr here.
+ // See https://crbug.com/pdfium/814
+ EXPECT_TRUE(lexer->HasError());
+}
+
TEST(CXFA_FMLexerTest, Whitespace) {
auto lexer = pdfium::MakeUnique<CXFA_FMLexer>(L" \t\xc\x9\xb");
CXFA_FMToken* token = lexer->NextToken();