name:
src/test/js/execution/CodeExecutorGeneralConcatenationTest.ts
-rw-r--r--
2154
1import { assert } from "chai";
2import { it, describe } from "../testutils/TestUtils";
3import { stub } from "sinon";
4import { F7Exception } from "../../../main/js/errors/F7Exception";
5import { F7ExceptionName } from "../../../main/js/errors/F7ExceptionName";
6import { CommonModels } from "../testutils/CommonModels";
7import { run, runWithLookups } from "../testutils/TestUtils";
8
9describe("CodeExecutor - General Concatenation Test", function () {
10 it("should work with strings", function () {
11 assert.deepEqual(run('"Hello" & "There"'), "HelloThere");
12 assert.deepEqual(run('"" & ""'), "");
13 assert.deepEqual(run('" " & " "'), " ");
14 });
15
16 it("should work with numbers", function () {
17 assert.deepEqual(run("0 & 1"), "01");
18 assert.deepEqual(run("0 & 0"), "00");
19 assert.deepEqual(run("131238 & 99281"), "13123899281");
20 assert.deepEqual(run("13.1238 & 99281"), "13.123899281");
21 assert.deepEqual(run("0.001 & 1.0"), "0.0011");
22 });
23
24 it("should work with booleans", function () {
25 assert.deepEqual(run("TRUE & TRUE"), "TRUETRUE");
26 assert.deepEqual(run("TRUE & FALSE"), "TRUEFALSE");
27 assert.deepEqual(run("FALSE & FALSE"), "FALSEFALSE");
28 });
29
30 it("should not work with errors", function () {
31 assert.deepEqual((run("1 & #DIV/0!") as F7Exception).name, F7ExceptionName.DIV);
32 });
33
34 it("should work with blanks", function () {
35 const lookup = stub();
36 const collateralLookup = stub();
37 collateralLookup.withArgs(CommonModels.A1, 2).returns(2);
38 collateralLookup.withArgs(CommonModels.A1, CommonModels.M44_RANGE).returns(null);
39 assert.deepEqual(runWithLookups("2 & M44", lookup, collateralLookup), "2");
40 assert.isTrue(collateralLookup.calledWith(CommonModels.A1, 2));
41 assert.isTrue(collateralLookup.calledWith(CommonModels.A1, CommonModels.M44_RANGE));
42 assert.equal(collateralLookup.callCount, 2);
43 assert.isTrue(lookup.notCalled);
44 });
45
46 it("should work with array literals", function () {
47 assert.deepEqual(run("{1} & {2}"), "12");
48 assert.deepEqual(run("{1, 2, 3} & {4, 5, 6}"), "14");
49 assert.deepEqual(run("{1, #NUM!} & {4, #REF!}"), "14");
50 });
51});