5#include "xfa/fxfa/formcalc/cxfa_fmparser.h"
7#include "core/fxcrt/widetext_buffer.h"
8#include "testing/fxgc_unittest.h"
9#include "testing/gtest/include/gtest/gtest.h"
10#include "xfa/fxfa/formcalc/cxfa_fmtojavascriptdepth.h"
22 absl::optional<WideTextBuffer> buf = ast->ToJavaScript();
23 ASSERT_TRUE(buf.has_value());
25 EXPECT_STREQ(L"// comments only", buf.value().MakeString().c_str());
38 absl::optional<WideTextBuffer> buf = ast->ToJavaScript();
39 ASSERT_TRUE(buf.has_value());
40 EXPECT_STREQ(L"// comments only", buf.value().MakeString().c_str());
46let pfm_method_runner = function(obj, cb) {
47 if (pfm_rt.is_ary(obj)) {
48 let pfm_method_return = null;
49 for (var idx = obj.length -1; idx > 1; idx--) {
50 pfm_method_return = cb(obj[idx]);
51 }
52 return pfm_method_return;
53 }
54 return cb(obj);
55};
56var pfm_ret = null;
57pfm_ret = 12;
58return pfm_rt.get_val(pfm_ret);
59}).call(this);)***";
68 absl::optional<WideTextBuffer> buf = ast->ToJavaScript();
69 ASSERT_TRUE(buf.has_value());
70 EXPECT_STREQ(ret, buf.value().MakeString().c_str());
74 const wchar_t input[] =
75 LR"***($ = Avg (-3, 5, -6, 12, -13);
76$ = Avg (Table2..Row[*].Cell1);
77if ($ ne -1)then
78 border.fill.color.value = "255,64,64";
79elseif ($ ne -2) then
80 border.fill.color.value = "128,128,128";
81else
82 border.fill.color.value = "20,170,13";
83endif
84$)***";
88let pfm_method_runner = function(obj, cb) {
89 if (pfm_rt.is_ary(obj)) {
90 let pfm_method_return = null;
91 for (var idx = obj.length -1; idx > 1; idx--) {
92 pfm_method_return = cb(obj[idx]);
93 }
94 return pfm_method_return;
95 }
96 return cb(obj);
97};
98var pfm_ret = null;
99if (pfm_rt.is_obj(this))
100{
101pfm_rt.asgn_val_op(this, pfm_rt.Avg(pfm_rt.neg_op(3), 5, pfm_rt.neg_op(6), 12, pfm_rt.neg_op(13)));
102}
103if (pfm_rt.is_obj(this))
104{
105pfm_rt.asgn_val_op(this, pfm_rt.Avg(pfm_rt.dot_acc(pfm_rt.dotdot_acc(Table2, "Table2", "Row", 1), "", "Cell1", 0, 0)));
106}
107if (pfm_rt.get_val(pfm_rt.neq_op(this, pfm_rt.neg_op(1))))
108{
109if (pfm_rt.is_obj(pfm_rt.dot_acc(pfm_rt.dot_acc(pfm_rt.dot_acc(border, "border", "fill", 0, 0), "", "color", 0, 0), "", "value", 0, 0)))
110{
111pfm_rt.asgn_val_op(pfm_rt.dot_acc(pfm_rt.dot_acc(pfm_rt.dot_acc(border, "border", "fill", 0, 0), "", "color", 0, 0), "", "value", 0, 0), "255,64,64");
112}
113}
114else if (pfm_rt.get_val(pfm_rt.neq_op(this, pfm_rt.neg_op(2))))
115{
116if (pfm_rt.is_obj(pfm_rt.dot_acc(pfm_rt.dot_acc(pfm_rt.dot_acc(border, "border", "fill", 0, 0), "", "color", 0, 0), "", "value", 0, 0)))
117{
118pfm_rt.asgn_val_op(pfm_rt.dot_acc(pfm_rt.dot_acc(pfm_rt.dot_acc(border, "border", "fill", 0, 0), "", "color", 0, 0), "", "value", 0, 0), "128,128,128");
119}
120}
121else {
122if (pfm_rt.is_obj(pfm_rt.dot_acc(pfm_rt.dot_acc(pfm_rt.dot_acc(border, "border", "fill", 0, 0), "", "color", 0, 0), "", "value", 0, 0)))
123{
124pfm_rt.asgn_val_op(pfm_rt.dot_acc(pfm_rt.dot_acc(pfm_rt.dot_acc(border, "border", "fill", 0, 0), "", "color", 0, 0), "", "value", 0, 0), "20,170,13");
125}
126}
127pfm_ret = this;
128return pfm_rt.get_val(pfm_ret);
129}).call(this);)***";
138 absl::optional<WideTextBuffer> buf = ast->ToJavaScript();
139 ASSERT_TRUE(buf.has_value());
140 EXPECT_EQ(ret, buf.value().AsStringView());
154.#
155fo@ =[=l)***");
171 const wchar_t input[] =
172 LR"***(func MyFunction(param1, param2) do
173 param1 * param2
174endfunc)***";
176 const wchar_t ret[] =
178let pfm_method_runner = function(obj, cb) {
179 if (pfm_rt.is_ary(obj)) {
180 let pfm_method_return = null;
181 for (var idx = obj.length -1; idx > 1; idx--) {
182 pfm_method_return = cb(obj[idx]);
183 }
184 return pfm_method_return;
185 }
186 return cb(obj);
187};
188var pfm_ret = null;
189function MyFunction(param1, param2) {
190var pfm_ret = null;
191pfm_ret = pfm_rt.mul_op(param1, param2);
192return pfm_ret;
193}
194return pfm_rt.get_val(pfm_ret);
195}).call(this);)***";
204 absl::optional<WideTextBuffer> buf = ast->ToJavaScript();
205 ASSERT_TRUE(buf.has_value());
206 EXPECT_STREQ(ret, buf.value().MakeString().c_str());
210 const wchar_t input[] =
211 LR"***(func MyFunction() do
212 42
213endfunc)***";
215 const wchar_t ret[] =
217let pfm_method_runner = function(obj, cb) {
218 if (pfm_rt.is_ary(obj)) {
219 let pfm_method_return = null;
220 for (var idx = obj.length -1; idx > 1; idx--) {
221 pfm_method_return = cb(obj[idx]);
222 }
223 return pfm_method_return;
224 }
225 return cb(obj);
226};
227var pfm_ret = null;
228function MyFunction() {
229var pfm_ret = null;
230pfm_ret = 42;
231return pfm_ret;
232}
233return pfm_rt.get_val(pfm_ret);
234}).call(this);)***";
243 absl::optional<WideTextBuffer> buf = ast->ToJavaScript();
244 ASSERT_TRUE(buf.has_value());
245 EXPECT_STREQ(ret, buf.value().MakeString().c_str());
249 const wchar_t input[] =
250 LR"***(func MyFunction(param1,) do
251 param1 * param2
252endfunc)***";
257 ASSERT_TRUE(ast ==
nullptr);
262 const wchar_t input[] = L"if ( then";
266 ASSERT_TRUE(ast ==
nullptr);
271 const wchar_t input[] =
272 LR"***(if ($ ne -1) then"
273elseif( then)***";
278 ASSERT_TRUE(ast ==
nullptr);
283 const wchar_t input[] = L"a <> b <> c <> d <> e <> f <> g <> h <> i <> j";
298 ASSERT_TRUE(ast ==
nullptr);
304 const wchar_t input[] = L"i.f(O)";
305 const wchar_t ret[] =
307let pfm_method_runner = function(obj, cb) {
308 if (pfm_rt.is_ary(obj)) {
309 let pfm_method_return = null;
310 for (var idx = obj.length -1; idx > 1; idx--) {
311 pfm_method_return = cb(obj[idx]);
312 }
313 return pfm_method_return;
314 }
315 return cb(obj);
316};
317var pfm_ret = null;
318pfm_ret = pfm_rt.get_val((function() {
319 return pfm_method_runner(i, function(obj) {
320 return obj.f(pfm_rt.get_val(O));
321 });
322}).call(this));
323return pfm_rt.get_val(pfm_ret);
324}).call(this);)***";
332 absl::optional<WideTextBuffer> buf = ast->ToJavaScript();
333 ASSERT_TRUE(buf.has_value());
334 EXPECT_STREQ(ret, buf.value().MakeString().c_str());
338 const wchar_t input[] = L"i.f(O.e(O.e(O)))";
339 const wchar_t ret[] =
341let pfm_method_runner = function(obj, cb) {
342 if (pfm_rt.is_ary(obj)) {
343 let pfm_method_return = null;
344 for (var idx = obj.length -1; idx > 1; idx--) {
345 pfm_method_return = cb(obj[idx]);
346 }
347 return pfm_method_return;
348 }
349 return cb(obj);
350};
351var pfm_ret = null;
352pfm_ret = pfm_rt.get_val((function() {
353 return pfm_method_runner(i, function(obj) {
354 return obj.f(pfm_rt.get_val((function() {
355 return pfm_method_runner(O, function(obj) {
356 return obj.e(pfm_rt.get_val((function() {
357 return pfm_method_runner(O, function(obj) {
358 return obj.e(pfm_rt.get_val(O));
359 });
360}).call(this)));
361 });
362}).call(this)));
363 });
364}).call(this));
365return pfm_rt.get_val(pfm_ret);
366}).call(this);)***";
374 absl::optional<WideTextBuffer> buf = ast->ToJavaScript();
375 ASSERT_TRUE(buf.has_value());
376 EXPECT_STREQ(ret, buf.value().MakeString().c_str());
380 const wchar_t input[] = LR"(var s = "")";
381 const wchar_t ret[] =
383let pfm_method_runner = function(obj, cb) {
384 if (pfm_rt.is_ary(obj)) {
385 let pfm_method_return = null;
386 for (var idx = obj.length -1; idx > 1; idx--) {
387 pfm_method_return = cb(obj[idx]);
388 }
389 return pfm_method_return;
390 }
391 return cb(obj);
392};
393var pfm_ret = null;
394var s = "";
395s = pfm_rt.var_filter(s);
396pfm_ret = s;
397return pfm_rt.get_val(pfm_ret);
398}).call(this);)***";
406 absl::optional<WideTextBuffer> buf = ast->ToJavaScript();
407 ASSERT_TRUE(buf.has_value());
408 EXPECT_STREQ(ret, buf.value().MakeString().c_str());
412 const wchar_t input[] = L"P.x()";
413 const wchar_t ret[] =
415let pfm_method_runner = function(obj, cb) {
416 if (pfm_rt.is_ary(obj)) {
417 let pfm_method_return = null;
418 for (var idx = obj.length -1; idx > 1; idx--) {
419 pfm_method_return = cb(obj[idx]);
420 }
421 return pfm_method_return;
422 }
423 return cb(obj);
424};
425var pfm_ret = null;
426pfm_ret = pfm_rt.get_val((function() {
427 return pfm_method_runner(P, function(obj) {
428 return obj.x();
429 });
430}).call(this));
431return pfm_rt.get_val(pfm_ret);
432}).call(this);)***";
440 absl::optional<WideTextBuffer> buf = ast->ToJavaScript();
441 ASSERT_TRUE(buf.has_value());
442 EXPECT_STREQ(ret, buf.value().MakeString().c_str());
446 const wchar_t input[] = L"P.x(foo)";
447 const wchar_t ret[] =
449let pfm_method_runner = function(obj, cb) {
450 if (pfm_rt.is_ary(obj)) {
451 let pfm_method_return = null;
452 for (var idx = obj.length -1; idx > 1; idx--) {
453 pfm_method_return = cb(obj[idx]);
454 }
455 return pfm_method_return;
456 }
457 return cb(obj);
458};
459var pfm_ret = null;
460pfm_ret = pfm_rt.get_val((function() {
461 return pfm_method_runner(P, function(obj) {
462 return obj.x(pfm_rt.get_jsobj(foo));
463 });
464}).call(this));
465return pfm_rt.get_val(pfm_ret);
466}).call(this);)***";
474 absl::optional<WideTextBuffer> buf = ast->ToJavaScript();
475 ASSERT_TRUE(buf.has_value());
476 EXPECT_STREQ(ret, buf.value().MakeString().c_str());
480 const wchar_t input[] = L"P.x(foo, bar, baz)";
481 const wchar_t ret[] =
483let pfm_method_runner = function(obj, cb) {
484 if (pfm_rt.is_ary(obj)) {
485 let pfm_method_return = null;
486 for (var idx = obj.length -1; idx > 1; idx--) {
487 pfm_method_return = cb(obj[idx]);
488 }
489 return pfm_method_return;
490 }
491 return cb(obj);
492};
493var pfm_ret = null;
494pfm_ret = pfm_rt.get_val((function() {
495 return pfm_method_runner(P, function(obj) {
496 return obj.x(pfm_rt.get_jsobj(foo), pfm_rt.get_val(bar), pfm_rt.get_val(baz));
497 });
498}).call(this));
499return pfm_rt.get_val(pfm_ret);
500}).call(this);)***";
508 absl::optional<WideTextBuffer> buf = ast->ToJavaScript();
509 ASSERT_TRUE(buf.has_value());
510 EXPECT_STREQ(ret, buf.value().MakeString().c_str());
514 const wchar_t input[] = L"P.x(!foo!bar!baz)";
518 ASSERT_TRUE(ast ==
nullptr);
523 const wchar_t input[] = L"P.x(foo,bar,baz,)";
527 ASSERT_TRUE(ast ==
nullptr);
532 const wchar_t input[] = L"P.x(foo,bar,,baz)";
536 ASSERT_TRUE(ast ==
nullptr);
void SetMaxParseDepthForTest(unsigned long max_depth)
TEST_F(CXFA_FMParserTest, Empty)