diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2018-06-06 18:00:14 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-06-06 18:00:14 +0000 |
commit | 5caa34c64382d8587a3ec3de5edbb30976b1390d (patch) | |
tree | 171e464aefbaf7072db676262b1243a7d397a660 /xfa/fxfa/fm2js/cxfa_fmexpression_unittest.cpp | |
parent | 2f6a861d2082bff2fe1125445b84cc5f7e11b826 (diff) | |
download | pdfium-5caa34c64382d8587a3ec3de5edbb30976b1390d.tar.xz |
[fm2js] Fixup initialized variable conversion
When converting a Var statement from formcalc to JS we would neglect to
add the ; if the variable was initialized. This generated invalid JS as
we'd end up with two statements smushed together.
FormCalc:
var s = ""
Previous JS:
var s = ""s = pfm....
New JS:
var s = "";
s = pfm ...
Bug: pdfium:1097
Change-Id: I8a869f07374cac68a06a487dace89699a4e5540c
Reviewed-on: https://pdfium-review.googlesource.com/34110
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'xfa/fxfa/fm2js/cxfa_fmexpression_unittest.cpp')
-rw-r--r-- | xfa/fxfa/fm2js/cxfa_fmexpression_unittest.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/xfa/fxfa/fm2js/cxfa_fmexpression_unittest.cpp b/xfa/fxfa/fm2js/cxfa_fmexpression_unittest.cpp new file mode 100644 index 0000000000..defe563afa --- /dev/null +++ b/xfa/fxfa/fm2js/cxfa_fmexpression_unittest.cpp @@ -0,0 +1,48 @@ +// Copyright 2018 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "xfa/fxfa/fm2js/cxfa_fmexpression.h" + +#include <memory> +#include <utility> + +#include "core/fxcrt/cfx_widetextbuf.h" +#include "core/fxcrt/fx_string.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "testing/test_support.h" +#include "third_party/base/ptr_util.h" +#include "xfa/fxfa/fm2js/cxfa_fmtojavascriptdepth.h" + +TEST(CXFA_FMExpressionTest, VarExpressionInitBlank) { + CXFA_FMToJavaScriptDepth::Reset(); + CFX_WideTextBuf accumulator; + + auto init = pdfium::MakeUnique<CXFA_FMStringExpression>(L"\"\""); + CXFA_FMVarExpression(L"s", std::move(init)) + .ToJavaScript(&accumulator, ReturnType::kInfered); + EXPECT_STREQ(L"var s = \"\";\ns = pfm_rt.var_filter(s);\n", + accumulator.MakeString().c_str()); +} + +TEST(CXFA_FMExpressionTest, VarExpressionInitString) { + CXFA_FMToJavaScriptDepth::Reset(); + CFX_WideTextBuf accumulator; + + auto init = pdfium::MakeUnique<CXFA_FMStringExpression>(L"\"foo\""); + CXFA_FMVarExpression(L"s", std::move(init)) + .ToJavaScript(&accumulator, ReturnType::kInfered); + EXPECT_STREQ(L"var s = \"foo\";\ns = pfm_rt.var_filter(s);\n", + accumulator.MakeString().c_str()); +} + +TEST(CXFA_FMExpressionTest, VarExpressionInitNumeric) { + CXFA_FMToJavaScriptDepth::Reset(); + CFX_WideTextBuf accumulator; + + auto init = pdfium::MakeUnique<CXFA_FMNumberExpression>(L"112"); + CXFA_FMVarExpression(L"s", std::move(init)) + .ToJavaScript(&accumulator, ReturnType::kInfered); + EXPECT_STREQ(L"var s = 112;\ns = pfm_rt.var_filter(s);\n", + accumulator.MakeString().c_str()); +} |