f7
f7 is a spreadsheet formula execution library
git clone https://git.vogt.world/f7.git
Log | Files | README.md | LICENSE.md
← All files
name: src/test/js/execution/ExecutorEqualityComparisonTest.ts
-rw-r--r--
6345
  1import { RefException } from "../../../main/js/errors/RefException";
  2import { runner, it, describe } from "../testutils/TestUtils";
  3
  4describe("Executor.execute - Equality Comparison", function () {
  5  it("should work with numbers", function () {
  6    runner().addCell("Alpha", "A1", "= 1 = 1").addExpectedValue("Alpha", "A1", true).run();
  7    runner().addCell("Alpha", "A1", "= 1 = 2").addExpectedValue("Alpha", "A1", false).run();
  8    runner()
  9      .addCell("Alpha", "A1", "= 1.1928731 = 1.1928731")
 10      .addExpectedValue("Alpha", "A1", true)
 11      .run();
 12  });
 13
 14  it("should work with strings", function () {
 15    runner().addCell("Alpha", "A1", '= "Yes" = "Yes"').addExpectedValue("Alpha", "A1", true).run();
 16    runner().addCell("Alpha", "A1", '= "Yes" = "No"').addExpectedValue("Alpha", "A1", false).run();
 17    runner().addCell("Alpha", "A1", '= "" = ""').addExpectedValue("Alpha", "A1", true).run();
 18  });
 19
 20  it("should work with booleans", function () {
 21    runner().addCell("Alpha", "A1", "= TRUE = TRUE").addExpectedValue("Alpha", "A1", true).run();
 22    runner().addCell("Alpha", "A1", "= FALSE = FALSE").addExpectedValue("Alpha", "A1", true).run();
 23    runner().addCell("Alpha", "A1", "= TRUE = FALSE").addExpectedValue("Alpha", "A1", false).run();
 24  });
 25
 26  it("should work with array literals", function () {
 27    runner()
 28      .addCell("Alpha", "A1", "= {1, 2, 3} = {1, 2, 3}")
 29      .addExpectedValue("Alpha", "A1", true)
 30      .run();
 31    runner()
 32      .addCell("Alpha", "A1", "= {1, 2, 3} = {44}")
 33      .addExpectedValue("Alpha", "A1", false)
 34      .run();
 35    runner()
 36      .addCell("Alpha", "A1", "= {44, #REF!} = {44, #REF!}")
 37      .addExpectedValue("Alpha", "A1", true)
 38      .run();
 39  });
 40
 41  it("should work with number to boolean comparison", function () {
 42    runner().addCell("Alpha", "A1", "= 0 = TRUE").addExpectedValue("Alpha", "A1", false).run();
 43    runner().addCell("Alpha", "A1", "= 1 = TRUE").addExpectedValue("Alpha", "A1", false).run();
 44    runner().addCell("Alpha", "A1", "= 1 = FALSE").addExpectedValue("Alpha", "A1", false).run();
 45    runner().addCell("Alpha", "A1", "= 0 = FALSE").addExpectedValue("Alpha", "A1", false).run();
 46  });
 47
 48  it("should work with number to string comarison", function () {
 49    runner().addCell("Alpha", "A1", '= 0 = ""').addExpectedValue("Alpha", "A1", false).run();
 50    runner().addCell("Alpha", "A1", '= 0 = "0"').addExpectedValue("Alpha", "A1", false).run();
 51    runner().addCell("Alpha", "A1", '= 1 = "0"').addExpectedValue("Alpha", "A1", false).run();
 52    runner().addCell("Alpha", "A1", '= 1 = "1"').addExpectedValue("Alpha", "A1", false).run();
 53  });
 54
 55  it("should work with number to array literal comparison", function () {
 56    runner().addCell("Alpha", "A1", "= 0 = {0, 1, 2}").addExpectedValue("Alpha", "A1", true).run();
 57    runner().addCell("Alpha", "A1", "= 1 = {0, 1, 2}").addExpectedValue("Alpha", "A1", false).run();
 58  });
 59
 60  it("should work with number to blank comparison", function () {
 61    runner().addCell("Alpha", "A1", "= 0 = M9").addExpectedValue("Alpha", "A1", true).run();
 62    runner().addCell("Alpha", "A1", "= 1 = M9").addExpectedValue("Alpha", "A1", false).run();
 63    runner().addCell("Alpha", "A1", "= M9 = 0").addExpectedValue("Alpha", "A1", true).run();
 64    runner().addCell("Alpha", "A1", "= M9 = 1").addExpectedValue("Alpha", "A1", false).run();
 65    runner().addCell("Alpha", "A1", "= -1 = M9").addExpectedValue("Alpha", "A1", false).run();
 66    runner().addCell("Alpha", "A1", "= M9 = -1").addExpectedValue("Alpha", "A1", false).run();
 67  });
 68
 69  it("should work with string to boolean comparison", function () {
 70    runner().addCell("Alpha", "A1", '= "TRUE" = TRUE').addExpectedValue("Alpha", "A1", false).run();
 71    runner()
 72      .addCell("Alpha", "A1", '= "FALSE" = FALSE')
 73      .addExpectedValue("Alpha", "A1", false)
 74      .run();
 75  });
 76
 77  it("should work with string to blank comparison", function () {
 78    runner().addCell("Alpha", "A1", '= "" = M10').addExpectedValue("Alpha", "A1", true).run();
 79    runner().addCell("Alpha", "A1", '= M10 = ""').addExpectedValue("Alpha", "A1", true).run();
 80    runner().addCell("Alpha", "A1", '= " " = M10').addExpectedValue("Alpha", "A1", false).run();
 81    runner().addCell("Alpha", "A1", '= M10 = " "').addExpectedValue("Alpha", "A1", false).run();
 82    runner().addCell("Alpha", "A1", '= "One" = M10').addExpectedValue("Alpha", "A1", false).run();
 83    runner().addCell("Alpha", "A1", '= M10 = "One"').addExpectedValue("Alpha", "A1", false).run();
 84  });
 85
 86  it("should work with boolean to blank comparison", function () {
 87    runner().addCell("Alpha", "A1", "= TRUE = M10").addExpectedValue("Alpha", "A1", false).run();
 88    runner().addCell("Alpha", "A1", "= FALSE = M10").addExpectedValue("Alpha", "A1", true).run();
 89    runner().addCell("Alpha", "A1", "= M10 = TRUE").addExpectedValue("Alpha", "A1", false).run();
 90    runner().addCell("Alpha", "A1", "= M10 = FALSE").addExpectedValue("Alpha", "A1", true).run();
 91  });
 92
 93  it("should work with array literla to string comparison", function () {
 94    runner()
 95      .addCell("Alpha", "A1", '= {"A", "B"} = "A"')
 96      .addExpectedValue("Alpha", "A1", true)
 97      .run();
 98    runner()
 99      .addCell("Alpha", "A1", '= "A" = {"A", "B"}')
100      .addExpectedValue("Alpha", "A1", true)
101      .run();
102    runner()
103      .addCell("Alpha", "A1", '= "B" = {"A", "B"}')
104      .addExpectedValue("Alpha", "A1", false)
105      .run();
106  });
107
108  it("should work with array literal to boolean comparison", function () {
109    runner()
110      .addCell("Alpha", "A1", "= {TRUE, FALSE} = TRUE")
111      .addExpectedValue("Alpha", "A1", true)
112      .run();
113    runner()
114      .addCell("Alpha", "A1", "= TRUE = {TRUE, FALSE}")
115      .addExpectedValue("Alpha", "A1", true)
116      .run();
117    runner()
118      .addCell("Alpha", "A1", "= {FALSE, FALSE} = TRUE")
119      .addExpectedValue("Alpha", "A1", false)
120      .run();
121    runner()
122      .addCell("Alpha", "A1", "= TRUE = {FALSE, FALSE}")
123      .addExpectedValue("Alpha", "A1", false)
124      .run();
125  });
126
127  it("should pass errors throguh", function () {
128    runner()
129      .addCell("Alpha", "A1", "= 10 = #REF!")
130      .addExpectedValue("Alpha", "A1", new RefException())
131      .run();
132    runner()
133      .addCell("Alpha", "A1", "= #REF! = TRUE")
134      .addExpectedValue("Alpha", "A1", new RefException())
135      .run();
136  });
137});