@odoo/o-spreadsheet 14.0.0 → 14.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/.eslintrc.json +20 -0
  2. package/.husky/post-checkout +9 -0
  3. package/.husky/pre-commit +39 -0
  4. package/.prettierignore +1 -0
  5. package/astToFormula.patch +0 -0
  6. package/demo/data.js +255 -0
  7. package/demo/index.html +9 -0
  8. package/demo/libs/Chart.bundle.js +20755 -0
  9. package/demo/main.js +101 -0
  10. package/doc/readme.md +46 -0
  11. package/package.json +3 -17
  12. package/rollup.config.js +23 -0
  13. package/src/base_plugin.ts +102 -0
  14. package/src/components/autofill.ts +146 -0
  15. package/src/components/bottom_bar.ts +199 -0
  16. package/src/components/color_picker.ts +150 -0
  17. package/src/components/composer/autocomplete_dropdown.ts +135 -0
  18. package/src/components/composer/composer.ts +487 -0
  19. package/src/components/composer/content_editable_helper.ts +146 -0
  20. package/src/components/figures/chart.ts +70 -0
  21. package/src/components/figures/container.ts +268 -0
  22. package/src/components/figures/text_figure.ts +36 -0
  23. package/src/components/grid.ts +635 -0
  24. package/src/components/helpers/dom_helpers.ts +7 -0
  25. package/src/components/helpers/drag_and_drop.ts +17 -0
  26. package/src/components/icons.ts +36 -0
  27. package/src/components/index.ts +1 -0
  28. package/src/components/menu.ts +288 -0
  29. package/src/components/overlay.ts +457 -0
  30. package/src/components/scrollbar.ts +22 -0
  31. package/src/components/selection_input.ts +168 -0
  32. package/src/components/side_panel/cell_is_rule_editor.ts +169 -0
  33. package/src/components/side_panel/chart_panel.ts +104 -0
  34. package/src/components/side_panel/color_scale_rule_editor.ts +145 -0
  35. package/src/components/side_panel/conditional_formatting.ts +396 -0
  36. package/src/components/side_panel/side_panel.ts +127 -0
  37. package/src/components/side_panel/translations_terms.ts +45 -0
  38. package/src/components/spreadsheet.ts +198 -0
  39. package/src/components/top_bar.ts +535 -0
  40. package/src/constants.ts +26 -0
  41. package/src/data.ts +149 -0
  42. package/src/fonts.ts +41 -0
  43. package/src/formulas/compiler.ts +258 -0
  44. package/src/formulas/composer_tokenizer.ts +70 -0
  45. package/src/formulas/index.ts +15 -0
  46. package/src/formulas/normalize.ts +52 -0
  47. package/src/formulas/parser.ts +280 -0
  48. package/src/formulas/range_tokenizer.ts +97 -0
  49. package/src/formulas/tokenizer.ts +242 -0
  50. package/src/functions/arguments.ts +114 -0
  51. package/src/functions/dates.ts +302 -0
  52. package/src/functions/helpers.ts +592 -0
  53. package/src/functions/index.ts +52 -0
  54. package/src/functions/module_database.ts +282 -0
  55. package/src/functions/module_date.ts +743 -0
  56. package/src/functions/module_info.ts +69 -0
  57. package/src/functions/module_logical.ts +208 -0
  58. package/src/functions/module_lookup.ts +185 -0
  59. package/src/functions/module_math.ts +1252 -0
  60. package/src/functions/module_operators.ts +291 -0
  61. package/src/functions/module_statistical.ts +882 -0
  62. package/src/functions/module_text.ts +370 -0
  63. package/src/helpers/color.ts +30 -0
  64. package/src/helpers/coordinates.ts +71 -0
  65. package/src/helpers/grid_manipulation.ts +68 -0
  66. package/src/helpers/index.ts +7 -0
  67. package/src/helpers/misc.ts +76 -0
  68. package/src/helpers/numbers.ts +117 -0
  69. package/src/helpers/uuid.ts +19 -0
  70. package/src/helpers/zones.ts +263 -0
  71. package/src/history.ts +186 -0
  72. package/src/index.ts +84 -0
  73. package/src/model.ts +261 -0
  74. package/src/plugins/autofill.ts +412 -0
  75. package/src/plugins/chart.ts +404 -0
  76. package/src/plugins/clipboard.ts +461 -0
  77. package/src/plugins/conditional_format.ts +445 -0
  78. package/src/plugins/core.ts +1502 -0
  79. package/src/plugins/edition.ts +157 -0
  80. package/src/plugins/evaluation.ts +428 -0
  81. package/src/plugins/figures.ts +123 -0
  82. package/src/plugins/formatting.ts +630 -0
  83. package/src/plugins/highlight.ts +187 -0
  84. package/src/plugins/index.ts +32 -0
  85. package/src/plugins/merge.ts +524 -0
  86. package/src/plugins/renderer.ts +571 -0
  87. package/src/plugins/selection.ts +562 -0
  88. package/src/plugins/selection_inputs.ts +326 -0
  89. package/src/registries/autofill_modifiers.ts +76 -0
  90. package/src/registries/autofill_rules.ts +98 -0
  91. package/src/registries/figure_registry.ts +30 -0
  92. package/src/registries/index.ts +7 -0
  93. package/src/registries/menu_items_registry.ts +110 -0
  94. package/src/registries/menus/cell_menu_registry.ts +79 -0
  95. package/src/registries/menus/col_menu_registry.ts +63 -0
  96. package/src/registries/menus/index.ts +6 -0
  97. package/src/registries/menus/menu_items_actions.ts +425 -0
  98. package/src/registries/menus/row_menu_registry.ts +63 -0
  99. package/src/registries/menus/sheet_menu_registry.ts +75 -0
  100. package/src/registries/menus/topbar_menu_registry.ts +204 -0
  101. package/src/registries/side_panel_registry.ts +26 -0
  102. package/src/registries/topbar_component_registry.ts +12 -0
  103. package/src/registry.ts +51 -0
  104. package/src/translation.ts +44 -0
  105. package/src/types/autofill.ts +48 -0
  106. package/src/types/chart.ts +26 -0
  107. package/src/types/commands.ts +716 -0
  108. package/src/types/conditional_formatting.ts +124 -0
  109. package/src/types/env.ts +13 -0
  110. package/src/types/functions.ts +35 -0
  111. package/src/types/getters.ts +103 -0
  112. package/src/types/index.ts +20 -0
  113. package/src/types/misc.ts +143 -0
  114. package/src/types/rendering.ts +41 -0
  115. package/src/types/workbook_data.ts +62 -0
  116. package/tests/__mocks__/uuid.ts +7 -0
  117. package/tests/canvas.mock.ts +34 -0
  118. package/tests/components/__mocks__/content_editable_helper.ts +79 -0
  119. package/tests/components/__mocks__/scrollbar.ts +18 -0
  120. package/tests/components/__snapshots__/autocomplete_dropdown_test.ts.snap +29 -0
  121. package/tests/components/__snapshots__/bottom_bar_test.ts.snap +75 -0
  122. package/tests/components/__snapshots__/context_menu_test.ts.snap +88 -0
  123. package/tests/components/__snapshots__/grid_test.ts.snap +60 -0
  124. package/tests/components/__snapshots__/spreadsheet_test.ts.snap +455 -0
  125. package/tests/components/__snapshots__/top_bar_test.ts.snap +705 -0
  126. package/tests/components/autocomplete_dropdown_test.ts +315 -0
  127. package/tests/components/autofill_test.ts +167 -0
  128. package/tests/components/bottom_bar_test.ts +262 -0
  129. package/tests/components/chart_side_panel_test.ts +123 -0
  130. package/tests/components/composer_test.ts +400 -0
  131. package/tests/components/context_menu_test.ts +825 -0
  132. package/tests/components/grid_manipulation_test.ts +163 -0
  133. package/tests/components/grid_test.ts +581 -0
  134. package/tests/components/overlay_test.ts +541 -0
  135. package/tests/components/selection_input_test.ts +259 -0
  136. package/tests/components/side_panel_test.ts +148 -0
  137. package/tests/components/spreadsheet_test.ts +194 -0
  138. package/tests/components/top_bar_test.ts +427 -0
  139. package/tests/data_test.ts +175 -0
  140. package/tests/dom_helper.ts +42 -0
  141. package/tests/formulas/__snapshots__/compiler_test.ts.snap +302 -0
  142. package/tests/formulas/compiler_test.ts +266 -0
  143. package/tests/formulas/composer_tokenizer_test.ts +137 -0
  144. package/tests/formulas/expressions_test.ts +57 -0
  145. package/tests/formulas/formulas_test.ts +80 -0
  146. package/tests/formulas/normalize_test.ts +82 -0
  147. package/tests/formulas/parser_test.ts +224 -0
  148. package/tests/formulas/range_tokenizer_test.ts +187 -0
  149. package/tests/formulas/tokenizer_test.ts +164 -0
  150. package/tests/functions/arguments_test.ts +141 -0
  151. package/tests/functions/dates_test.ts +1081 -0
  152. package/tests/functions/functions_test.ts +53 -0
  153. package/tests/functions/helper_test.ts +98 -0
  154. package/tests/functions/module_database_test.ts +311 -0
  155. package/tests/functions/module_date_test.ts +941 -0
  156. package/tests/functions/module_info_test.ts +139 -0
  157. package/tests/functions/module_logical_test.ts +369 -0
  158. package/tests/functions/module_lookup_test.ts +541 -0
  159. package/tests/functions/module_math_test.ts +2482 -0
  160. package/tests/functions/module_operators_test.ts +955 -0
  161. package/tests/functions/module_statistical_test.ts +2014 -0
  162. package/tests/functions/module_text_test.ts +667 -0
  163. package/tests/helpers/coordinates_test.ts +25 -0
  164. package/tests/helpers/misc_test.ts +95 -0
  165. package/tests/helpers/numbers_test.ts +196 -0
  166. package/tests/helpers/zones_test.ts +97 -0
  167. package/tests/helpers.ts +384 -0
  168. package/tests/menu_items_registry_test.ts +540 -0
  169. package/tests/model/plugins/__snapshots__/chart_test.ts.snap +90 -0
  170. package/tests/model/plugins/chart_test.ts +562 -0
  171. package/tests/model_test.ts +82 -0
  172. package/tests/plugins/__snapshots__/conditional_formatting_test.ts.snap +131 -0
  173. package/tests/plugins/__snapshots__/renderer_test.ts.snap +371 -0
  174. package/tests/plugins/autofill_test.ts +457 -0
  175. package/tests/plugins/borders_test.ts +295 -0
  176. package/tests/plugins/clipboard_test.ts +1180 -0
  177. package/tests/plugins/conditional_formatting_test.ts +1253 -0
  178. package/tests/plugins/core_test.ts +614 -0
  179. package/tests/plugins/edition_test.ts +100 -0
  180. package/tests/plugins/evaluation_async_test.ts +332 -0
  181. package/tests/plugins/evaluation_dates_test.ts +79 -0
  182. package/tests/plugins/evaluation_test.ts +901 -0
  183. package/tests/plugins/figures_test.ts +327 -0
  184. package/tests/plugins/formatting_test.ts +391 -0
  185. package/tests/plugins/grid_manipulation_test.ts +1366 -0
  186. package/tests/plugins/highlight_test.ts +413 -0
  187. package/tests/plugins/history_test.ts +142 -0
  188. package/tests/plugins/import_export_test.ts +276 -0
  189. package/tests/plugins/merges_test.ts +490 -0
  190. package/tests/plugins/navigation_test.ts +181 -0
  191. package/tests/plugins/plugins/evaluation_test.ts +111 -0
  192. package/tests/plugins/renderer_test.ts +598 -0
  193. package/tests/plugins/resizing_test.ts +152 -0
  194. package/tests/plugins/selection_input_test.ts +409 -0
  195. package/tests/plugins/selection_test.ts +442 -0
  196. package/tests/plugins/sheets_test.ts +643 -0
  197. package/tests/plugins/style_test.ts +90 -0
  198. package/tsconfig.json +22 -0
