summaryrefslogtreecommitdiff
path: root/xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp')
-rw-r--r--xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp82
1 files changed, 69 insertions, 13 deletions
diff --git a/xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp b/xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp
index e939cd954f..a7f7006fcc 100644
--- a/xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp
@@ -14,20 +14,20 @@
TEST(CXFA_FMParserTest, Empty) {
auto parser = pdfium::MakeUnique<CXFA_FMParser>(L"");
- std::unique_ptr<CXFA_FMFunctionDefinition> ast = parser->Parse();
+ std::unique_ptr<CXFA_FMAST> ast = parser->Parse();
ASSERT(ast != nullptr);
EXPECT_FALSE(parser->HasError());
CXFA_FMToJavaScriptDepth::Reset();
CFX_WideTextBuf buf;
- EXPECT_TRUE(ast->ToJavaScript(buf, ReturnType::kInfered));
+ EXPECT_TRUE(ast->ToJavaScript(buf));
// TODO(dsinclair): This is a little weird .....
EXPECT_EQ(L"// comments only", buf.AsStringView());
}
TEST(CXFA_FMParserTest, CommentOnlyIsError) {
auto parser = pdfium::MakeUnique<CXFA_FMParser>(L"; Just comment");
- std::unique_ptr<CXFA_FMFunctionDefinition> ast = parser->Parse();
+ std::unique_ptr<CXFA_FMAST> ast = parser->Parse();
ASSERT(ast != nullptr);
// TODO(dsinclair): This isn't allowed per the spec.
EXPECT_FALSE(parser->HasError());
@@ -35,26 +35,26 @@ TEST(CXFA_FMParserTest, CommentOnlyIsError) {
CXFA_FMToJavaScriptDepth::Reset();
CFX_WideTextBuf buf;
- EXPECT_TRUE(ast->ToJavaScript(buf, ReturnType::kInfered));
+ EXPECT_TRUE(ast->ToJavaScript(buf));
EXPECT_EQ(L"// comments only", buf.AsStringView());
}
TEST(CXFA_FMParserTest, CommentThenValue) {
const wchar_t ret[] =
- L"(\nfunction ()\n{\n"
+ L"(function() {\n"
L"var pfm_ret = null;\n"
L"pfm_ret = 12;\n"
L"return pfm_rt.get_val(pfm_ret);\n"
- L"}\n).call(this);\n";
+ L"}).call(this);";
auto parser = pdfium::MakeUnique<CXFA_FMParser>(L"; Just comment\n12");
- std::unique_ptr<CXFA_FMFunctionDefinition> ast = parser->Parse();
+ std::unique_ptr<CXFA_FMAST> ast = parser->Parse();
ASSERT(ast != nullptr);
EXPECT_FALSE(parser->HasError());
CXFA_FMToJavaScriptDepth::Reset();
CFX_WideTextBuf buf;
- EXPECT_TRUE(ast->ToJavaScript(buf, ReturnType::kInfered));
+ EXPECT_TRUE(ast->ToJavaScript(buf));
EXPECT_EQ(ret, buf.AsStringView());
}
@@ -74,7 +74,7 @@ TEST(CXFA_FMParserTest, Parse) {
L"$";
const wchar_t ret[] =
- L"(\nfunction ()\n{\n"
+ L"(function() {\n"
L"var pfm_ret = null;\n"
L"if (pfm_rt.is_obj(this))\n{\n"
L"pfm_rt.asgn_val_op(this, pfm_rt.Avg(pfm_rt.neg_op(3), 5, "
@@ -114,16 +114,16 @@ TEST(CXFA_FMParserTest, Parse) {
L"}\n"
L"pfm_ret = this;\n"
L"return pfm_rt.get_val(pfm_ret);\n"
- L"}\n).call(this);\n";
+ L"}).call(this);";
auto parser = pdfium::MakeUnique<CXFA_FMParser>(input);
- std::unique_ptr<CXFA_FMFunctionDefinition> ast = parser->Parse();
+ std::unique_ptr<CXFA_FMAST> ast = parser->Parse();
ASSERT(ast != nullptr);
EXPECT_FALSE(parser->HasError());
CXFA_FMToJavaScriptDepth::Reset();
CFX_WideTextBuf buf;
- EXPECT_TRUE(ast->ToJavaScript(buf, ReturnType::kInfered));
+ EXPECT_TRUE(ast->ToJavaScript(buf));
EXPECT_EQ(ret, buf.AsStringView());
}
@@ -146,7 +146,63 @@ TEST(CFXA_FMParserTest, chromium752201) {
TEST(CXFA_FMParserTest, MultipleAssignmentIsNotAllowed) {
auto parser = pdfium::MakeUnique<CXFA_FMParser>(L"(a=(b=t))=u");
- std::unique_ptr<CXFA_FMFunctionDefinition> ast = parser->Parse();
+ std::unique_ptr<CXFA_FMAST> ast = parser->Parse();
ASSERT(ast == nullptr);
EXPECT_TRUE(parser->HasError());
}
+
+TEST(CXFA_FMParserTest, ParseFuncWithParams) {
+ const wchar_t input[] = {
+ L"func MyFunction(param1, param2) do\n"
+ L" param1 * param2\n"
+ L"endfunc"};
+
+ const wchar_t ret[] = {
+ L"(function() {\n"
+ L"var pfm_ret = null;\n"
+ L"function MyFunction(param1, param2) {\n"
+ L"var pfm_ret = null;\n"
+ L"pfm_ret = pfm_rt.mul_op(param1, param2);\n"
+ L"return pfm_ret;\n"
+ L"}\n"
+ L"return pfm_rt.get_val(pfm_ret);\n"
+ L"}).call(this);"};
+
+ auto parser = pdfium::MakeUnique<CXFA_FMParser>(input);
+ std::unique_ptr<CXFA_FMAST> ast = parser->Parse();
+ ASSERT(ast != nullptr);
+ EXPECT_FALSE(parser->HasError());
+
+ CXFA_FMToJavaScriptDepth::Reset();
+ CFX_WideTextBuf buf;
+ EXPECT_TRUE(ast->ToJavaScript(buf));
+ EXPECT_EQ(ret, buf.AsStringView());
+}
+
+TEST(CXFA_FMParserTest, ParseFuncWithoutParams) {
+ const wchar_t input[] = {
+ L"func MyFunction() do\n"
+ L" 42\n"
+ L"endfunc"};
+
+ const wchar_t ret[] = {
+ L"(function() {\n"
+ L"var pfm_ret = null;\n"
+ L"function MyFunction() {\n"
+ L"var pfm_ret = null;\n"
+ L"pfm_ret = 42;\n"
+ L"return pfm_ret;\n"
+ L"}\n"
+ L"return pfm_rt.get_val(pfm_ret);\n"
+ L"}).call(this);"};
+
+ auto parser = pdfium::MakeUnique<CXFA_FMParser>(input);
+ std::unique_ptr<CXFA_FMAST> ast = parser->Parse();
+ ASSERT(ast != nullptr);
+ EXPECT_FALSE(parser->HasError());
+
+ CXFA_FMToJavaScriptDepth::Reset();
+ CFX_WideTextBuf buf;
+ EXPECT_TRUE(ast->ToJavaScript(buf));
+ EXPECT_EQ(ret, buf.AsStringView());
+}