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.cpp135
1 files changed, 71 insertions, 64 deletions
diff --git a/xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp b/xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp
index a6ab871b18..00dc494582 100644
--- a/xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp
@@ -12,86 +12,86 @@
TEST(CXFA_FMLexerTest, EmptyString) {
CXFA_FMLexer lexer(L"");
- std::unique_ptr<CXFA_FMToken> token = lexer.NextToken();
- EXPECT_EQ(TOKeof, token->m_type);
+ CXFA_FMToken token = lexer.NextToken();
+ EXPECT_EQ(TOKeof, token.m_type);
}
TEST(CXFA_FMLexerTest, Numbers) {
auto lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"-12");
- std::unique_ptr<CXFA_FMToken> token = lexer->NextToken();
+ CXFA_FMToken token = lexer->NextToken();
// TODO(dsinclair): Should this return -12 instead of two tokens?
- EXPECT_EQ(TOKminus, token->m_type);
+ EXPECT_EQ(TOKminus, token.m_type);
token = lexer->NextToken();
- EXPECT_EQ(L"12", token->m_string);
+ EXPECT_EQ(L"12", token.m_string);
token = lexer->NextToken();
- EXPECT_EQ(TOKeof, token->m_type);
+ EXPECT_EQ(TOKeof, token.m_type);
lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"1.5362");
token = lexer->NextToken();
- EXPECT_EQ(TOKnumber, token->m_type);
- EXPECT_EQ(L"1.5362", token->m_string);
+ EXPECT_EQ(TOKnumber, token.m_type);
+ EXPECT_EQ(L"1.5362", token.m_string);
lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"0.875");
token = lexer->NextToken();
- EXPECT_EQ(TOKnumber, token->m_type);
- EXPECT_EQ(L"0.875", token->m_string);
+ EXPECT_EQ(TOKnumber, token.m_type);
+ EXPECT_EQ(L"0.875", token.m_string);
lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"5.56e-2");
token = lexer->NextToken();
- EXPECT_EQ(TOKnumber, token->m_type);
- EXPECT_EQ(L"5.56e-2", token->m_string);
+ EXPECT_EQ(TOKnumber, token.m_type);
+ EXPECT_EQ(L"5.56e-2", token.m_string);
lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"1.234E10");
token = lexer->NextToken();
- EXPECT_EQ(TOKnumber, token->m_type);
- EXPECT_EQ(L"1.234E10", token->m_string);
+ EXPECT_EQ(TOKnumber, token.m_type);
+ EXPECT_EQ(L"1.234E10", token.m_string);
lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"123456789.012345678");
token = lexer->NextToken();
- EXPECT_EQ(TOKnumber, token->m_type);
+ EXPECT_EQ(TOKnumber, token.m_type);
// TODO(dsinclair): This should round as per IEEE 64-bit values.
- // EXPECT_EQ(L"123456789.01234567", token->m_string);
- EXPECT_EQ(L"123456789.012345678", token->m_string);
+ // EXPECT_EQ(L"123456789.01234567", token.m_string);
+ EXPECT_EQ(L"123456789.012345678", token.m_string);
lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"99999999999999999");
token = lexer->NextToken();
- EXPECT_EQ(TOKnumber, token->m_type);
+ EXPECT_EQ(TOKnumber, token.m_type);
// TODO(dsinclair): This is spec'd as rounding when > 16 significant digits
// prior to the exponent.
- // EXPECT_EQ(L"100000000000000000", token->m_string);
- EXPECT_EQ(L"99999999999999999", token->m_string);
+ // EXPECT_EQ(L"100000000000000000", token.m_string);
+ EXPECT_EQ(L"99999999999999999", token.m_string);
}
// The quotes are stripped in CXFA_FMStringExpression::ToJavaScript.
TEST(CXFA_FMLexerTest, Strings) {
auto lexer =
pdfium::MakeUnique<CXFA_FMLexer>(L"\"The cat jumped over the fence.\"");
- std::unique_ptr<CXFA_FMToken> token = lexer->NextToken();
- EXPECT_EQ(TOKstring, token->m_type);
- EXPECT_EQ(L"\"The cat jumped over the fence.\"", token->m_string);
+ CXFA_FMToken token = lexer->NextToken();
+ EXPECT_EQ(TOKstring, token.m_type);
+ EXPECT_EQ(L"\"The cat jumped over the fence.\"", token.m_string);
token = lexer->NextToken();
- EXPECT_EQ(TOKeof, token->m_type);
+ EXPECT_EQ(TOKeof, token.m_type);
lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"\"\"");
token = lexer->NextToken();
- EXPECT_EQ(TOKstring, token->m_type);
- EXPECT_EQ(L"\"\"", token->m_string);
+ EXPECT_EQ(TOKstring, token.m_type);
+ EXPECT_EQ(L"\"\"", token.m_string);
lexer = pdfium::MakeUnique<CXFA_FMLexer>(
L"\"The message reads: \"\"Warning: Insufficient Memory\"\"\"");
token = lexer->NextToken();
- EXPECT_EQ(TOKstring, token->m_type);
+ EXPECT_EQ(TOKstring, token.m_type);
EXPECT_EQ(L"\"The message reads: \"\"Warning: Insufficient Memory\"\"\"",
- token->m_string);
+ token.m_string);
lexer = pdfium::MakeUnique<CXFA_FMLexer>(
L"\"\\u0047\\u006f\\u0066\\u0069\\u0073\\u0068\\u0021\\u000d\\u000a\"");
token = lexer->NextToken();
- EXPECT_EQ(TOKstring, token->m_type);
+ EXPECT_EQ(TOKstring, token.m_type);
EXPECT_EQ(
L"\"\\u0047\\u006f\\u0066\\u0069\\u0073\\u0068\\u0021\\u000d\\u000a\"",
- token->m_string);
+ token.m_string);
}
// Note, 'this' is a keyword but is not matched by the lexer.
@@ -161,51 +161,51 @@ TEST(CXFA_FMLexerTest, OperatorsAndKeywords) {
for (size_t i = 0; i < FX_ArraySize(op); ++i) {
auto lexer = pdfium::MakeUnique<CXFA_FMLexer>(op[i].op);
- std::unique_ptr<CXFA_FMToken> token = lexer->NextToken();
- EXPECT_EQ(op[i].token, token->m_type);
+ CXFA_FMToken token = lexer->NextToken();
+ EXPECT_EQ(op[i].token, token.m_type);
}
}
TEST(CXFA_FMLexerTest, Comments) {
auto lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"// Empty.");
- std::unique_ptr<CXFA_FMToken> token = lexer->NextToken();
- EXPECT_EQ(TOKeof, token->m_type);
+ CXFA_FMToken token = lexer->NextToken();
+ EXPECT_EQ(TOKeof, token.m_type);
lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"//");
token = lexer->NextToken();
- EXPECT_EQ(TOKeof, token->m_type);
+ EXPECT_EQ(TOKeof, token.m_type);
lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"123 // Empty.\n\"str\"");
token = lexer->NextToken();
- EXPECT_EQ(TOKnumber, token->m_type);
- EXPECT_EQ(L"123", token->m_string);
+ EXPECT_EQ(TOKnumber, token.m_type);
+ EXPECT_EQ(L"123", token.m_string);
token = lexer->NextToken();
- EXPECT_EQ(TOKstring, token->m_type);
- EXPECT_EQ(L"\"str\"", token->m_string);
+ EXPECT_EQ(TOKstring, token.m_type);
+ EXPECT_EQ(L"\"str\"", token.m_string);
token = lexer->NextToken();
- EXPECT_EQ(TOKeof, token->m_type);
+ EXPECT_EQ(TOKeof, token.m_type);
lexer = pdfium::MakeUnique<CXFA_FMLexer>(L";");
token = lexer->NextToken();
- EXPECT_EQ(TOKeof, token->m_type);
+ EXPECT_EQ(TOKeof, token.m_type);
lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"; Empty.");
token = lexer->NextToken();
- EXPECT_EQ(TOKeof, token->m_type);
+ EXPECT_EQ(TOKeof, token.m_type);
lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"123 ;Empty.\n\"str\"");
token = lexer->NextToken();
- EXPECT_EQ(TOKnumber, token->m_type);
- EXPECT_EQ(L"123", token->m_string);
+ EXPECT_EQ(TOKnumber, token.m_type);
+ EXPECT_EQ(L"123", token.m_string);
token = lexer->NextToken();
- EXPECT_EQ(TOKstring, token->m_type);
- EXPECT_EQ(L"\"str\"", token->m_string);
+ EXPECT_EQ(TOKstring, token.m_type);
+ EXPECT_EQ(L"\"str\"", token.m_string);
token = lexer->NextToken();
- EXPECT_EQ(TOKeof, token->m_type);
+ EXPECT_EQ(TOKeof, token.m_type);
}
TEST(CXFA_FMLexerTest, ValidIdentifiers) {
@@ -213,43 +213,50 @@ TEST(CXFA_FMLexerTest, ValidIdentifiers) {
L"a", L"an_identifier", L"_ident", L"$ident", L"!ident", L"GetAddr"};
for (const auto* ident : identifiers) {
auto lexer = pdfium::MakeUnique<CXFA_FMLexer>(ident);
- std::unique_ptr<CXFA_FMToken> token = lexer->NextToken();
- EXPECT_EQ(TOKidentifier, token->m_type);
- EXPECT_EQ(ident, token->m_string);
+ CXFA_FMToken token = lexer->NextToken();
+ EXPECT_EQ(TOKidentifier, token.m_type);
+ EXPECT_EQ(ident, token.m_string);
}
}
TEST(CXFA_FMLexerTest, InvalidIdentifiers) {
auto lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"#a");
- EXPECT_EQ(nullptr, lexer->NextToken());
+ auto token = lexer->NextToken();
+ EXPECT_EQ(TOKreserver, token.m_type);
lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"1a");
- EXPECT_EQ(nullptr, lexer->NextToken());
+ token = lexer->NextToken();
+ EXPECT_EQ(TOKreserver, token.m_type);
lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"an@identifier");
- EXPECT_NE(nullptr, lexer->NextToken());
- EXPECT_EQ(nullptr, lexer->NextToken());
- EXPECT_EQ(nullptr, lexer->NextToken());
+ token = lexer->NextToken();
+ EXPECT_NE(TOKreserver, token.m_type);
+ token = lexer->NextToken();
+ EXPECT_EQ(TOKreserver, token.m_type);
+ token = lexer->NextToken();
+ EXPECT_EQ(TOKreserver, token.m_type);
lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"_ident@");
- EXPECT_NE(nullptr, lexer->NextToken());
- EXPECT_EQ(nullptr, lexer->NextToken());
+ token = lexer->NextToken();
+ EXPECT_NE(TOKreserver, token.m_type);
+ token = lexer->NextToken();
+ EXPECT_EQ(TOKreserver, token.m_type);
}
TEST(CXFA_FMLexerTest, Whitespace) {
auto lexer = pdfium::MakeUnique<CXFA_FMLexer>(L" \t\xc\x9\xb");
- std::unique_ptr<CXFA_FMToken> token = lexer->NextToken();
- EXPECT_EQ(TOKeof, token->m_type);
+ CXFA_FMToken token = lexer->NextToken();
+ EXPECT_EQ(TOKeof, token.m_type);
lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"123 \t\xc\x9\xb 456");
token = lexer->NextToken();
- EXPECT_EQ(TOKnumber, token->m_type);
- EXPECT_EQ(L"123", token->m_string);
+ EXPECT_EQ(TOKnumber, token.m_type);
+ EXPECT_EQ(L"123", token.m_string);
token = lexer->NextToken();
- EXPECT_EQ(TOKnumber, token->m_type);
- EXPECT_EQ(L"456", token->m_string);
+ EXPECT_EQ(TOKnumber, token.m_type);
+ EXPECT_EQ(L"456", token.m_string);
token = lexer->NextToken();
- EXPECT_EQ(TOKeof, token->m_type);
+ EXPECT_EQ(TOKeof, token.m_type);
}