5#include "xfa/fxfa/formcalc/cxfa_fmexpression.h"
9#include "core/fxcrt/fx_string.h"
10#include "core/fxcrt/widetext_buffer.h"
11#include "testing/fxgc_unittest.h"
12#include "testing/gtest/include/gtest/gtest.h"
13#include "v8/include/cppgc/heap.h"
14#include "xfa/fxfa/formcalc/cxfa_fmlexer.h"
15#include "xfa/fxfa/formcalc/cxfa_fmtojavascriptdepth.h"
23 auto* exp = cppgc::MakeGarbageCollected<CXFA_FMIdentifierExpression>(
24 heap()->GetAllocationHandle(), L"sign");
26 std::vector<cppgc::Member<CXFA_FMSimpleExpression>> args;
27 for (size_t i = 0; i < 50; i++) {
28 args.push_back(cppgc::MakeGarbageCollected<CXFA_FMNullExpression>(
29 heap()->GetAllocationHandle()));
32 auto* callExp = cppgc::MakeGarbageCollected<CXFA_FMCallExpression>(
33 heap()->GetAllocationHandle(), exp, std::move(args),
true);
39 WideString result = L"sign(";
40 for (size_t i = 0; i < 50; i++) {
44 result
+= L"pfm_rt.get_";
46 if (i == 0 || i == 5 || i == 6)
47 result
+= L"jsobj(null)";
49 result
+= L"val(null)";
58 WideTextBuffer accumulator;
59 auto* exp = cppgc::MakeGarbageCollected<CXFA_FMStringExpression>(
60 heap()->GetAllocationHandle(), L"");
61 exp->ToJavaScript(&accumulator,
68 WideTextBuffer accumulator;
69 auto* exp = cppgc::MakeGarbageCollected<CXFA_FMStringExpression>(
70 heap()->GetAllocationHandle(), L"a");
71 exp->ToJavaScript(&accumulator,
78 WideTextBuffer accumulator;
79 auto* exp = cppgc::MakeGarbageCollected<CXFA_FMStringExpression>(
80 heap()->GetAllocationHandle(), L".abcd.");
81 exp->ToJavaScript(&accumulator,
88 WideTextBuffer accumulator;
89 std::vector<WideStringView::UnsignedType> vec(140000, L'A');
90 auto* exp = cppgc::MakeGarbageCollected<CXFA_FMStringExpression>(
91 heap()->GetAllocationHandle(), WideString(WideStringView(vec)));
92 exp->ToJavaScript(&accumulator,
94 EXPECT_EQ(140000u, accumulator.GetLength());
99 WideTextBuffer accumulator;
100 auto* exp = cppgc::MakeGarbageCollected<CXFA_FMStringExpression>(
101 heap()->GetAllocationHandle(), L".Simon says \"\"run\"\".");
102 exp->ToJavaScript(&accumulator,
104 EXPECT_EQ(L"\"Simon says \\\"run\\\"\"", accumulator
.AsStringView());
109 WideTextBuffer accumulator;
111 auto* expr = cppgc::MakeGarbageCollected<CXFA_FMVarExpression>(
112 heap()->GetAllocationHandle(), L"s",
nullptr);
113 expr->ToJavaScript(&accumulator,
117)***",
123 WideTextBuffer accumulator;
125 auto* init = cppgc::MakeGarbageCollected<CXFA_FMStringExpression>(
126 heap()->GetAllocationHandle(), LR"("")");
127 auto* expr = cppgc::MakeGarbageCollected<CXFA_FMVarExpression>(
128 heap()->GetAllocationHandle(), L"s", init);
129 expr->ToJavaScript(&accumulator,
133s = pfm_rt.var_filter(s);
134)***",
140 WideTextBuffer accumulator;
142 auto* init = cppgc::MakeGarbageCollected<CXFA_FMStringExpression>(
143 heap()->GetAllocationHandle(), LR"("foo")");
144 auto* expr = cppgc::MakeGarbageCollected<CXFA_FMVarExpression>(
145 heap()->GetAllocationHandle(), L"s", init);
146 expr->ToJavaScript(&accumulator,
149 LR"***(var s = "foo";
150s = pfm_rt.var_filter(s);
151)***",
157 WideTextBuffer accumulator;
159 auto* init = cppgc::MakeGarbageCollected<CXFA_FMNumberExpression>(
160 heap()->GetAllocationHandle(), L"112");
161 auto* expr = cppgc::MakeGarbageCollected<CXFA_FMVarExpression>(
162 heap()->GetAllocationHandle(), L"s", init);
163 expr->ToJavaScript(&accumulator,
167s = pfm_rt.var_filter(s);
168)***",
WideString & operator+=(const wchar_t *str)
const wchar_t * c_str() const
WideString MakeString() const
WideStringView AsStringView() const
TEST_F(FMExpressionTest, VarExpressionInitNull)
TEST_F(FMCallExpressionTest, more_than_32_arguments)
TEST_F(FMStringExpressionTest, Empty)