scripting_spec.js 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2022 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * JavaScript code in this page
  21. */
  22. "use strict";
  23. var _display_utils = require("../../display/display_utils.js");
  24. const sandboxBundleSrc = "../../build/generic/build/pdf.sandbox.js";
  25. describe("Scripting", function () {
  26. let sandbox, send_queue, test_id, ref, windowAlert;
  27. function getId() {
  28. const id = `${ref++}R`;
  29. return id;
  30. }
  31. function myeval(code) {
  32. const key = (test_id++).toString();
  33. return sandbox.eval(code, key).then(() => {
  34. const result = send_queue.get(key).result;
  35. send_queue.delete(key);
  36. return result;
  37. });
  38. }
  39. beforeAll(function () {
  40. test_id = 0;
  41. ref = 1;
  42. send_queue = new Map();
  43. window.dispatchEvent = event => {
  44. if (event.detail.command) {
  45. send_queue.set(event.detail.command, event.detail);
  46. } else if (send_queue.has(event.detail.id)) {
  47. const prev = send_queue.get(event.detail.id);
  48. Object.assign(prev, event.detail);
  49. } else {
  50. send_queue.set(event.detail.id, event.detail);
  51. }
  52. };
  53. windowAlert = window.alert;
  54. window.alert = value => {
  55. const command = "alert";
  56. send_queue.set(command, {
  57. command,
  58. value
  59. });
  60. };
  61. const promise = (0, _display_utils.loadScript)(sandboxBundleSrc).then(() => {
  62. return window.pdfjsSandbox.QuickJSSandbox();
  63. });
  64. sandbox = {
  65. createSandbox(data) {
  66. promise.then(sbx => sbx.create(data));
  67. },
  68. dispatchEventInSandbox(data) {
  69. return promise.then(sbx => sbx.dispatchEvent(data));
  70. },
  71. nukeSandbox() {
  72. promise.then(sbx => sbx.nukeSandbox());
  73. },
  74. eval(code, key) {
  75. return promise.then(sbx => sbx.evalForTesting(code, key));
  76. }
  77. };
  78. });
  79. afterAll(function () {
  80. sandbox.nukeSandbox();
  81. sandbox = null;
  82. send_queue = null;
  83. window.alert = windowAlert;
  84. });
  85. describe("Sandbox", function () {
  86. it("should send a value, execute an action and get back a new value", async () => {
  87. function compute(n) {
  88. let s = 0;
  89. for (let i = 0; i < n; i++) {
  90. s += i;
  91. }
  92. return s;
  93. }
  94. const number = 123;
  95. const expected = (number - 1) * number / 2;
  96. const refId = getId();
  97. const data = {
  98. objects: {
  99. field: [{
  100. id: refId,
  101. value: "",
  102. actions: {
  103. Keystroke: [`${compute.toString()}event.value = compute(parseInt(event.value));`]
  104. },
  105. type: "text"
  106. }]
  107. },
  108. calculationOrder: [],
  109. appInfo: {
  110. language: "en-US",
  111. platform: "Linux x86_64"
  112. }
  113. };
  114. sandbox.createSandbox(data);
  115. await sandbox.dispatchEventInSandbox({
  116. id: refId,
  117. value: `${number}`,
  118. name: "Keystroke",
  119. willCommit: true
  120. });
  121. expect(send_queue.has(refId)).toEqual(true);
  122. expect(send_queue.get(refId)).toEqual({
  123. id: refId,
  124. siblings: null,
  125. value: expected,
  126. formattedValue: null
  127. });
  128. });
  129. });
  130. describe("Doc", function () {
  131. it("should treat globalThis as the doc", async () => {
  132. const refId = getId();
  133. const data = {
  134. objects: {
  135. field: [{
  136. id: refId,
  137. value: "",
  138. actions: {},
  139. type: "text"
  140. }]
  141. },
  142. appInfo: {
  143. language: "en-US",
  144. platform: "Linux x86_64"
  145. },
  146. calculationOrder: [],
  147. dispatchEventName: "_dispatchMe"
  148. };
  149. sandbox.createSandbox(data);
  150. await myeval(`(this.foobar = 123456, 0)`);
  151. const value = await myeval(`this.getField("field").doc.foobar`);
  152. expect(value).toEqual(123456);
  153. });
  154. it("should get field using a path", async () => {
  155. const base = value => {
  156. return {
  157. id: getId(),
  158. value,
  159. actions: {},
  160. type: "text"
  161. };
  162. };
  163. const data = {
  164. objects: {
  165. A: [base(1)],
  166. "A.B": [base(2)],
  167. "A.B.C": [base(3)],
  168. "A.B.C.D": [base(4)],
  169. "A.B.C.D.E": [base(5)],
  170. "A.B.C.D.E.F": [base(6)],
  171. "A.B.C.D.G": [base(7)],
  172. C: [base(8)]
  173. },
  174. appInfo: {
  175. language: "en-US",
  176. platform: "Linux x86_64"
  177. },
  178. calculationOrder: [],
  179. dispatchEventName: "_dispatchMe"
  180. };
  181. sandbox.createSandbox(data);
  182. let value = await myeval(`this.getField("A").value`);
  183. expect(value).toEqual(1);
  184. value = await myeval(`this.getField("B.C").value`);
  185. expect(value).toEqual(3);
  186. value = await myeval(`this.getField("B.C").value`);
  187. expect(value).toEqual(3);
  188. value = await myeval(`this.getField("B.C.D#0").value`);
  189. expect(value).toEqual(5);
  190. value = await myeval(`this.getField("B.C.D#1").value`);
  191. expect(value).toEqual(7);
  192. value = await myeval(`this.getField("C").value`);
  193. expect(value).toEqual(8);
  194. value = await myeval(`this.getField("A.B.C.D").getArray().map((x) => x.value)`);
  195. expect(value).toEqual([4, 5, 6, 7]);
  196. });
  197. });
  198. describe("Util", function () {
  199. beforeAll(function () {
  200. sandbox.createSandbox({
  201. appInfo: {
  202. language: "en-US",
  203. platform: "Linux x86_64"
  204. },
  205. objects: {},
  206. calculationOrder: []
  207. });
  208. });
  209. describe("printd", function () {
  210. it("should print a date according to a format", async () => {
  211. const date = `new Date("Sun Apr 15 2007 03:14:15")`;
  212. let value = await myeval(`util.printd(0, ${date})`);
  213. expect(value).toEqual("D:20070415031415");
  214. value = await myeval(`util.printd(1, ${date})`);
  215. expect(value).toEqual("2007.04.15 03:14:15");
  216. value = await myeval(`util.printd(2, ${date})`);
  217. expect(value).toEqual("4/15/07 3:14:15 am");
  218. value = await myeval(`util.printd("mmmm mmm mm m", ${date})`);
  219. expect(value).toEqual("April Apr 04 4");
  220. value = await myeval(`util.printd("dddd ddd dd d", ${date})`);
  221. expect(value).toEqual("Sunday Sun 15 15");
  222. });
  223. });
  224. describe("scand", function () {
  225. it("should parse a date according to a format", async () => {
  226. const date = new Date("Sun Apr 15 2007 03:14:15");
  227. let value = await myeval(`util.scand(0, "D:20070415031415").toString()`);
  228. expect(new Date(value)).toEqual(date);
  229. value = await myeval(`util.scand(1, "2007.04.15 03:14:15").toString()`);
  230. expect(new Date(value)).toEqual(date);
  231. value = await myeval(`util.scand(2, "4/15/07 3:14:15 am").toString()`);
  232. expect(new Date(value)).toEqual(date);
  233. });
  234. });
  235. describe("printf", function () {
  236. it("should print some data according to a format", async () => {
  237. let value = await myeval(`util.printf("Integer numbers: %d, %d,...", 1.234, 56.789)`);
  238. expect(value).toEqual("Integer numbers: 1, 56,...");
  239. value = await myeval(`util.printf("Hex numbers: %x, %x,...", 1234, 56789)`);
  240. expect(value).toEqual("Hex numbers: 4D2, DDD5,...");
  241. value = await myeval(`util.printf("Hex numbers with 0x: %#x, %#x,...", 1234, 56789)`);
  242. expect(value).toEqual("Hex numbers with 0x: 0x4D2, 0xDDD5,...");
  243. value = await myeval(`util.printf("Decimal number: %,0+.3f", 1234567.89123)`);
  244. expect(value).toEqual("Decimal number: +1,234,567.891");
  245. value = await myeval(`util.printf("Decimal number: %,0+8.3f", 1.234567)`);
  246. expect(value).toEqual("Decimal number: + 1.235");
  247. value = await myeval(`util.printf("Decimal number: %,0.2f", -12.34567)`);
  248. expect(value).toEqual("Decimal number: -12.35");
  249. value = await myeval(`util.printf("Decimal number: %,0.0f", 4.95)`);
  250. expect(value).toEqual("Decimal number: 5");
  251. value = await myeval(`util.printf("Decimal number: %,0.0f", 4.49)`);
  252. expect(value).toEqual("Decimal number: 4");
  253. value = await myeval(`util.printf("Decimal number: %,0.0f", -4.95)`);
  254. expect(value).toEqual("Decimal number: -5");
  255. value = await myeval(`util.printf("Decimal number: %,0.0f", -4.49)`);
  256. expect(value).toEqual("Decimal number: -4");
  257. });
  258. it("should print a string with no argument", async () => {
  259. const value = await myeval(`util.printf("hello world")`);
  260. expect(value).toEqual("hello world");
  261. });
  262. it("print a string with a percent", async () => {
  263. const value = await myeval(`util.printf("%%s")`);
  264. expect(value).toEqual("%%s");
  265. });
  266. });
  267. describe("printx", function () {
  268. it("should print some data according to a format", async () => {
  269. const value = await myeval(`util.printx("9 (999) 999-9999", "aaa14159697489zzz")`);
  270. expect(value).toEqual("1 (415) 969-7489");
  271. });
  272. });
  273. });
  274. describe("Events", function () {
  275. it("should trigger an event and modify the source", async () => {
  276. const refId = getId();
  277. const data = {
  278. objects: {
  279. field: [{
  280. id: refId,
  281. value: "",
  282. actions: {
  283. test: [`event.source.value = "123";`]
  284. },
  285. type: "text"
  286. }]
  287. },
  288. appInfo: {
  289. language: "en-US",
  290. platform: "Linux x86_64"
  291. },
  292. calculationOrder: []
  293. };
  294. sandbox.createSandbox(data);
  295. await sandbox.dispatchEventInSandbox({
  296. id: refId,
  297. value: "",
  298. name: "test",
  299. willCommit: true
  300. });
  301. expect(send_queue.has(refId)).toEqual(true);
  302. expect(send_queue.get(refId)).toEqual({
  303. id: refId,
  304. value: 123
  305. });
  306. });
  307. it("should trigger a Keystroke event and invalidate it", async () => {
  308. const refId = getId();
  309. const data = {
  310. objects: {
  311. field: [{
  312. id: refId,
  313. value: "",
  314. actions: {
  315. Keystroke: [`event.rc = false;`]
  316. },
  317. type: "text"
  318. }]
  319. },
  320. appInfo: {
  321. language: "en-US",
  322. platform: "Linux x86_64"
  323. },
  324. calculationOrder: []
  325. };
  326. sandbox.createSandbox(data);
  327. await sandbox.dispatchEventInSandbox({
  328. id: refId,
  329. value: "hell",
  330. name: "Keystroke",
  331. willCommit: false,
  332. change: "o",
  333. selStart: 4,
  334. selEnd: 4
  335. });
  336. expect(send_queue.has(refId)).toEqual(true);
  337. expect(send_queue.get(refId)).toEqual({
  338. id: refId,
  339. siblings: null,
  340. value: "hell",
  341. selRange: [4, 4]
  342. });
  343. });
  344. it("should trigger a Keystroke event and change it", async () => {
  345. const refId = getId();
  346. const data = {
  347. objects: {
  348. field: [{
  349. id: refId,
  350. value: "",
  351. actions: {
  352. Keystroke: [`event.change = "a";`]
  353. },
  354. type: "text"
  355. }]
  356. },
  357. appInfo: {
  358. language: "en-US",
  359. platform: "Linux x86_64"
  360. },
  361. calculationOrder: []
  362. };
  363. sandbox.createSandbox(data);
  364. await sandbox.dispatchEventInSandbox({
  365. id: refId,
  366. value: "hell",
  367. name: "Keystroke",
  368. willCommit: false,
  369. change: "o",
  370. selStart: 4,
  371. selEnd: 4
  372. });
  373. expect(send_queue.has(refId)).toEqual(true);
  374. expect(send_queue.get(refId)).toEqual({
  375. id: refId,
  376. siblings: null,
  377. value: "hella",
  378. selRange: [5, 5]
  379. });
  380. });
  381. it("should trigger an invalid commit Keystroke event", async () => {
  382. const refId = getId();
  383. const data = {
  384. objects: {
  385. field: [{
  386. id: refId,
  387. value: "",
  388. actions: {
  389. test: [`event.rc = false;`]
  390. },
  391. type: "text"
  392. }]
  393. },
  394. appInfo: {
  395. language: "en-US",
  396. platform: "Linux x86_64"
  397. },
  398. calculationOrder: []
  399. };
  400. sandbox.createSandbox(data);
  401. await sandbox.dispatchEventInSandbox({
  402. id: refId,
  403. value: "",
  404. name: "test",
  405. willCommit: true
  406. });
  407. expect(send_queue.has(refId)).toEqual(false);
  408. });
  409. it("should trigger a valid commit Keystroke event", async () => {
  410. const refId1 = getId();
  411. const refId2 = getId();
  412. const data = {
  413. objects: {
  414. field1: [{
  415. id: refId1,
  416. value: "",
  417. actions: {
  418. Validate: [`event.value = "world";`]
  419. },
  420. type: "text"
  421. }],
  422. field2: [{
  423. id: refId2,
  424. value: "",
  425. actions: {
  426. Calculate: [`event.value = "hello";`]
  427. },
  428. type: "text"
  429. }]
  430. },
  431. appInfo: {
  432. language: "en-US",
  433. platform: "Linux x86_64"
  434. },
  435. calculationOrder: [refId2]
  436. };
  437. sandbox.createSandbox(data);
  438. await sandbox.dispatchEventInSandbox({
  439. id: refId1,
  440. value: "hello",
  441. name: "Keystroke",
  442. willCommit: true
  443. });
  444. expect(send_queue.has(refId1)).toEqual(true);
  445. expect(send_queue.get(refId1)).toEqual({
  446. id: refId1,
  447. siblings: null,
  448. value: "world",
  449. formattedValue: null
  450. });
  451. });
  452. });
  453. describe("Color", function () {
  454. beforeAll(function () {
  455. sandbox.createSandbox({
  456. appInfo: {
  457. language: "en-US",
  458. platform: "Linux x86_64"
  459. },
  460. objects: {},
  461. calculationOrder: []
  462. });
  463. });
  464. function round(color) {
  465. return [color[0], ...color.slice(1).map(x => Math.round(x * 1000) / 1000)];
  466. }
  467. it("should convert RGB color for different color spaces", async () => {
  468. let value = await myeval(`color.convert(["RGB", 0.1, 0.2, 0.3], "T")`);
  469. expect(round(value)).toEqual(["T"]);
  470. value = await myeval(`color.convert(["RGB", 0.1, 0.2, 0.3], "G")`);
  471. expect(round(value)).toEqual(["G", 0.181]);
  472. value = await myeval(`color.convert(["RGB", 0.1, 0.2, 0.3], "RGB")`);
  473. expect(round(value)).toEqual(["RGB", 0.1, 0.2, 0.3]);
  474. value = await myeval(`color.convert(["RGB", 0.1, 0.2, 0.3], "CMYK")`);
  475. expect(round(value)).toEqual(["CMYK", 0.9, 0.8, 0.7, 0.7]);
  476. });
  477. it("should convert CMYK color for different color spaces", async () => {
  478. let value = await myeval(`color.convert(["CMYK", 0.1, 0.2, 0.3, 0.4], "T")`);
  479. expect(round(value)).toEqual(["T"]);
  480. value = await myeval(`color.convert(["CMYK", 0.1, 0.2, 0.3, 0.4], "G")`);
  481. expect(round(value)).toEqual(["G", 0.371]);
  482. value = await myeval(`color.convert(["CMYK", 0.1, 0.2, 0.3, 0.4], "RGB")`);
  483. expect(round(value)).toEqual(["RGB", 0.5, 0.3, 0.4]);
  484. value = await myeval(`color.convert(["CMYK", 0.1, 0.2, 0.3, 0.4], "CMYK")`);
  485. expect(round(value)).toEqual(["CMYK", 0.1, 0.2, 0.3, 0.4]);
  486. });
  487. it("should convert Gray color for different color spaces", async () => {
  488. let value = await myeval(`color.convert(["G", 0.1], "T")`);
  489. expect(round(value)).toEqual(["T"]);
  490. value = await myeval(`color.convert(["G", 0.1], "G")`);
  491. expect(round(value)).toEqual(["G", 0.1]);
  492. value = await myeval(`color.convert(["G", 0.1], "RGB")`);
  493. expect(round(value)).toEqual(["RGB", 0.1, 0.1, 0.1]);
  494. value = await myeval(`color.convert(["G", 0.1], "CMYK")`);
  495. expect(round(value)).toEqual(["CMYK", 0, 0, 0, 0.9]);
  496. });
  497. it("should convert Transparent color for different color spaces", async () => {
  498. let value = await myeval(`color.convert(["T"], "T")`);
  499. expect(round(value)).toEqual(["T"]);
  500. value = await myeval(`color.convert(["T"], "G")`);
  501. expect(round(value)).toEqual(["G", 0]);
  502. value = await myeval(`color.convert(["T"], "RGB")`);
  503. expect(round(value)).toEqual(["RGB", 0, 0, 0]);
  504. value = await myeval(`color.convert(["T"], "CMYK")`);
  505. expect(round(value)).toEqual(["CMYK", 0, 0, 0, 1]);
  506. });
  507. });
  508. describe("App", function () {
  509. beforeAll(function () {
  510. sandbox.createSandbox({
  511. appInfo: {
  512. language: "en-US",
  513. platform: "Linux x86_64"
  514. },
  515. objects: {},
  516. calculationOrder: []
  517. });
  518. });
  519. it("should test language", async () => {
  520. let value = await myeval(`app.language`);
  521. expect(value).toEqual("ENU");
  522. value = await myeval(`app.language = "hello"`);
  523. expect(value).toEqual("app.language is read-only");
  524. });
  525. it("should test platform", async () => {
  526. let value = await myeval(`app.platform`);
  527. expect(value).toEqual("UNIX");
  528. value = await myeval(`app.platform = "hello"`);
  529. expect(value).toEqual("app.platform is read-only");
  530. });
  531. });
  532. describe("AForm", function () {
  533. beforeAll(function () {
  534. sandbox.createSandbox({
  535. appInfo: {
  536. language: "en-US",
  537. platform: "Linux x86_64"
  538. },
  539. objects: {},
  540. calculationOrder: [],
  541. dispatchEventName: "_dispatchMe"
  542. });
  543. });
  544. describe("AFParseDateEx", function () {
  545. it("should parse a date with a format", async () => {
  546. const check = async (date, format, expected) => {
  547. const value = await myeval(`AFParseDateEx("${date}", "${format}").toISOString().replace(/T.*$/, "")`);
  548. expect(value).toEqual(new Date(expected).toISOString().replace(/T.*$/, ""));
  549. };
  550. await check("05", "dd", "2000/01/05");
  551. await check("12", "mm", "2000/12/01");
  552. await check("2022", "yyyy", "2022/01/01");
  553. await check("a1$9bbbb21", "dd/mm/yyyy", "2021/09/01");
  554. });
  555. });
  556. describe("AFExtractNums", function () {
  557. it("should extract numbers", async () => {
  558. let value = await myeval(`AFExtractNums("123 456 789")`);
  559. expect(value).toEqual(["123", "456", "789"]);
  560. value = await myeval(`AFExtractNums("123.456")`);
  561. expect(value).toEqual(["123", "456"]);
  562. value = await myeval(`AFExtractNums("123")`);
  563. expect(value).toEqual(["123"]);
  564. value = await myeval(`AFExtractNums(".123")`);
  565. expect(value).toEqual(["0", "123"]);
  566. value = await myeval(`AFExtractNums(",123")`);
  567. expect(value).toEqual(["0", "123"]);
  568. });
  569. });
  570. describe("AFMakeNumber", function () {
  571. it("should convert string to number", async () => {
  572. let value = await myeval(`AFMakeNumber("123.456")`);
  573. expect(value).toEqual(123.456);
  574. value = await myeval(`AFMakeNumber(123.456)`);
  575. expect(value).toEqual(123.456);
  576. value = await myeval(`AFMakeNumber("-123.456")`);
  577. expect(value).toEqual(-123.456);
  578. value = await myeval(`AFMakeNumber("-123,456")`);
  579. expect(value).toEqual(-123.456);
  580. value = await myeval(`AFMakeNumber("not a number")`);
  581. expect(value).toEqual(null);
  582. });
  583. });
  584. describe("AFMakeArrayFromList", function () {
  585. it("should split a string into an array of strings", async () => {
  586. const value = await myeval(`AFMakeArrayFromList("aaaa, bbbbbbb,cc,ddd, e")`);
  587. expect(value).toEqual(["aaaa", " bbbbbbb", "cc", "ddd", "e"]);
  588. });
  589. });
  590. describe("AFNumber_format", function () {
  591. it("should format a number", async () => {
  592. const refId = getId();
  593. const data = {
  594. objects: {
  595. field: [{
  596. id: refId,
  597. value: "",
  598. actions: {
  599. test1: [`AFNumber_Format(2, 0, 0, 0, "€", false);` + `event.source.value = event.value;`],
  600. test2: [`AFNumber_Format(1, 3, 0, 0, "$", true);` + `event.source.value = event.value;`],
  601. test3: [`AFNumber_Format(2, 0, 1, 0, "€", false);` + `event.source.value = event.value;`],
  602. test4: [`AFNumber_Format(2, 0, 2, 0, "€", false);` + `event.source.value = event.value;`],
  603. test5: [`AFNumber_Format(2, 0, 3, 0, "€", false);` + `event.source.value = event.value;`]
  604. },
  605. type: "text"
  606. }]
  607. },
  608. appInfo: {
  609. language: "en-US",
  610. platform: "Linux x86_64"
  611. },
  612. calculationOrder: [],
  613. dispatchEventName: "_dispatchMe"
  614. };
  615. sandbox.createSandbox(data);
  616. await sandbox.dispatchEventInSandbox({
  617. id: refId,
  618. value: "123456.789",
  619. name: "test1"
  620. });
  621. expect(send_queue.has(refId)).toEqual(true);
  622. expect(send_queue.get(refId)).toEqual({
  623. id: refId,
  624. value: "123,456.79€"
  625. });
  626. send_queue.delete(refId);
  627. await sandbox.dispatchEventInSandbox({
  628. id: refId,
  629. value: "223456.789",
  630. name: "test2"
  631. });
  632. expect(send_queue.has(refId)).toEqual(true);
  633. expect(send_queue.get(refId)).toEqual({
  634. id: refId,
  635. value: "$223456,8"
  636. });
  637. send_queue.delete(refId);
  638. await sandbox.dispatchEventInSandbox({
  639. id: refId,
  640. value: "-323456.789",
  641. name: "test3"
  642. });
  643. expect(send_queue.has(refId)).toEqual(true);
  644. expect(send_queue.get(refId)).toEqual({
  645. id: refId,
  646. value: "323,456.79€",
  647. textColor: ["RGB", 1, 0, 0]
  648. });
  649. send_queue.delete(refId);
  650. await sandbox.dispatchEventInSandbox({
  651. id: refId,
  652. value: "-423456.789",
  653. name: "test4"
  654. });
  655. expect(send_queue.has(refId)).toEqual(true);
  656. expect(send_queue.get(refId)).toEqual({
  657. id: refId,
  658. value: "(423,456.79€)"
  659. });
  660. send_queue.delete(refId);
  661. await sandbox.dispatchEventInSandbox({
  662. id: refId,
  663. value: "-52345.678",
  664. name: "test5"
  665. });
  666. expect(send_queue.has(refId)).toEqual(true);
  667. expect(send_queue.get(refId)).toEqual({
  668. id: refId,
  669. value: "(52,345.68€)",
  670. textColor: ["RGB", 1, 0, 0]
  671. });
  672. });
  673. });
  674. describe("AFNumber_Keystroke", function () {
  675. it("should validate a number on a keystroke event", async () => {
  676. const refId = getId();
  677. const data = {
  678. objects: {
  679. field: [{
  680. id: refId,
  681. value: "",
  682. actions: {
  683. Validate: [`AFNumber_Keystroke(null, 0, null, null, null, null);`]
  684. },
  685. type: "text",
  686. name: "MyField"
  687. }]
  688. },
  689. appInfo: {
  690. language: "en-US",
  691. platform: "Linux x86_64"
  692. },
  693. calculationOrder: [],
  694. dispatchEventName: "_dispatchMe"
  695. };
  696. sandbox.createSandbox(data);
  697. await sandbox.dispatchEventInSandbox({
  698. id: refId,
  699. value: "123456.789",
  700. name: "Keystroke",
  701. willCommit: true
  702. });
  703. expect(send_queue.has(refId)).toEqual(true);
  704. expect(send_queue.get(refId)).toEqual({
  705. id: refId,
  706. siblings: null,
  707. value: 123456.789,
  708. formattedValue: null
  709. });
  710. });
  711. it("should not validate a number on a keystroke event", async () => {
  712. const refId = getId();
  713. const data = {
  714. objects: {
  715. field: [{
  716. id: refId,
  717. value: "",
  718. actions: {
  719. Validate: [`AFNumber_Keystroke(null, 0, null, null, null, null);`]
  720. },
  721. type: "text",
  722. name: "MyField"
  723. }]
  724. },
  725. appInfo: {
  726. language: "en-US",
  727. platform: "Linux x86_64"
  728. },
  729. calculationOrder: [],
  730. dispatchEventName: "_dispatchMe"
  731. };
  732. sandbox.createSandbox(data);
  733. await sandbox.dispatchEventInSandbox({
  734. id: refId,
  735. value: "123s456.789",
  736. name: "Keystroke",
  737. willCommit: true
  738. });
  739. expect(send_queue.has("alert")).toEqual(true);
  740. expect(send_queue.get("alert")).toEqual({
  741. command: "alert",
  742. value: "The value entered does not match the format of the field [ MyField ]"
  743. });
  744. });
  745. });
  746. describe("AFPercent_Format", function () {
  747. it("should format a percentage", async () => {
  748. const refId = getId();
  749. const data = {
  750. objects: {
  751. field: [{
  752. id: refId,
  753. value: "",
  754. actions: {
  755. test1: [`AFPercent_Format(2, 1, false);` + `event.source.value = event.value;`],
  756. test2: [`AFPercent_Format(2, 1, true);` + `event.source.value = event.value;`]
  757. },
  758. type: "text"
  759. }]
  760. },
  761. appInfo: {
  762. language: "en-US",
  763. platform: "Linux x86_64"
  764. },
  765. calculationOrder: [],
  766. dispatchEventName: "_dispatchMe"
  767. };
  768. sandbox.createSandbox(data);
  769. await sandbox.dispatchEventInSandbox({
  770. id: refId,
  771. value: "0.456789",
  772. name: "test1"
  773. });
  774. expect(send_queue.has(refId)).toEqual(true);
  775. expect(send_queue.get(refId)).toEqual({
  776. id: refId,
  777. value: "45.68%"
  778. });
  779. send_queue.delete(refId);
  780. await sandbox.dispatchEventInSandbox({
  781. id: refId,
  782. value: "0.456789",
  783. name: "test2"
  784. });
  785. expect(send_queue.has(refId)).toEqual(true);
  786. expect(send_queue.get(refId)).toEqual({
  787. id: refId,
  788. value: "%45.68"
  789. });
  790. });
  791. });
  792. describe("AFDate_Format", function () {
  793. it("should format a date", async () => {
  794. const refId = getId();
  795. const data = {
  796. objects: {
  797. field: [{
  798. id: refId,
  799. value: "",
  800. actions: {
  801. test1: [`AFDate_Format(0);event.source.value = event.value;`],
  802. test2: [`AFDate_Format(12);event.source.value = event.value;`]
  803. },
  804. type: "text"
  805. }]
  806. },
  807. appInfo: {
  808. language: "en-US",
  809. platform: "Linux x86_64"
  810. },
  811. calculationOrder: [],
  812. dispatchEventName: "_dispatchMe"
  813. };
  814. sandbox.createSandbox(data);
  815. await sandbox.dispatchEventInSandbox({
  816. id: refId,
  817. value: "Sun Apr 15 2007 03:14:15",
  818. name: "test1"
  819. });
  820. expect(send_queue.has(refId)).toEqual(true);
  821. expect(send_queue.get(refId)).toEqual({
  822. id: refId,
  823. value: "4/15"
  824. });
  825. send_queue.delete(refId);
  826. await sandbox.dispatchEventInSandbox({
  827. id: refId,
  828. value: "Sun Apr 15 2007 03:14:15",
  829. name: "test2"
  830. });
  831. expect(send_queue.has(refId)).toEqual(true);
  832. expect(send_queue.get(refId)).toEqual({
  833. id: refId,
  834. value: "4/15/07 3:14 am"
  835. });
  836. });
  837. });
  838. describe("AFRange_Validate", function () {
  839. it("should validate a number in range [a, b]", async () => {
  840. const refId = getId();
  841. const data = {
  842. objects: {
  843. field: [{
  844. id: refId,
  845. value: "",
  846. actions: {
  847. Validate: [`AFRange_Validate(true, 123, true, 456);`]
  848. },
  849. type: "text"
  850. }]
  851. },
  852. appInfo: {
  853. language: "en-US",
  854. platform: "Linux x86_64"
  855. },
  856. calculationOrder: [],
  857. dispatchEventName: "_dispatchMe"
  858. };
  859. sandbox.createSandbox(data);
  860. await sandbox.dispatchEventInSandbox({
  861. id: refId,
  862. value: "321",
  863. name: "Keystroke",
  864. willCommit: true
  865. });
  866. expect(send_queue.has(refId)).toEqual(true);
  867. expect(send_queue.get(refId)).toEqual({
  868. id: refId,
  869. siblings: null,
  870. value: 321,
  871. formattedValue: null
  872. });
  873. });
  874. it("should invalidate a number out of range [a, b]", async () => {
  875. const refId = getId();
  876. const data = {
  877. objects: {
  878. field: [{
  879. id: refId,
  880. value: "",
  881. actions: {
  882. Validate: [`AFRange_Validate(true, 123, true, 456);`]
  883. },
  884. type: "text"
  885. }]
  886. },
  887. appInfo: {
  888. language: "en-US",
  889. platform: "Linux x86_64"
  890. },
  891. calculationOrder: [],
  892. dispatchEventName: "_dispatchMe"
  893. };
  894. sandbox.createSandbox(data);
  895. await sandbox.dispatchEventInSandbox({
  896. id: refId,
  897. value: "12",
  898. name: "Keystroke",
  899. willCommit: true
  900. });
  901. expect(send_queue.has("alert")).toEqual(true);
  902. expect(send_queue.get("alert")).toEqual({
  903. command: "alert",
  904. value: "Invalid value: must be greater than or equal to 123 and less than or equal to 456."
  905. });
  906. });
  907. });
  908. describe("AFSimple_Calculate", function () {
  909. it("should compute the sum of several fields", async () => {
  910. const refIds = [0, 1, 2, 3, 4].map(_ => getId());
  911. const data = {
  912. objects: {
  913. field1: [{
  914. id: refIds[0],
  915. value: "",
  916. actions: {},
  917. type: "text"
  918. }],
  919. field2: [{
  920. id: refIds[1],
  921. value: "",
  922. actions: {},
  923. type: "text"
  924. }],
  925. field3: [{
  926. id: refIds[2],
  927. value: "",
  928. actions: {},
  929. type: "text"
  930. }],
  931. field4: [{
  932. id: refIds[3],
  933. value: "",
  934. actions: {
  935. Calculate: [`AFSimple_Calculate("SUM", ["field1", "field2", "field3", "unknown"]);`]
  936. },
  937. type: "text"
  938. }],
  939. field5: [{
  940. id: refIds[4],
  941. value: "",
  942. actions: {
  943. Calculate: [`AFSimple_Calculate("SUM", "field1, field2, field3, unknown");`]
  944. },
  945. type: "text"
  946. }]
  947. },
  948. appInfo: {
  949. language: "en-US",
  950. platform: "Linux x86_64"
  951. },
  952. calculationOrder: [refIds[3], refIds[4]],
  953. dispatchEventName: "_dispatchMe"
  954. };
  955. sandbox.createSandbox(data);
  956. await sandbox.dispatchEventInSandbox({
  957. id: refIds[0],
  958. value: "1",
  959. name: "Keystroke",
  960. willCommit: true
  961. });
  962. expect(send_queue.has(refIds[3])).toEqual(true);
  963. expect(send_queue.get(refIds[3])).toEqual({
  964. id: refIds[3],
  965. siblings: null,
  966. value: 1,
  967. formattedValue: null
  968. });
  969. await sandbox.dispatchEventInSandbox({
  970. id: refIds[1],
  971. value: "2",
  972. name: "Keystroke",
  973. willCommit: true
  974. });
  975. expect(send_queue.has(refIds[3])).toEqual(true);
  976. expect(send_queue.get(refIds[3])).toEqual({
  977. id: refIds[3],
  978. siblings: null,
  979. value: 3,
  980. formattedValue: null
  981. });
  982. await sandbox.dispatchEventInSandbox({
  983. id: refIds[2],
  984. value: "3",
  985. name: "Keystroke",
  986. willCommit: true
  987. });
  988. expect(send_queue.has(refIds[3])).toEqual(true);
  989. expect(send_queue.get(refIds[3])).toEqual({
  990. id: refIds[3],
  991. siblings: null,
  992. value: 6,
  993. formattedValue: null
  994. });
  995. expect(send_queue.has(refIds[4])).toEqual(true);
  996. expect(send_queue.get(refIds[4])).toEqual({
  997. id: refIds[4],
  998. siblings: null,
  999. value: 6,
  1000. formattedValue: null
  1001. });
  1002. });
  1003. it("should compute the sum of several fields in fields tree", async () => {
  1004. const refIds = [0, 1, 2, 3, 4, 5].map(_ => getId());
  1005. const data = {
  1006. objects: {
  1007. field1: [{
  1008. id: refIds[0],
  1009. kidIds: [refIds[1], refIds[2]]
  1010. }],
  1011. "field1.field2": [{
  1012. id: refIds[1],
  1013. kidIds: [refIds[3]]
  1014. }],
  1015. "field1.field3": [{
  1016. id: refIds[2],
  1017. value: "",
  1018. actions: {},
  1019. type: "text"
  1020. }],
  1021. "field1.field2.field4": [{
  1022. id: refIds[3],
  1023. kidIds: [refIds[4]]
  1024. }],
  1025. "field1.field2.field4.field5": [{
  1026. id: refIds[4],
  1027. value: "",
  1028. actions: {},
  1029. type: "text"
  1030. }],
  1031. field6: [{
  1032. id: refIds[5],
  1033. value: "",
  1034. actions: {
  1035. Calculate: [`AFSimple_Calculate("SUM", "field1");`]
  1036. },
  1037. type: "text"
  1038. }]
  1039. },
  1040. appInfo: {
  1041. language: "en-US",
  1042. platform: "Linux x86_64"
  1043. },
  1044. calculationOrder: [refIds[5]],
  1045. dispatchEventName: "_dispatchMe"
  1046. };
  1047. sandbox.createSandbox(data);
  1048. await sandbox.dispatchEventInSandbox({
  1049. id: refIds[2],
  1050. value: "123",
  1051. name: "Keystroke",
  1052. willCommit: true
  1053. });
  1054. expect(send_queue.has(refIds[5])).toEqual(true);
  1055. expect(send_queue.get(refIds[5])).toEqual({
  1056. id: refIds[5],
  1057. siblings: null,
  1058. value: 123,
  1059. formattedValue: null
  1060. });
  1061. await sandbox.dispatchEventInSandbox({
  1062. id: refIds[4],
  1063. value: "456",
  1064. name: "Keystroke",
  1065. willCommit: true
  1066. });
  1067. expect(send_queue.has(refIds[5])).toEqual(true);
  1068. expect(send_queue.get(refIds[5])).toEqual({
  1069. id: refIds[5],
  1070. siblings: null,
  1071. value: 579,
  1072. formattedValue: null
  1073. });
  1074. });
  1075. });
  1076. describe("AFSpecial_KeystrokeEx", function () {
  1077. it("should validate a phone number on a keystroke event", async () => {
  1078. const refId = getId();
  1079. const data = {
  1080. objects: {
  1081. field: [{
  1082. id: refId,
  1083. value: "",
  1084. actions: {
  1085. Keystroke: [`AFSpecial_KeystrokeEx("9AXO");`]
  1086. },
  1087. type: "text"
  1088. }]
  1089. },
  1090. appInfo: {
  1091. language: "en-US",
  1092. platform: "Linux x86_64"
  1093. },
  1094. calculationOrder: [],
  1095. dispatchEventName: "_dispatchMe"
  1096. };
  1097. sandbox.createSandbox(data);
  1098. await sandbox.dispatchEventInSandbox({
  1099. id: refId,
  1100. value: "",
  1101. change: "3",
  1102. name: "Keystroke",
  1103. willCommit: false,
  1104. selStart: 0,
  1105. selEnd: 0
  1106. });
  1107. expect(send_queue.has(refId)).toEqual(true);
  1108. send_queue.delete(refId);
  1109. await sandbox.dispatchEventInSandbox({
  1110. id: refId,
  1111. value: "3",
  1112. change: "F",
  1113. name: "Keystroke",
  1114. willCommit: false,
  1115. selStart: 1,
  1116. selEnd: 1
  1117. });
  1118. expect(send_queue.has(refId)).toEqual(true);
  1119. send_queue.delete(refId);
  1120. await sandbox.dispatchEventInSandbox({
  1121. id: refId,
  1122. value: "3F",
  1123. change: "?",
  1124. name: "Keystroke",
  1125. willCommit: false,
  1126. selStart: 2,
  1127. selEnd: 2
  1128. });
  1129. expect(send_queue.has(refId)).toEqual(true);
  1130. send_queue.delete(refId);
  1131. await sandbox.dispatchEventInSandbox({
  1132. id: refId,
  1133. value: "3F?",
  1134. change: "@",
  1135. name: "Keystroke",
  1136. willCommit: false,
  1137. selStart: 3,
  1138. selEnd: 3
  1139. });
  1140. expect(send_queue.has(refId)).toEqual(true);
  1141. expect(send_queue.get(refId)).toEqual({
  1142. id: refId,
  1143. siblings: null,
  1144. value: "3F?",
  1145. selRange: [3, 3]
  1146. });
  1147. send_queue.delete(refId);
  1148. await sandbox.dispatchEventInSandbox({
  1149. id: refId,
  1150. value: "3F?",
  1151. change: "0",
  1152. name: "Keystroke",
  1153. willCommit: false,
  1154. selStart: 3,
  1155. selEnd: 3
  1156. });
  1157. expect(send_queue.has(refId)).toEqual(true);
  1158. send_queue.delete(refId);
  1159. await sandbox.dispatchEventInSandbox({
  1160. id: refId,
  1161. value: "3F?0",
  1162. name: "Keystroke",
  1163. willCommit: true,
  1164. selStart: 4,
  1165. selEnd: 4
  1166. });
  1167. expect(send_queue.has(refId)).toEqual(true);
  1168. expect(send_queue.get(refId)).toEqual({
  1169. id: refId,
  1170. siblings: null,
  1171. value: "3F?0",
  1172. formattedValue: null
  1173. });
  1174. });
  1175. });
  1176. describe("AFSpecial_Keystroke", function () {
  1177. it("should validate a zip code on a keystroke event", async () => {
  1178. const refId = getId();
  1179. const data = {
  1180. objects: {
  1181. field: [{
  1182. id: refId,
  1183. value: "",
  1184. actions: {
  1185. Keystroke: [`AFSpecial_Keystroke(0);`]
  1186. },
  1187. type: "text"
  1188. }]
  1189. },
  1190. appInfo: {
  1191. language: "en-US",
  1192. platform: "Linux x86_64"
  1193. },
  1194. calculationOrder: [],
  1195. dispatchEventName: "_dispatchMe"
  1196. };
  1197. sandbox.createSandbox(data);
  1198. let value = "";
  1199. const changes = "12345";
  1200. let i = 0;
  1201. for (; i < changes.length; i++) {
  1202. const change = changes.charAt(i);
  1203. await sandbox.dispatchEventInSandbox({
  1204. id: refId,
  1205. value,
  1206. change,
  1207. name: "Keystroke",
  1208. willCommit: false,
  1209. selStart: i,
  1210. selEnd: i
  1211. });
  1212. expect(send_queue.has(refId)).toEqual(true);
  1213. send_queue.delete(refId);
  1214. value += change;
  1215. }
  1216. await sandbox.dispatchEventInSandbox({
  1217. id: refId,
  1218. value,
  1219. change: "A",
  1220. name: "Keystroke",
  1221. willCommit: false,
  1222. selStart: i,
  1223. selEnd: i
  1224. });
  1225. expect(send_queue.has(refId)).toEqual(true);
  1226. expect(send_queue.get(refId)).toEqual({
  1227. id: refId,
  1228. siblings: null,
  1229. value,
  1230. selRange: [i, i]
  1231. });
  1232. send_queue.delete(refId);
  1233. });
  1234. it("should validate a US phone number (long) on a keystroke event", async () => {
  1235. const refId = getId();
  1236. const data = {
  1237. objects: {
  1238. field: [{
  1239. id: refId,
  1240. value: "",
  1241. actions: {
  1242. Keystroke: [`AFSpecial_Keystroke(2);`]
  1243. },
  1244. type: "text"
  1245. }]
  1246. },
  1247. appInfo: {
  1248. language: "en-US",
  1249. platform: "Linux x86_64"
  1250. },
  1251. calculationOrder: [],
  1252. dispatchEventName: "_dispatchMe"
  1253. };
  1254. sandbox.createSandbox(data);
  1255. let value = "";
  1256. const changes = "(123) 456-7890";
  1257. let i = 0;
  1258. for (; i < changes.length; i++) {
  1259. const change = changes.charAt(i);
  1260. await sandbox.dispatchEventInSandbox({
  1261. id: refId,
  1262. value,
  1263. change,
  1264. name: "Keystroke",
  1265. willCommit: false,
  1266. selStart: i,
  1267. selEnd: i
  1268. });
  1269. expect(send_queue.has(refId)).toEqual(true);
  1270. send_queue.delete(refId);
  1271. value += change;
  1272. }
  1273. await sandbox.dispatchEventInSandbox({
  1274. id: refId,
  1275. value,
  1276. change: "A",
  1277. name: "Keystroke",
  1278. willCommit: false,
  1279. selStart: i,
  1280. selEnd: i
  1281. });
  1282. expect(send_queue.has(refId)).toEqual(true);
  1283. expect(send_queue.get(refId)).toEqual({
  1284. id: refId,
  1285. siblings: null,
  1286. value,
  1287. selRange: [i, i]
  1288. });
  1289. send_queue.delete(refId);
  1290. });
  1291. it("should validate a US phone number (short) on a keystroke event", async () => {
  1292. const refId = getId();
  1293. const data = {
  1294. objects: {
  1295. field: [{
  1296. id: refId,
  1297. value: "",
  1298. actions: {
  1299. Keystroke: [`AFSpecial_Keystroke(2);`]
  1300. },
  1301. type: "text"
  1302. }]
  1303. },
  1304. appInfo: {
  1305. language: "en-US",
  1306. platform: "Linux x86_64"
  1307. },
  1308. calculationOrder: [],
  1309. dispatchEventName: "_dispatchMe"
  1310. };
  1311. sandbox.createSandbox(data);
  1312. let value = "";
  1313. const changes = "123-4567";
  1314. let i = 0;
  1315. for (; i < changes.length; i++) {
  1316. const change = changes.charAt(i);
  1317. await sandbox.dispatchEventInSandbox({
  1318. id: refId,
  1319. value,
  1320. change,
  1321. name: "Keystroke",
  1322. willCommit: false,
  1323. selStart: i,
  1324. selEnd: i
  1325. });
  1326. expect(send_queue.has(refId)).toEqual(true);
  1327. send_queue.delete(refId);
  1328. value += change;
  1329. }
  1330. await sandbox.dispatchEventInSandbox({
  1331. id: refId,
  1332. value,
  1333. change: "A",
  1334. name: "Keystroke",
  1335. willCommit: false,
  1336. selStart: i,
  1337. selEnd: i
  1338. });
  1339. expect(send_queue.has(refId)).toEqual(true);
  1340. expect(send_queue.get(refId)).toEqual({
  1341. id: refId,
  1342. siblings: null,
  1343. value,
  1344. selRange: [i, i]
  1345. });
  1346. send_queue.delete(refId);
  1347. });
  1348. });
  1349. describe("eMailValidate", function () {
  1350. it("should validate an e-mail address", async () => {
  1351. let value = await myeval(`eMailValidate(123)`);
  1352. expect(value).toEqual(false);
  1353. value = await myeval(`eMailValidate("foo@bar.com")`);
  1354. expect(value).toEqual(true);
  1355. value = await myeval(`eMailValidate("foo bar")`);
  1356. expect(value).toEqual(false);
  1357. });
  1358. });
  1359. describe("AFExactMatch", function () {
  1360. it("should check matching between regexs and a string", async () => {
  1361. let value = await myeval(`AFExactMatch(/\\d+/, "123")`);
  1362. expect(value).toEqual(true);
  1363. value = await myeval(`AFExactMatch(/\\d+/, "foo")`);
  1364. expect(value).toEqual(0);
  1365. value = await myeval(`AFExactMatch([/\\d+/, /[fo]*/], "foo")`);
  1366. expect(value).toEqual(2);
  1367. value = await myeval(`AFExactMatch([/\\d+/, /[fo]*/], "bar")`);
  1368. expect(value).toEqual(0);
  1369. });
  1370. });
  1371. });
  1372. });