@@ -0,0 +1,667 @@
1
+ import { evaluateCell, evaluateGrid } from "../helpers";
2
+
3
+ describe("text", () => {
4
+ //----------------------------------------------------------------------------
5
+ // CHAR
6
+ //----------------------------------------------------------------------------
7
+
8
+ test("CHAR: functional tests on simple arguments", () => {
9
+ expect(evaluateCell("A1", { A1: "=CHAR()" })).toBe("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
10
+ expect(evaluateCell("A1", { A1: "=CHAR(65)" })).toBe("A");
11
+ expect(evaluateCell("A1", { A1: "=CHAR(122)" })).toBe("z");
12
+ expect(evaluateCell("A1", { A1: "=CHAR(57)" })).toBe("9");
13
+ expect(evaluateCell("A1", { A1: "=CHAR(-1)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
14
+ expect(evaluateCell("A1", { A1: "=CHAR(65.9)" })).toBe("A");
15
+ });
16
+
17
+ test("CHAR: casting tests on simple arguments", () => {
18
+ expect(evaluateCell("A1", { A1: '=CHAR("65")' })).toBe("A");
19
+ });
20
+
21
+ test("CHAR: functional tests on cell arguments", () => {
22
+ expect(evaluateCell("A1", { A1: "=CHAR(A2)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
23
+ expect(evaluateCell("A1", { A1: "=CHAR(A2)", A2: "66" })).toBe("B");
24
+ expect(evaluateCell("A1", { A1: "=CHAR(A2)", A2: "121" })).toBe("y");
25
+ expect(evaluateCell("A1", { A1: "=CHAR(A2)", A2: "56" })).toBe("8");
26
+ expect(evaluateCell("A1", { A1: "=CHAR(A2)", A2: "-1" })).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
27
+ expect(evaluateCell("A1", { A1: "=CHAR(A2)", A2: "66.9" })).toBe("B");
28
+ });
29
+
30
+ test("CHAR: casting tests on cell arguments", () => {
31
+ expect(evaluateCell("A1", { A1: "=CHAR(A2)", A2: '"68"' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
32
+ expect(evaluateCell("A1", { A1: "=CHAR(A2)", A2: '="68"' })).toBe("D");
33
+ });
34
+
35
+ //----------------------------------------------------------------------------
36
+ // CONCATENATE
37
+ //----------------------------------------------------------------------------
38
+
39
+ test("CONCATENATE: functional tests on simple arguments", () => {
40
+ expect(evaluateCell("A1", { A1: "=CONCATENATE()" })).toBe("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
41
+ expect(evaluateCell("A1", { A1: "=CONCATENATE( , )" })).toBe("");
42
+ expect(evaluateCell("A1", { A1: "=CONCATENATE( , 1)" })).toBe("1");
43
+ expect(evaluateCell("A1", { A1: "=CONCATENATE(42)" })).toBe("42");
44
+ expect(evaluateCell("A1", { A1: "=CONCATENATE(42, 24)" })).toBe("4224");
45
+ expect(evaluateCell("A1", { A1: "=CONCATENATE(42, -24)" })).toBe("42-24");
46
+ expect(evaluateCell("A1", { A1: "=CONCATENATE(42, 0.42)" })).toBe("420.42");
47
+ expect(evaluateCell("A1", { A1: "=CONCATENATE(42, 42%)" })).toBe("420.42");
48
+ expect(evaluateCell("A1", { A1: '=CONCATENATE(1, "")' })).toBe("1");
49
+ expect(evaluateCell("A1", { A1: '=CONCATENATE(1, " ")' })).toBe("1 ");
50
+ expect(evaluateCell("A1", { A1: '=CONCATENATE(1, "3")' })).toBe("13");
51
+ expect(evaluateCell("A1", { A1: '=CONCATENATE(1, "-3")' })).toBe("1-3");
52
+ expect(evaluateCell("A1", { A1: "=CONCATENATE(1, TRUE)" })).toBe("1TRUE");
53
+ expect(evaluateCell("A1", { A1: "=CONCATENATE(1, FALSE)" })).toBe("1FALSE");
54
+ expect(evaluateCell("A1", { A1: '=CONCATENATE(1, "3%")' })).toBe("13%");
55
+ expect(evaluateCell("A1", { A1: '=CONCATENATE("ki", "kou")' })).toBe("kikou");
56
+ expect(evaluateCell("A1", { A1: '=CONCATENATE("TRUE", TRUE)' })).toBe("TRUETRUE");
57
+ });
58
+
59
+ test("CONCATENATE: functional tests on cell arguments", () => {
60
+ expect(evaluateCell("A1", { A1: "=CONCATENATE(A2, A3)" })).toBe("");
61
+ expect(evaluateCell("A1", { A1: "=CONCATENATE(A2, A3)", A2: "1" })).toBe("1");
62
+ expect(evaluateCell("A1", { A1: "=CONCATENATE(A2, A3)", A2: "1", A3: "42" })).toBe("142");
63
+ expect(evaluateCell("A1", { A1: "=CONCATENATE(A2, A3)", A2: "42", A3: '""' })).toBe('42""');
64
+ expect(evaluateCell("A1", { A1: "=CONCATENATE(A2, A3)", A2: "42", A3: '"42"' })).toBe('42"42"');
65
+ expect(evaluateCell("A1", { A1: "=CONCATENATE(A2, A3)", A2: "42", A3: "TRUE" })).toBe("42TRUE");
66
+ expect(evaluateCell("A1", { A1: "=CONCATENATE(A2, A3)", A2: '"TRUE"', A3: "TRUE" })).toBe(
67
+ '"TRUE"TRUE'
68
+ );
69
+ expect(evaluateCell("A1", { A1: "=CONCATENATE(A2, A3)", A2: "42", A3: '=""' })).toBe("42");
70
+ expect(evaluateCell("A1", { A1: "=CONCATENATE(A2, A3)", A2: "42", A3: '=" "' })).toBe("42 ");
71
+ expect(evaluateCell("A1", { A1: "=CONCATENATE(A2, A3)", A2: "42", A3: '="24"' })).toBe("4224");
72
+ });
73
+
74
+ // prettier-ignore
75
+ test("CONCATENATE: functional tests on range arguments", () => {
76
+ const grid = {
77
+ A1: "=CONCATENATE(A2:A4)",
78
+ B1: "=CONCATENATE(B2:B4)",
79
+ C1: "=CONCATENATE(C2:C4)",
80
+
81
+ A2: "9", A3: "test", A4: '"42"',
82
+ B2: "tRuE", B3: '="123"', B4: '="tset"',
83
+ C2: "7%", C3: '"8%"', C4: '=""',
84
+ };
85
+
86
+ const gridResult = evaluateGrid(grid);
87
+ expect(gridResult.A1).toBe('9test"42"');
88
+ expect(gridResult.B1).toBe("TRUE123tset");
89
+ expect(gridResult.C1).toBe('0.07"8%"');
90
+ });
91
+
92
+ //----------------------------------------------------------------------------
93
+ // EXACT
94
+ //----------------------------------------------------------------------------
95
+
96
+ test("EXACT: functional tests on simple arguments", () => {
97
+ expect(evaluateCell("A1", { A1: "=EXACT(,)" })).toBe(true);
98
+ expect(evaluateCell("A1", { A1: '=EXACT(,"")' })).toBe(true);
99
+ expect(evaluateCell("A1", { A1: '=EXACT("test","test")' })).toBe(true);
100
+ expect(evaluateCell("A1", { A1: '=EXACT("test","Test")' })).toBe(false);
101
+ expect(evaluateCell("A1", { A1: '=EXACT("test"," test ")' })).toBe(false);
102
+ });
103
+
104
+ test("EXACT: casting tests on simple arguments", () => {
105
+ expect(evaluateCell("A1", { A1: "=EXACT(123, 123)" })).toBe(true);
106
+ expect(evaluateCell("A1", { A1: "=EXACT(123, 1234)" })).toBe(false);
107
+ expect(evaluateCell("A1", { A1: '=EXACT(123, "123")' })).toBe(true);
108
+ expect(evaluateCell("A1", { A1: '=EXACT(TRUE, "TRUE")' })).toBe(true);
109
+ });
110
+
111
+ test("EXACT: functional tests on cell arguments", () => {
112
+ expect(evaluateCell("A1", { A1: "=EXACT(A2, A3)" })).toBe(true);
113
+ expect(evaluateCell("A1", { A1: "=EXACT(A2, A3)", A2: "test", A3: "test" })).toBe(true);
114
+ expect(evaluateCell("A1", { A1: "=EXACT(A2, A3)", A2: "test", A3: "Test" })).toBe(false);
115
+ });
116
+
117
+ test("EXACT: casting tests on cell arguments", () => {
118
+ expect(evaluateCell("A1", { A1: "=EXACT(A2, A3)", A2: "TRUE", A3: "TRUE" })).toBe(true);
119
+ expect(evaluateCell("A1", { A1: "=EXACT(A2, A3)", A2: "TRUE", A3: "FALSE" })).toBe(false);
120
+ expect(evaluateCell("A1", { A1: "=EXACT(A2, A3)", A2: "456", A3: "456" })).toBe(true);
121
+ expect(evaluateCell("A1", { A1: "=EXACT(A2, A3)", A2: "456", A3: '"456"' })).toBe(false);
122
+ expect(evaluateCell("A1", { A1: "=EXACT(A2, A3)", A2: "456", A3: '="456"' })).toBe(true);
123
+ });
124
+
125
+ //----------------------------------------------------------------------------
126
+ // FIND
127
+ //----------------------------------------------------------------------------
128
+
129
+ test("FIND: functional tests on simple arguments", () => {
130
+ expect(evaluateCell("A1", { A1: "=FIND( , )" })).toBe("#ERROR"); // @compatibility: on google sheets, return #N/A
131
+ expect(evaluateCell("A1", { A1: '=FIND("", "")' })).toBe("#ERROR"); // @compatibility: on google sheets, return #N/A
132
+ expect(evaluateCell("A1", { A1: "=FIND( , , )" })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
133
+ expect(evaluateCell("A1", { A1: '=FIND( , "", )' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
134
+ expect(evaluateCell("A1", { A1: '=FIND("C", "ABCD")' })).toBe(3);
135
+ expect(evaluateCell("A1", { A1: '=FIND("C", "ABCD", 0)' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
136
+ expect(evaluateCell("A1", { A1: '=FIND("C", "ABCD", 1)' })).toBe(3);
137
+ expect(evaluateCell("A1", { A1: '=FIND("C", "ABCD", 2)' })).toBe(3);
138
+ expect(evaluateCell("A1", { A1: '=FIND("C", "ABCD", 3)' })).toBe(3);
139
+ expect(evaluateCell("A1", { A1: '=FIND("C", "ABCD", 4)' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
140
+ expect(evaluateCell("A1", { A1: '=FIND("C", "ABCDC", 4)' })).toBe(5);
141
+ });
142
+
143
+ test("FIND: functional tests on cell arguments", () => {
144
+ expect(evaluateCell("A1", { A1: "=FIND(A2, A3)", A2: "do", A3: "Odoo" })).toBe(2);
145
+ expect(
146
+ evaluateCell("A1", { A1: "=FIND(A2, A3, A4)", A2: "do", A3: "Odoo Docs", A4: "1" })
147
+ ).toBe(2);
148
+ expect(
149
+ evaluateCell("A1", { A1: "=FIND(A2, A3, A4)", A2: "do", A3: "Odoo Docs", A4: "4" })
150
+ ).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
151
+ expect(
152
+ evaluateCell("A1", { A1: "=FIND(A2, A3, A4)", A2: "S", A3: "Spreadsheet", A4: "1" })
153
+ ).toBe(1);
154
+ expect(
155
+ evaluateCell("A1", { A1: "=FIND(A2, A3, A4)", A2: "S", A3: "Spreadsheet", A4: "6" })
156
+ ).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
157
+ expect(
158
+ evaluateCell("A1", { A1: "=FIND(A2, A3, A4)", A2: "S", A3: "Spreadsheet", A4: "8" })
159
+ ).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
160
+ expect(evaluateCell("A1", { A1: "=FIND(A2, A3)", A2: "7", A3: "No.7 Doc" })).toBe(4);
161
+ });
162
+
163
+ test("FIND: casting tests on cell arguments", () => {
164
+ expect(
165
+ evaluateCell("A1", { A1: "=FIND(A2, A3, A4)", A2: "S", A3: "Spreadsheet", A4: '="6"' })
166
+ ).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
167
+ expect(
168
+ evaluateCell("A1", { A1: "=FIND(A2, A3, A4)", A2: "S", A3: "Spreadsheet", A4: "TRUE" })
169
+ ).toBe(1);
170
+ expect(evaluateCell("A1", { A1: "=FIND(A2, A3, A4)", A2: "U", A3: "TRUE", A4: "1" })).toBe(3);
171
+ expect(
172
+ evaluateCell("A1", { A1: "=FIND(A2, A3, A4)", A2: "TRUE", A3: "FALSETRUE", A4: "1" })
173
+ ).toBe(6);
174
+ });
175
+
176
+ //----------------------------------------------------------------------------
177
+ // JOIN
178
+ //----------------------------------------------------------------------------
179
+
180
+ test("JOIN: functional tests on simple arguments", () => {
181
+ expect(evaluateCell("A1", { A1: "=JOIN()" })).toBe("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
182
+ expect(evaluateCell("A1", { A1: "=JOIN( , )" })).toBe("");
183
+ expect(evaluateCell("A1", { A1: "=JOIN( , 1)" })).toBe("1");
184
+ expect(evaluateCell("A1", { A1: '=JOIN("-", 1)' })).toBe("1");
185
+ expect(evaluateCell("A1", { A1: "=JOIN( , 1, 2, 3)" })).toBe("123");
186
+ expect(evaluateCell("A1", { A1: '=JOIN("", 1, 2, 3)' })).toBe("123");
187
+ expect(evaluateCell("A1", { A1: '=JOIN("-", 1, 2, 3)' })).toBe("1-2-3");
188
+ expect(evaluateCell("A1", { A1: '=JOIN("9", 1, 2, 3)' })).toBe("19293");
189
+ expect(evaluateCell("A1", { A1: '=JOIN(9, "1", "2", "3")' })).toBe("19293");
190
+ expect(evaluateCell("A1", { A1: "=JOIN(TRUE, 1, 2, 3)" })).toBe("1TRUE2TRUE3");
191
+ });
192
+
193
+ test("JOIN: functional tests on cell arguments", () => {
194
+ expect(evaluateCell("A1", { A1: "=JOIN(A2, A3)" })).toBe("");
195
+ expect(evaluateCell("A1", { A1: "=JOIN(A2, A3)", A3: "1" })).toBe("1");
196
+ expect(evaluateCell("A1", { A1: "=JOIN(A2, A3)", A2: "-", A3: "1" })).toBe("1");
197
+ expect(evaluateCell("A1", { A1: "=JOIN(A2, A3, A4, A5)", A3: "1", A4: "2", A5: "3" })).toBe(
198
+ "123"
199
+ );
200
+ expect(
201
+ evaluateCell("A1", { A1: "=JOIN(A2, A3, A4, A5)", A2: '=""', A3: "1", A4: "2", A5: "3" })
202
+ ).toBe("123");
203
+ expect(
204
+ evaluateCell("A1", { A1: "=JOIN(A2, A3, A4, A5)", A2: "-", A3: "1", A4: "2", A5: "3" })
205
+ ).toBe("1-2-3");
206
+ expect(
207
+ evaluateCell("A1", { A1: "=JOIN(A2, A3, A4, A5)", A2: '="9"', A3: "1", A4: "2", A5: "3" })
208
+ ).toBe("19293");
209
+ expect(
210
+ evaluateCell("A1", {
211
+ A1: "=JOIN(A2, A3, A4, A5)",
212
+ A2: "9",
213
+ A3: '="1"',
214
+ A4: '="2"',
215
+ A5: '="3"',
216
+ })
217
+ ).toBe("19293");
218
+ expect(
219
+ evaluateCell("A1", { A1: "=JOIN(A2, A3, A4, A5)", A2: "TRUE", A3: "1", A4: "2", A5: "3" })
220
+ ).toBe("1TRUE2TRUE3");
221
+ });
222
+
223
+ // prettier-ignore
224
+ test("JOIN: functional tests on range arguments", () => {
225
+ const grid = {
226
+ A1: '=JOIN("*", A2:A4)',
227
+ B1: '=JOIN(42, B2:B4)',
228
+ C1: '=JOIN(",", C2:C4)',
229
+
230
+ A2: "9", A3: "test", A4: '"42"',
231
+ B2: "tRuE", B3: '="123"', B4: '="tset"',
232
+ C2: "7%", C3: '"8%"', C4: '=""',
233
+ };
234
+
235
+ const gridResult = evaluateGrid(grid);
236
+ expect(gridResult.A1).toBe('9*test*"42"');
237
+ expect(gridResult.B1).toBe("TRUE4212342tset");
238
+ expect(gridResult.C1).toBe('0.07,"8%",');
239
+ });
240
+
241
+ //----------------------------------------------------------------------------
242
+ // LEFT
243
+ //----------------------------------------------------------------------------
244
+
245
+ test("LEFT: functional tests on simple arguments", () => {
246
+ expect(evaluateCell("A1", { A1: "=LEFT()" })).toBe("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
247
+ expect(evaluateCell("A1", { A1: '=LEFT("kikou")' })).toBe("k");
248
+ expect(evaluateCell("A1", { A1: '=LEFT("123")' })).toBe("1");
249
+ expect(evaluateCell("A1", { A1: "=LEFT(123)" })).toBe("1");
250
+ expect(evaluateCell("A1", { A1: "=LEFT(TRUE)" })).toBe("T");
251
+ expect(evaluateCell("A1", { A1: "=LEFT( , )" })).toBe("");
252
+ expect(evaluateCell("A1", { A1: '=LEFT("kikou", )' })).toBe("");
253
+ expect(evaluateCell("A1", { A1: '=LEFT("kikou", -1)' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
254
+ expect(evaluateCell("A1", { A1: '=LEFT("kikou", 0)' })).toBe("");
255
+ expect(evaluateCell("A1", { A1: '=LEFT("kikou", 1)' })).toBe("k");
256
+ expect(evaluateCell("A1", { A1: '=LEFT("kikou", 2)' })).toBe("ki");
257
+ expect(evaluateCell("A1", { A1: '=LEFT("kikou", 6)' })).toBe("kikou");
258
+ expect(evaluateCell("A1", { A1: '=LEFT("kikou", 99)' })).toBe("kikou");
259
+ expect(evaluateCell("A1", { A1: '=LEFT("kikou", "2")' })).toBe("ki");
260
+ });
261
+
262
+ test("LEFT: functional tests on cell arguments", () => {
263
+ expect(evaluateCell("A1", { A1: "=LEFT(A2)" })).toBe("");
264
+ expect(evaluateCell("A1", { A1: "=LEFT(A2)", A2: "kikou" })).toBe("k");
265
+ expect(evaluateCell("A1", { A1: "=LEFT(A2)", A2: '="123"' })).toBe("1");
266
+ expect(evaluateCell("A1", { A1: "=LEFT(A2)", A2: "123" })).toBe("1");
267
+ expect(evaluateCell("A1", { A1: "=LEFT(A2)", A2: "TRUE" })).toBe("T");
268
+ expect(evaluateCell("A1", { A1: "=LEFT(A2, A3)" })).toBe("");
269
+ expect(evaluateCell("A1", { A1: "=LEFT(A2, A3)", A2: "kikou" })).toBe("");
270
+ expect(evaluateCell("A1", { A1: "=LEFT(A2, A3)", A2: "kikou", A3: "-1" })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
271
+ expect(evaluateCell("A1", { A1: "=LEFT(A2, A3)", A2: "kikou", A3: "0" })).toBe("");
272
+ expect(evaluateCell("A1", { A1: "=LEFT(A2, A3)", A2: "kikou", A3: "1" })).toBe("k");
273
+ expect(evaluateCell("A1", { A1: "=LEFT(A2, A3)", A2: "kikou", A3: "2" })).toBe("ki");
274
+ expect(evaluateCell("A1", { A1: "=LEFT(A2, A3)", A2: "kikou", A3: "6" })).toBe("kikou");
275
+ expect(evaluateCell("A1", { A1: "=LEFT(A2, A3)", A2: "kikou", A3: "99" })).toBe("kikou");
276
+ expect(evaluateCell("A1", { A1: "=LEFT(A2, A3)", A2: "kikou", A3: '="2"' })).toBe("ki");
277
+ });
278
+
279
+ //----------------------------------------------------------------------------
280
+ // LEN
281
+ //----------------------------------------------------------------------------
282
+
283
+ test("LEN: functional tests on simple arguments", () => {
284
+ expect(evaluateCell("A1", { A1: "=LEN()" })).toBe("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
285
+ expect(evaluateCell("A1", { A1: "=LEN(0)" })).toBe(1);
286
+ expect(evaluateCell("A1", { A1: "=LEN(42)" })).toBe(2);
287
+ expect(evaluateCell("A1", { A1: "=LEN(-4.42)" })).toBe(5);
288
+ expect(evaluateCell("A1", { A1: "=LEN(TRUE)" })).toBe(4);
289
+ expect(evaluateCell("A1", { A1: "=LEN(FALSE)" })).toBe(5);
290
+ expect(evaluateCell("A1", { A1: "=LEN(FALSE)" })).toBe(5);
291
+ expect(evaluateCell("A1", { A1: '=LEN("")' })).toBe(0);
292
+ expect(evaluateCell("A1", { A1: '=LEN(" ")' })).toBe(1);
293
+ expect(evaluateCell("A1", { A1: '=LEN("42")' })).toBe(2);
294
+ expect(evaluateCell("A1", { A1: '=LEN("オドゥ")' })).toBe(3);
295
+ });
296
+
297
+ test("LEN: functional tests on cell arguments", () => {
298
+ expect(evaluateCell("A1", { A1: "=LEN(A2)" })).toBe(0);
299
+ expect(evaluateCell("A1", { A1: "=LEN(A2)", A2: " " })).toBe(1);
300
+ expect(evaluateCell("A1", { A1: "=LEN(A2)", A2: "0" })).toBe(1);
301
+ expect(evaluateCell("A1", { A1: "=LEN(A2)", A2: "42" })).toBe(2);
302
+ expect(evaluateCell("A1", { A1: "=LEN(A2)", A2: "TRUE" })).toBe(4);
303
+ expect(evaluateCell("A1", { A1: "=LEN(A2)", A2: "FALSE" })).toBe(5);
304
+ expect(evaluateCell("A1", { A1: "=LEN(A2)", A2: '""' })).toBe(2);
305
+ expect(evaluateCell("A1", { A1: "=LEN(A2)", A2: '" "' })).toBe(3);
306
+ expect(evaluateCell("A1", { A1: "=LEN(A2)", A2: '"42"' })).toBe(4);
307
+ expect(evaluateCell("A1", { A1: "=LEN(A2)", A2: '=""' })).toBe(0);
308
+ expect(evaluateCell("A1", { A1: "=LEN(A2)", A2: '=" "' })).toBe(1);
309
+ expect(evaluateCell("A1", { A1: "=LEN(A2)", A2: '="42"' })).toBe(2);
310
+ });
311
+
312
+ //----------------------------------------------------------------------------
313
+ // LOWER
314
+ //----------------------------------------------------------------------------
315
+
316
+ test("LOWER: functional tests on simple arguments", () => {
317
+ expect(evaluateCell("A1", { A1: "=LOWER()" })).toBe("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
318
+ expect(evaluateCell("A1", { A1: "=LOWER(0)" })).toBe("0");
319
+ expect(evaluateCell("A1", { A1: "=LOWER(42)" })).toBe("42");
320
+ expect(evaluateCell("A1", { A1: "=LOWER(TRUE)" })).toBe("true");
321
+ expect(evaluateCell("A1", { A1: "=LOWER(FALSE)" })).toBe("false");
322
+ expect(evaluateCell("A1", { A1: '=LOWER("")' })).toBe("");
323
+ expect(evaluateCell("A1", { A1: '=LOWER(" ")' })).toBe(" ");
324
+ expect(evaluateCell("A1", { A1: '=LOWER("42")' })).toBe("42");
325
+ expect(evaluateCell("A1", { A1: '=LOWER("オドゥ")' })).toBe("オドゥ");
326
+ expect(evaluateCell("A1", { A1: '=LOWER("オAドB")' })).toBe("オaドb");
327
+ });
328
+
329
+ test("LOWER: functional tests on cell arguments", () => {
330
+ expect(evaluateCell("A1", { A1: "=LOWER(A2)" })).toBe("");
331
+ expect(evaluateCell("A1", { A1: "=LOWER(A2)", A2: " " })).toBe(" ");
332
+ expect(evaluateCell("A1", { A1: "=LOWER(A2)", A2: "0" })).toBe("0");
333
+ expect(evaluateCell("A1", { A1: "=LOWER(A2)", A2: "42" })).toBe("42");
334
+ expect(evaluateCell("A1", { A1: "=LOWER(A2)", A2: "TRUE" })).toBe("true");
335
+ expect(evaluateCell("A1", { A1: "=LOWER(A2)", A2: "FALSE" })).toBe("false");
336
+ expect(evaluateCell("A1", { A1: "=LOWER(A2)", A2: '""' })).toBe('""');
337
+ expect(evaluateCell("A1", { A1: "=LOWER(A2)", A2: '" "' })).toBe('" "');
338
+ expect(evaluateCell("A1", { A1: "=LOWER(A2)", A2: '"TEST"' })).toBe('"test"');
339
+ expect(evaluateCell("A1", { A1: "=LOWER(A2)", A2: '=""' })).toBe("");
340
+ expect(evaluateCell("A1", { A1: "=LOWER(A2)", A2: '=" "' })).toBe(" ");
341
+ expect(evaluateCell("A1", { A1: "=LOWER(A2)", A2: '="TEST"' })).toBe("test");
342
+ });
343
+
344
+ //----------------------------------------------------------------------------
345
+ // REPLACE
346
+ //----------------------------------------------------------------------------
347
+
348
+ test("REPLACE: functional tests on simple arguments", () => {
349
+ expect(evaluateCell("A1", { A1: '=REPLACE("ABZ", 2, 1, "Y")' })).toBe("AYZ");
350
+ expect(evaluateCell("A1", { A1: '=REPLACE("ABZ", 3, 1, "Y")' })).toBe("ABY");
351
+ expect(evaluateCell("A1", { A1: '=REPLACE("ABZ", 4, 1, "Y")' })).toBe("ABZY");
352
+ expect(evaluateCell("A1", { A1: '=REPLACE("ABZ", 5, 1, "Y")' })).toBe("ABZY");
353
+ expect(evaluateCell("A1", { A1: '=REPLACE("ABZ", 3, 2, "Y")' })).toBe("ABY");
354
+ expect(evaluateCell("A1", { A1: '=REPLACE("ABZ", 3, 2, " Y")' })).toBe("AB Y");
355
+ expect(evaluateCell("A1", { A1: '=REPLACE("ABZ", 5, 2, " Y")' })).toBe("ABZ Y");
356
+ expect(evaluateCell("A1", { A1: '=REPLACE("ABZ", 2, 2, "Y")' })).toBe("AY");
357
+ expect(evaluateCell("A1", { A1: '=REPLACE("ABZ", 1, 2, "Y")' })).toBe("YZ");
358
+ expect(evaluateCell("A1", { A1: '=REPLACE("ABZ", 0, 2, "Y")' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
359
+ expect(evaluateCell("A1", { A1: '=REPLACE("ABZ", 1, 1, "Y")' })).toBe("YBZ");
360
+ expect(evaluateCell("A1", { A1: '=REPLACE("ABZ", 1, 0, "Y")' })).toBe("YABZ");
361
+ expect(evaluateCell("A1", { A1: '=REPLACE("ABZ", 2, 0, "Y")' })).toBe("AYBZ");
362
+ expect(evaluateCell("A1", { A1: '=REPLACE("ABZ", -1, 0, "Y")' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
363
+ });
364
+
365
+ test("REPLACE: casting tests on simple arguments", () => {
366
+ expect(evaluateCell("A1", { A1: '=REPLACE("ABZ", "2", TRUE, "Y")' })).toBe("AYZ");
367
+ expect(evaluateCell("A1", { A1: '=REPLACE(1239, 2, 2, "78")' })).toBe("1789");
368
+ expect(evaluateCell("A1", { A1: '=REPLACE("1789", 2, 2, 23)' })).toBe("1239");
369
+ });
370
+
371
+ //----------------------------------------------------------------------------
372
+ // RIGHT
373
+ //----------------------------------------------------------------------------
374
+
375
+ test("RIGHT: functional tests on simple arguments", () => {
376
+ expect(evaluateCell("A1", { A1: "=RIGHT()" })).toBe("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
377
+ expect(evaluateCell("A1", { A1: '=RIGHT("kikou")' })).toBe("u");
378
+ expect(evaluateCell("A1", { A1: '=RIGHT("123")' })).toBe("3");
379
+ expect(evaluateCell("A1", { A1: "=RIGHT(123)" })).toBe("3");
380
+ expect(evaluateCell("A1", { A1: "=RIGHT(TRUE)" })).toBe("E");
381
+ expect(evaluateCell("A1", { A1: "=RIGHT( , )" })).toBe("");
382
+ expect(evaluateCell("A1", { A1: '=RIGHT("kikou", )' })).toBe("");
383
+ expect(evaluateCell("A1", { A1: '=RIGHT("kikou", -1)' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
384
+ expect(evaluateCell("A1", { A1: '=RIGHT("kikou", 0)' })).toBe("");
385
+ expect(evaluateCell("A1", { A1: '=RIGHT("kikou", 1)' })).toBe("u");
386
+ expect(evaluateCell("A1", { A1: '=RIGHT("kikou", 2)' })).toBe("ou");
387
+ expect(evaluateCell("A1", { A1: '=RIGHT("kikou", 6)' })).toBe("kikou");
388
+ expect(evaluateCell("A1", { A1: '=RIGHT("kikou", 99)' })).toBe("kikou");
389
+ expect(evaluateCell("A1", { A1: '=RIGHT("kikou", "2")' })).toBe("ou");
390
+ });
391
+
392
+ test("RIGHT: functional tests on cell arguments", () => {
393
+ expect(evaluateCell("A1", { A1: "=RIGHT(A2)" })).toBe("");
394
+ expect(evaluateCell("A1", { A1: "=RIGHT(A2)", A2: "kikou" })).toBe("u");
395
+ expect(evaluateCell("A1", { A1: "=RIGHT(A2)", A2: '="123"' })).toBe("3");
396
+ expect(evaluateCell("A1", { A1: "=RIGHT(A2)", A2: "123" })).toBe("3");
397
+ expect(evaluateCell("A1", { A1: "=RIGHT(A2)", A2: "TRUE" })).toBe("E");
398
+ expect(evaluateCell("A1", { A1: "=RIGHT(A2, A3)" })).toBe("");
399
+ expect(evaluateCell("A1", { A1: "=RIGHT(A2, A3)", A2: "kikou" })).toBe("");
400
+ expect(evaluateCell("A1", { A1: "=RIGHT(A2, A3)", A2: "kikou", A3: "-1" })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
401
+ expect(evaluateCell("A1", { A1: "=RIGHT(A2, A3)", A2: "kikou", A3: "0" })).toBe("");
402
+ expect(evaluateCell("A1", { A1: "=RIGHT(A2, A3)", A2: "kikou", A3: "1" })).toBe("u");
403
+ expect(evaluateCell("A1", { A1: "=RIGHT(A2, A3)", A2: "kikou", A3: "2" })).toBe("ou");
404
+ expect(evaluateCell("A1", { A1: "=RIGHT(A2, A3)", A2: "kikou", A3: "6" })).toBe("kikou");
405
+ expect(evaluateCell("A1", { A1: "=RIGHT(A2, A3)", A2: "kikou", A3: "99" })).toBe("kikou");
406
+ expect(evaluateCell("A1", { A1: "=RIGHT(A2, A3)", A2: "kikou", A3: '="2"' })).toBe("ou");
407
+ });
408
+
409
+ //----------------------------------------------------------------------------
410
+ // SEARCH
411
+ //----------------------------------------------------------------------------
412
+
413
+ test("SEARCH: functional tests on simple arguments", () => {
414
+ expect(evaluateCell("A1", { A1: "=SEARCH( , )" })).toBe("#ERROR"); // @compatibility: on google sheets, return #N/A
415
+ expect(evaluateCell("A1", { A1: "=SEARCH( , , )" })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
416
+ expect(evaluateCell("A1", { A1: '=SEARCH("C", "ABCD")' })).toBe(3);
417
+ expect(evaluateCell("A1", { A1: '=SEARCH("C", "ABCD", 0)' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
418
+ expect(evaluateCell("A1", { A1: '=SEARCH("C", "ABCD", 1)' })).toBe(3);
419
+ expect(evaluateCell("A1", { A1: '=SEARCH("C", "ABCD", 2)' })).toBe(3);
420
+ expect(evaluateCell("A1", { A1: '=SEARCH("C", "ABCD", 3)' })).toBe(3);
421
+ expect(evaluateCell("A1", { A1: '=SEARCH("C", "ABCD", 4)' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
422
+ expect(evaluateCell("A1", { A1: '=SEARCH("C", "ABCDC", 4)' })).toBe(5);
423
+ });
424
+
425
+ test("SEARCH: functional tests on cell arguments", () => {
426
+ expect(evaluateCell("A1", { A1: "=SEARCH(A2, A3)", A2: "do", A3: "Odoo" })).toBe(2);
427
+ expect(
428
+ evaluateCell("A1", { A1: "=SEARCH(A2, A3, A4)", A2: "do", A3: "Odoo Docs", A4: "1" })
429
+ ).toBe(2);
430
+ expect(
431
+ evaluateCell("A1", { A1: "=SEARCH(A2, A3, A4)", A2: "do", A3: "Odoo Docs", A4: "4" })
432
+ ).toBe(6);
433
+ expect(
434
+ evaluateCell("A1", { A1: "=SEARCH(A2, A3, A4)", A2: "S", A3: "Spreadsheet", A4: "1" })
435
+ ).toBe(1);
436
+ expect(
437
+ evaluateCell("A1", { A1: "=SEARCH(A2, A3, A4)", A2: "S", A3: "Spreadsheet", A4: "6" })
438
+ ).toBe(7);
439
+ expect(
440
+ evaluateCell("A1", { A1: "=SEARCH(A2, A3, A4)", A2: "S", A3: "Spreadsheet", A4: "8" })
441
+ ).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
442
+ expect(evaluateCell("A1", { A1: "=SEARCH(A2, A3)", A2: "7", A3: "No.7 Doc" })).toBe(4);
443
+ });
444
+
445
+ test("SEARCH: casting tests on cell arguments", () => {
446
+ expect(
447
+ evaluateCell("A1", { A1: "=SEARCH(A2, A3, A4)", A2: "S", A3: "Spreadsheet", A4: '="6"' })
448
+ ).toBe(7);
449
+ expect(
450
+ evaluateCell("A1", { A1: "=SEARCH(A2, A3, A4)", A2: "S", A3: "Spreadsheet", A4: "TRUE" })
451
+ ).toBe(1);
452
+ expect(evaluateCell("A1", { A1: "=SEARCH(A2, A3, A4)", A2: "U", A3: "TRUE", A4: "1" })).toBe(3);
453
+ expect(
454
+ evaluateCell("A1", { A1: "=SEARCH(A2, A3, A4)", A2: "TRUE", A3: "FALSETRUE", A4: "1" })
455
+ ).toBe(6);
456
+ });
457
+
458
+ //----------------------------------------------------------------------------
459
+ // SUBSTITUTE
460
+ //----------------------------------------------------------------------------
461
+
462
+ test("SUBSTITUTE: functional tests on simple arguments", () => {
463
+ expect(evaluateCell("A1", { A1: "=SUBSTITUTE( , , )" })).toBe("");
464
+ expect(evaluateCell("A1", { A1: '=SUBSTITUTE("Odoo", "do", "de à Odo")' })).toBe("Ode à Odoo");
465
+ expect(evaluateCell("A1", { A1: '=SUBSTITUTE("odoodoo sur MON bidet", "o", "a")' })).toBe(
466
+ "adaadaa sur MON bidet"
467
+ );
468
+ expect(evaluateCell("A1", { A1: '=SUBSTITUTE("Aa", "a", "b")' })).toBe("Ab");
469
+ expect(evaluateCell("A1", { A1: '=SUBSTITUTE("Spread Sheet", "e", "E", 2)' })).toBe(
470
+ "Spread ShEet"
471
+ );
472
+ expect(evaluateCell("A1", { A1: '=SUBSTITUTE("AAAA", "", "B")' })).toBe("AAAA");
473
+ });
474
+
475
+ test("SUBSTITUTE: functional tests on cell arguments", () => {
476
+ expect(
477
+ evaluateCell("A1", {
478
+ A1: "=SUBSTITUTE(A2, A3, A4)",
479
+ A2: "Coquille",
480
+ A3: "e",
481
+ A4: 'e sans "q"',
482
+ })
483
+ ).toBe('Coquille sans "q"');
484
+ expect(evaluateCell("A1", { A1: "=SUBSTITUTE(A2, A3, A4)", A2: "ABAB", A3: "A" })).toBe("BB");
485
+ expect(evaluateCell("A1", { A1: "=SUBSTITUTE(A2, A3, A4)", A2: "AAAA", A3: "A" })).toBe("");
486
+ expect(evaluateCell("A1", { A1: "=SUBSTITUTE(A2, A3, A4)", A2: "AAAA" })).toBe("AAAA");
487
+ expect(evaluateCell("A1", { A1: "=SUBSTITUTE(A2, A3, A4)", A2: "AAAA", A4: "B" })).toBe("AAAA");
488
+
489
+ expect(
490
+ evaluateCell("A1", { A1: "=SUBSTITUTE(A2, A3, A4)", A2: "Hello there", A3: "e", A4: "E" })
491
+ ).toBe("HEllo thErE");
492
+ expect(
493
+ evaluateCell("A1", { A1: "=SUBSTITUTE(A2, A3, A4, A5)", A2: "Hello there", A3: "e", A4: "E" })
494
+ ).toBe("HEllo thErE");
495
+ expect(
496
+ evaluateCell("A1", {
497
+ A1: "=SUBSTITUTE(A2, A3, A4, A5)",
498
+ A2: "Hello there",
499
+ A3: "e",
500
+ A4: "E",
501
+ A5: "0",
502
+ })
503
+ ).toBe("HEllo thErE");
504
+ expect(
505
+ evaluateCell("A1", {
506
+ A1: "=SUBSTITUTE(A2, A3, A4, A5)",
507
+ A2: "Hello there",
508
+ A3: "e",
509
+ A4: "E",
510
+ A5: "1",
511
+ })
512
+ ).toBe("HEllo there");
513
+ expect(
514
+ evaluateCell("A1", {
515
+ A1: "=SUBSTITUTE(A2, A3, A4, A5)",
516
+ A2: "Hello there",
517
+ A3: "e",
518
+ A4: "E",
519
+ A5: "2",
520
+ })
521
+ ).toBe("Hello thEre");
522
+ expect(
523
+ evaluateCell("A1", {
524
+ A1: "=SUBSTITUTE(A2, A3, A4, A5)",
525
+ A2: "Hello there",
526
+ A3: "e",
527
+ A4: "E",
528
+ A5: "-1",
529
+ })
530
+ ).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
531
+ });
532
+
533
+ test("SUBSTITUTE: casting tests on cell arguments", () => {
534
+ expect(evaluateCell("A1", { A1: "=SUBSTITUTE(A2, A3, A4)", A2: "22", A3: "2", A4: "99" })).toBe(
535
+ "9999"
536
+ );
537
+ expect(
538
+ evaluateCell("A1", {
539
+ A1: "=SUBSTITUTE(A2, A3, A4, A5)",
540
+ A2: "2222",
541
+ A3: "2",
542
+ A4: "99",
543
+ A5: "3",
544
+ })
545
+ ).toBe("22992");
546
+ expect(
547
+ evaluateCell("A1", { A1: "=SUBSTITUTE(A2, A3, A4)", A2: "TRUE", A3: "E", A4: "QUE" })
548
+ ).toBe("TRUQUE");
549
+ });
550
+
551
+ //----------------------------------------------------------------------------
552
+ // TEXTJOIN
553
+ //----------------------------------------------------------------------------
554
+
555
+ test("TEXTJOIN: functional tests on simple arguments", () => {
556
+ expect(evaluateCell("A1", { A1: "=TEXTJOIN( , , )" })).toBe("");
557
+ expect(evaluateCell("A1", { A1: '=TEXTJOIN("d", TRUE, "O", "oo", "oo", "oo")' })).toBe(
558
+ "Odoodoodoo"
559
+ );
560
+ expect(evaluateCell("A1", { A1: '=TEXTJOIN(" ", TRUE, "1", "2", "3", "", "4")' })).toBe(
561
+ "1 2 3 4"
562
+ );
563
+ expect(evaluateCell("A1", { A1: '=TEXTJOIN(" ", TRUE, "1", "2", "3", , "4")' })).toBe(
564
+ "1 2 3 4"
565
+ );
566
+ expect(evaluateCell("A1", { A1: '=TEXTJOIN(" ", FALSE, "1", "2", "3", "", "4")' })).toBe(
567
+ "1 2 3 4"
568
+ );
569
+ expect(evaluateCell("A1", { A1: '=TEXTJOIN(" ", FALSE, "1", "2", "3", , "4")' })).toBe(
570
+ "1 2 3 4"
571
+ );
572
+ });
573
+
574
+ test("TEXTJOIN: casting tests on simple arguments", () => {
575
+ expect(evaluateCell("A1", { A1: '=TEXTJOIN(" ", TRUE, 1, 2, 3, , 4)' })).toBe("1 2 3 4");
576
+ expect(evaluateCell("A1", { A1: '=TEXTJOIN(" ", FALSE, 1, 2, 3, , 4)' })).toBe("1 2 3 4");
577
+ expect(evaluateCell("A1", { A1: '=TEXTJOIN(" ", 1, "1", "2", "3", "", "4")' })).toBe("1 2 3 4");
578
+ expect(evaluateCell("A1", { A1: '=TEXTJOIN(" ", 0, "1", "2", "3", "", "4")' })).toBe(
579
+ "1 2 3 4"
580
+ );
581
+ });
582
+
583
+ test("TEXTJOIN: functional tests on cell arguments", () => {
584
+ expect(
585
+ evaluateCell("A1", {
586
+ A1: "=TEXTJOIN(A2, A3, A4:A6)",
587
+ A2: "PINCE",
588
+ A3: "FALSE",
589
+ A5: "MI et ",
590
+ A6: "MOI sont dans un bateau",
591
+ })
592
+ ).toBe("PINCEMI et PINCEMOI sont dans un bateau");
593
+ expect(
594
+ evaluateCell("A1", {
595
+ A1: "=TEXTJOIN(A2, A3, A4:A6)",
596
+ A2: "PINCE",
597
+ A3: "TRUE",
598
+ A5: "MI et ",
599
+ A6: "MOI sont dans un bateau",
600
+ })
601
+ ).toBe("MI et PINCEMOI sont dans un bateau");
602
+ expect(evaluateCell("A1", { A1: "=TEXTJOIN(A2, A3, A4:A6)", A2: "COU", A3: "FALSE" })).toBe(
603
+ "COUCOU"
604
+ );
605
+ expect(evaluateCell("A1", { A1: "=TEXTJOIN(A2, A3, A4:A6)", A3: "TRUE" })).toBe("");
606
+ expect(evaluateCell("A1", { A1: "=TEXTJOIN(A2, A3, A4:A6)", A2: "TRO", A4: "L'ÂNE " })).toBe(
607
+ "L'ÂNE TROTRO"
608
+ );
609
+ });
610
+
611
+ //----------------------------------------------------------------------------
612
+ // TRIM
613
+ //----------------------------------------------------------------------------
614
+
615
+ test("TRIM: functional tests on simple arguments", () => {
616
+ expect(evaluateCell("A1", { A1: "=TRIM()" })).toBe("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
617
+ expect(evaluateCell("A1", { A1: '=TRIM("")' })).toBe("");
618
+ expect(evaluateCell("A1", { A1: '=TRIM(" ")' })).toBe("");
619
+ expect(evaluateCell("A1", { A1: '=TRIM(" Jean Ticonstitutionnalise ")' })).toBe(
620
+ "Jean Ticonstitutionnalise"
621
+ );
622
+ expect(evaluateCell("A1", { A1: '=TRIM(" A ")' })).toBe("A");
623
+ expect(evaluateCell("A1", { A1: '=TRIM(" A ")' })).toBe("A");
624
+ });
625
+
626
+ test("TRIM: casting tests on simple arguments", () => {
627
+ expect(evaluateCell("A1", { A1: "=TRIM(123)" })).toBe("123");
628
+ expect(evaluateCell("A1", { A1: "=TRIM(TRUE)" })).toBe("TRUE");
629
+ });
630
+
631
+ test("TRIM: functional tests on cell arguments", () => {
632
+ expect(evaluateCell("A1", { A1: "=TRIM(A2)" })).toBe("");
633
+ expect(evaluateCell("A1", { A1: "=TRIM(A2)", A2: " Kikou " })).toBe("Kikou");
634
+ expect(evaluateCell("A1", { A1: "=TRIM(A2)", A2: '" Kikou "' })).toBe('" Kikou "');
635
+ expect(evaluateCell("A1", { A1: "=TRIM(A2)", A2: '=" Kikou "' })).toBe("Kikou");
636
+ });
637
+
638
+ //----------------------------------------------------------------------------
639
+ // UPPER
640
+ //----------------------------------------------------------------------------
641
+
642
+ test("UPPER: functional tests on simple arguments", () => {
643
+ expect(evaluateCell("A1", { A1: "=UPPER()" })).toBe("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
644
+ expect(evaluateCell("A1", { A1: "=UPPER(0)" })).toBe("0");
645
+ expect(evaluateCell("A1", { A1: "=UPPER(42)" })).toBe("42");
646
+ expect(evaluateCell("A1", { A1: '=UPPER("grrrr !")' })).toBe("GRRRR !");
647
+ expect(evaluateCell("A1", { A1: '=UPPER("true")' })).toBe("TRUE");
648
+ expect(evaluateCell("A1", { A1: '=UPPER("false")' })).toBe("FALSE");
649
+ expect(evaluateCell("A1", { A1: '=UPPER("オドゥ")' })).toBe("オドゥ");
650
+ expect(evaluateCell("A1", { A1: '=UPPER("オaドb")' })).toBe("オAドB");
651
+ expect(evaluateCell("A1", { A1: '=UPPER("")' })).toBe("");
652
+ expect(evaluateCell("A1", { A1: '=UPPER(" ")' })).toBe(" ");
653
+ });
654
+
655
+ test("UPPER: functional tests on cell arguments", () => {
656
+ expect(evaluateCell("A1", { A1: "=UPPER(A2)" })).toBe("");
657
+ expect(evaluateCell("A1", { A1: "=UPPER(A2)", A2: " " })).toBe(" ");
658
+ expect(evaluateCell("A1", { A1: "=UPPER(A2)", A2: "0" })).toBe("0");
659
+ expect(evaluateCell("A1", { A1: "=UPPER(A2)", A2: '""' })).toBe('""');
660
+ expect(evaluateCell("A1", { A1: "=UPPER(A2)", A2: '" "' })).toBe('" "');
661
+ expect(evaluateCell("A1", { A1: "=UPPER(A2)", A2: '"true"' })).toBe('"TRUE"');
662
+ expect(evaluateCell("A1", { A1: "=UPPER(A2)", A2: '=""' })).toBe("");
663
+ expect(evaluateCell("A1", { A1: "=UPPER(A2)", A2: '=" "' })).toBe(" ");
664
+ expect(evaluateCell("A1", { A1: "=UPPER(A2)", A2: '="test"' })).toBe("TEST");
665
+ expect(evaluateCell("A1", { A1: "=UPPER(A2)", A2: '="true"' })).toBe("TRUE");
666
+ });
667
+ });