1 // Copyright 2018 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "xfa/fxfa/fm2js/cxfa_fmexpression.h"
6
7 #include <memory>
8 #include <utility>
9
10 #include "core/fxcrt/cfx_widetextbuf.h"
11 #include "core/fxcrt/fx_string.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/base/ptr_util.h"
14 #include "xfa/fxfa/fm2js/cxfa_fmtojavascriptdepth.h"
15
TEST(CXFA_FMExpressionTest,VarExpressionInitNull)16 TEST(CXFA_FMExpressionTest, VarExpressionInitNull) {
17 CXFA_FMToJavaScriptDepth::Reset();
18 CFX_WideTextBuf accumulator;
19
20 CXFA_FMVarExpression(L"s", nullptr)
21 .ToJavaScript(&accumulator, ReturnType::kInfered);
22 EXPECT_STREQ(
23 LR"***(var s = "";
24 )***",
25 accumulator.MakeString().c_str());
26 }
27
TEST(CXFA_FMExpressionTest,VarExpressionInitBlank)28 TEST(CXFA_FMExpressionTest, VarExpressionInitBlank) {
29 CXFA_FMToJavaScriptDepth::Reset();
30 CFX_WideTextBuf accumulator;
31
32 auto init = pdfium::MakeUnique<CXFA_FMStringExpression>(LR"("")");
33 CXFA_FMVarExpression(L"s", std::move(init))
34 .ToJavaScript(&accumulator, ReturnType::kInfered);
35 EXPECT_STREQ(
36 LR"***(var s = "";
37 s = pfm_rt.var_filter(s);
38 )***",
39 accumulator.MakeString().c_str());
40 }
41
TEST(CXFA_FMExpressionTest,VarExpressionInitString)42 TEST(CXFA_FMExpressionTest, VarExpressionInitString) {
43 CXFA_FMToJavaScriptDepth::Reset();
44 CFX_WideTextBuf accumulator;
45
46 auto init = pdfium::MakeUnique<CXFA_FMStringExpression>(LR"("foo")");
47 CXFA_FMVarExpression(L"s", std::move(init))
48 .ToJavaScript(&accumulator, ReturnType::kInfered);
49 EXPECT_STREQ(
50 LR"***(var s = "foo";
51 s = pfm_rt.var_filter(s);
52 )***",
53 accumulator.MakeString().c_str());
54 }
55
TEST(CXFA_FMExpressionTest,VarExpressionInitNumeric)56 TEST(CXFA_FMExpressionTest, VarExpressionInitNumeric) {
57 CXFA_FMToJavaScriptDepth::Reset();
58 CFX_WideTextBuf accumulator;
59
60 auto init = pdfium::MakeUnique<CXFA_FMNumberExpression>(L"112");
61 CXFA_FMVarExpression(L"s", std::move(init))
62 .ToJavaScript(&accumulator, ReturnType::kInfered);
63 EXPECT_STREQ(
64 LR"***(var s = 112;
65 s = pfm_rt.var_filter(s);
66 )***",
67 accumulator.MakeString().c_str());
68 }
69