@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,541 @@
1
+ import { evaluateGrid } from "../helpers";
2
+
3
+ describe("lookup", () => {
4
+ //----------------------------------------------------------------------------
5
+ // LOOKUP
6
+ //----------------------------------------------------------------------------
7
+
8
+ test("LOOKUP: functional tests on range", () => {
9
+ // prettier-ignore
10
+ const grid = {
11
+ A1: "1", B1: "res 01", C1: "res 11", D1: "res 21", E1: "res 31",
12
+ A2: "2", B2: "res 02", C2: "res 12", D2: "res 22", E2: "res 32",
13
+ A3: "6", B3: "res 06", C3: "res 16", D3: "res 26", E3: "res 36",
14
+ A4: "9", B4: "res 09", C4: "res 19", D4: "res 29", E4: "res 39",
15
+
16
+ A5: "=LOOKUP(6, A1:A4)",
17
+ A6: "=LOOKUP(6, A1:B4)",
18
+ A7: "=LOOKUP(6, A1:C4)",
19
+ A8: "=LOOKUP(6, A1:D4)",
20
+ A9: "=LOOKUP(6, A1:E4)",
21
+
22
+ A10: "=LOOKUP(6, A1:D4, E1:E4)", B10: "=LOOKUP(6, A1:C4, D1:E4)",
23
+ A11: "=LOOKUP(6, A1:A2, B3:B4)", B11: "=LOOKUP(6, A1:A2, B2:B4)",
24
+ A12: "=LOOKUP(1, A1:A2, B1:C1)", B12: "=LOOKUP(2, A1:A2, B1:C1)",
25
+
26
+ A13: "=LOOKUP(6, A1:A3, B2:B3)",
27
+ A14: "=LOOKUP(6, A1:A3, B3:C3)",
28
+
29
+ A15: "=LOOKUP(0, A1:B4)",
30
+ A16: "=LOOKUP(10, A1:B4)"
31
+ };
32
+
33
+ const evaluatedGrid = evaluateGrid(grid);
34
+ expect(evaluatedGrid.A5).toBe(6);
35
+ expect(evaluatedGrid.A6).toBe("res 06");
36
+ expect(evaluatedGrid.A7).toBe("res 16");
37
+ expect(evaluatedGrid.A8).toBe("res 26");
38
+ expect(evaluatedGrid.A9).toBe(9);
39
+
40
+ expect(evaluatedGrid.A10).toBe("res 36");
41
+ expect(evaluatedGrid.B10).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
42
+ expect(evaluatedGrid.A11).toBe("res 09");
43
+ expect(evaluatedGrid.B11).toBe("res 06");
44
+ expect(evaluatedGrid.A12).toBe("res 01");
45
+ expect(evaluatedGrid.B12).toBe("res 11");
46
+
47
+ expect(evaluatedGrid.A13).toBe("#ERROR"); // @compatibility: on googlesheets, return #NUM!
48
+ expect(evaluatedGrid.A14).toBe("#ERROR"); // @compatibility: on googlesheets, return #NUM!
49
+
50
+ expect(evaluatedGrid.A15).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
51
+ expect(evaluatedGrid.A16).toBe("res 09");
52
+ });
53
+
54
+ test("LOOKUP: lookup dates", () => {
55
+ // prettier-ignore
56
+ const grid = {
57
+ A1: "01/03/2020", B1: "999", C1: "15", D1: "01/03/2020", E1: "01/04/2000",
58
+ A2: "missed1", B2: "missed2", C2: "touché",
59
+
60
+ A4: "=LOOKUP(D1, A1:C1, A2:C2)",
61
+ A5: "=LOOKUP(E1, A1:C1, A2:C2)",
62
+ }
63
+ const evaluatedGrid = evaluateGrid(grid);
64
+ expect(evaluatedGrid.A4).toBe("touché");
65
+ expect(evaluatedGrid.A5).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
66
+ });
67
+
68
+ //----------------------------------------------------------------------------
69
+ // MATCH
70
+ //----------------------------------------------------------------------------
71
+
72
+ // prettier-ignore
73
+ const rangeAscending = {
74
+ A1: "1", A2: "2", A3: "2", A4: "3", A5: "5", A6: "6"
75
+ };
76
+
77
+ // prettier-ignore
78
+ const rangeUnsorted = {
79
+ A1: "1", A2: "5", A3: "3", A4: "3", A5: "2", A6: "7"
80
+ };
81
+
82
+ // prettier-ignore
83
+ const rangeDescending = {
84
+ A1: "6", A2: "5", A3: "3", A4: "2", A5: "2", A6: "1"
85
+ };
86
+
87
+ // prettier-ignore
88
+ const evAsAscending = {
89
+ B1: "=MATCH( 0, A1:A6, 1)", B2: "=MATCH( 1, A1:A6, 1)",
90
+ B3: "=MATCH( 2, A1:A6, 1)", B4: "=MATCH( 3, A1:A6, 1)",
91
+ B5: "=MATCH( 4, A1:A6, 1)", B6: "=MATCH( 5, A1:A6, 1)",
92
+ B7: "=MATCH( 6, A1:A6, 1)", B8: "=MATCH( 7, A1:A6, 1)"
93
+ };
94
+
95
+ // prettier-ignore
96
+ const evAsUnsorted = {
97
+ C1: "=MATCH( 0, A1:A6, 0)", C2: "=MATCH( 1, A1:A6, 0)",
98
+ C3: "=MATCH( 2, A1:A6, 0)", C4: "=MATCH( 3, A1:A6, 0)",
99
+ C5: "=MATCH( 4, A1:A6, 0)", C6: "=MATCH( 5, A1:A6, 0)",
100
+ C7: "=MATCH( 6, A1:A6, 0)", C8: "=MATCH( 7, A1:A6, 0)"
101
+ };
102
+
103
+ // prettier-ignore
104
+ const evAsDescending = {
105
+ D1: "=MATCH( 0, A1:A6, -1)", D2: "=MATCH( 1, A1:A6, -1)",
106
+ D3: "=MATCH( 2, A1:A6, -1)", D4: "=MATCH( 3, A1:A6, -1)",
107
+ D5: "=MATCH( 4, A1:A6, -1)", D6: "=MATCH( 5, A1:A6, -1)",
108
+ D7: "=MATCH( 6, A1:A6, -1)", D8: "=MATCH( 7, A1:A6, -1)"
109
+ };
110
+
111
+ test("MATCH: range evaluate sorted ascending", () => {
112
+ const ascendingAsAscending = { ...rangeAscending, ...evAsAscending };
113
+ const aAsA = evaluateGrid(ascendingAsAscending);
114
+
115
+ expect(aAsA.B1).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
116
+ expect(aAsA.B2).toBe(1);
117
+ expect(aAsA.B3).toBe(3);
118
+ expect(aAsA.B4).toBe(4);
119
+ expect(aAsA.B5).toBe(4);
120
+ expect(aAsA.B6).toBe(5);
121
+ expect(aAsA.B7).toBe(6);
122
+ expect(aAsA.B8).toBe(6);
123
+
124
+ const ascendingAsUnsorted = { ...rangeAscending, ...evAsUnsorted };
125
+ const aAsU = evaluateGrid(ascendingAsUnsorted);
126
+
127
+ expect(aAsU.C1).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
128
+ expect(aAsU.C2).toBe(1);
129
+ expect(aAsU.C3).toBe(2);
130
+ expect(aAsU.C4).toBe(4);
131
+ expect(aAsU.C5).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
132
+ expect(aAsU.C6).toBe(5);
133
+ expect(aAsU.C7).toBe(6);
134
+ expect(aAsU.C8).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
135
+
136
+ const ascendingAsDescending = { ...rangeAscending, ...evAsDescending };
137
+ const aAsD = evaluateGrid(ascendingAsDescending);
138
+
139
+ expect(aAsD.D1).toBe(6);
140
+ expect(aAsD.D2).toBe(6);
141
+ expect(aAsD.D3).toBe("#ERROR"); // @compatibility: on googlesheets, return 6
142
+ expect(aAsD.D4).toBe("#ERROR"); // @compatibility: on googlesheets, return 6
143
+ expect(aAsD.D5).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
144
+ expect(aAsD.D6).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
145
+ expect(aAsD.D7).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
146
+ expect(aAsD.D8).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
147
+ });
148
+
149
+ test("MATCH: range evaluate unsorted", () => {
150
+ const unsortedAsAscending = { ...rangeUnsorted, ...evAsAscending };
151
+ const uAsA = evaluateGrid(unsortedAsAscending);
152
+
153
+ expect(uAsA.B1).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
154
+ expect(uAsA.B2).toBe(1);
155
+ expect(uAsA.B3).toBe(1);
156
+ expect(uAsA.B4).toBe(4); // @compatibility: on googlesheets, return 5
157
+ expect(uAsA.B5).toBe(4); // @compatibility: on googlesheets, return 5
158
+ expect(uAsA.B6).toBe(4); // @compatibility: on googlesheets, return 5
159
+ expect(uAsA.B7).toBe(4); // @compatibility: on googlesheets, return 5
160
+ expect(uAsA.B8).toBe(6);
161
+
162
+ const unsortedAsUnsorted = { ...rangeUnsorted, ...evAsUnsorted };
163
+ const uAsU = evaluateGrid(unsortedAsUnsorted);
164
+
165
+ expect(uAsU.C1).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
166
+ expect(uAsU.C2).toBe(1);
167
+ expect(uAsU.C3).toBe(5);
168
+ expect(uAsU.C4).toBe(3);
169
+ expect(uAsU.C5).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
170
+ expect(uAsU.C6).toBe(2);
171
+ expect(uAsU.C7).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
172
+ expect(uAsU.C8).toBe(6);
173
+
174
+ const unsortedAsDescending = { ...rangeUnsorted, ...evAsDescending };
175
+ const uAsD = evaluateGrid(unsortedAsDescending);
176
+
177
+ expect(uAsD.D1).toBe(6);
178
+ expect(uAsD.D2).toBe(6);
179
+ expect(uAsD.D3).toBe("#ERROR"); // @compatibility: on googlesheets, return 6
180
+ expect(uAsD.D4).toBe("#ERROR"); // @compatibility: on googlesheets, return 3
181
+ expect(uAsD.D5).toBe("#ERROR"); // @compatibility: on googlesheets, return 2
182
+ expect(uAsD.D6).toBe("#ERROR"); // @compatibility: on googlesheets, return 2
183
+ expect(uAsD.D7).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
184
+ expect(uAsD.D8).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
185
+ });
186
+
187
+ test("MATCH: range evaluate sorted descending", () => {
188
+ const descendingAsAscending = { ...rangeDescending, ...evAsAscending };
189
+ const dAsA = evaluateGrid(descendingAsAscending);
190
+
191
+ expect(dAsA.B1).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
192
+ expect(dAsA.B2).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
193
+ expect(dAsA.B3).toBe("#ERROR"); // @compatibility: on googlesheets, return 6
194
+ expect(dAsA.B4).toBe("#ERROR"); // @compatibility: on googlesheets, return 6
195
+ expect(dAsA.B5).toBe("#ERROR"); // @compatibility: on googlesheets, return 6
196
+ expect(dAsA.B6).toBe("#ERROR"); // @compatibility: on googlesheets, return 6
197
+ expect(dAsA.B7).toBe(6);
198
+ expect(dAsA.B8).toBe(6);
199
+
200
+ const descendingAsUnsorted = { ...rangeDescending, ...evAsUnsorted };
201
+ const dAsU = evaluateGrid(descendingAsUnsorted);
202
+
203
+ expect(dAsU.C1).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
204
+ expect(dAsU.C2).toBe(6);
205
+ expect(dAsU.C3).toBe(4);
206
+ expect(dAsU.C4).toBe(3);
207
+ expect(dAsU.C5).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
208
+ expect(dAsU.C6).toBe(2);
209
+ expect(dAsU.C7).toBe(1);
210
+ expect(dAsU.C8).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
211
+
212
+ const descendingAsDescending = { ...rangeDescending, ...evAsDescending };
213
+ const dAsD = evaluateGrid(descendingAsDescending);
214
+
215
+ expect(dAsD.D1).toBe(6);
216
+ expect(dAsD.D2).toBe(6);
217
+ expect(dAsD.D3).toBe(4);
218
+ expect(dAsD.D4).toBe(3);
219
+ expect(dAsD.D5).toBe(2);
220
+ expect(dAsD.D6).toBe(2);
221
+ expect(dAsD.D7).toBe(1);
222
+ expect(dAsD.D8).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
223
+ });
224
+
225
+ test("MATCH: grid of STRING ascending", () => {
226
+ // prettier-ignore
227
+ const ascendingStringEvAsAscending = {
228
+ A1: '="1"', A2: '="10"', A3: '="100"', A4: '="2"', A5: '="2"',
229
+ B1: '=MATCH( "1", A1:A5, 1)',
230
+ B2: '=MATCH( "2", A1:A5, 1)',
231
+ B3: '=MATCH( "5", A1:A5, 1)',
232
+ B4: '=MATCH( "10", A1:A5, 1)',
233
+ B5: '=MATCH( "100", A1:A5, 1)',
234
+ };
235
+ const ascendingString = evaluateGrid(ascendingStringEvAsAscending);
236
+
237
+ expect(ascendingString.B1).toBe(1);
238
+ expect(ascendingString.B2).toBe(5);
239
+ expect(ascendingString.B3).toBe(5);
240
+ expect(ascendingString.B4).toBe(2);
241
+ expect(ascendingString.B5).toBe(3);
242
+ });
243
+
244
+ test("MATCH: grid of STRING unsorted", () => {
245
+ // prettier-ignore
246
+ const unsortedStringEvAsUnsorted = {
247
+ A1: '="1"', A2: '="2"', A3: '="2"', A4: '="10"', A5: '="100"',
248
+ C1: '=MATCH( "1", A1:A5, 0)',
249
+ C2: '=MATCH( "2", A1:A5, 0)',
250
+ C3: '=MATCH( "5", A1:A5, 0)',
251
+ C4: '=MATCH( "10", A1:A5, 0)',
252
+ C5: '=MATCH( "100", A1:A5, 0)',
253
+ };
254
+ const unsortedString = evaluateGrid(unsortedStringEvAsUnsorted);
255
+
256
+ expect(unsortedString.C1).toBe(1);
257
+ expect(unsortedString.C2).toBe(2);
258
+ expect(unsortedString.C3).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
259
+ expect(unsortedString.C4).toBe(4);
260
+ expect(unsortedString.C5).toBe(5);
261
+ });
262
+
263
+ test("MATCH: grid of STRING descending", () => {
264
+ // prettier-ignore
265
+ const descendingStringEvAsDescending = {
266
+ A1: '="2"', A2: '="2"', A3: '="100"', A4: '="10"', A5: '="1"',
267
+ D1: '=MATCH( "1", A1:A5, -1)',
268
+ D2: '=MATCH( "2", A1:A5, -1)',
269
+ D3: '=MATCH( "5", A1:A5, -1)',
270
+ D4: '=MATCH( "10", A1:A5, -1)',
271
+ D5: '=MATCH( "100", A1:A5, -1)',
272
+ }
273
+ const descendingString = evaluateGrid(descendingStringEvAsDescending);
274
+
275
+ expect(descendingString.D1).toBe(5);
276
+ expect(descendingString.D2).toBe(1);
277
+ expect(descendingString.D3).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
278
+ expect(descendingString.D4).toBe(4);
279
+ expect(descendingString.D5).toBe(3);
280
+ });
281
+
282
+ test("MATCH: match dates", () => {
283
+ // prettier-ignore
284
+ const grid = {
285
+ A1: "01/03/2020", B1: "999", C1: "15", D1: "01/03/2020", E1: "01/04/2000",
286
+
287
+ A4: "=MATCH(D1, A1:C1, 0)",
288
+ A5: "=MATCH(D1, A1:C1, 1)",
289
+ A6: "=MATCH(E1, A1:C1, 0)",
290
+ A7: "=MATCH(E1, A1:C1, 1)",
291
+ }
292
+ const evaluatedGrid = evaluateGrid(grid);
293
+ expect(evaluatedGrid.A4).toBe(1);
294
+ expect(evaluatedGrid.A5).toBe(3);
295
+ expect(evaluatedGrid.A6).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
296
+ expect(evaluatedGrid.A7).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
297
+ });
298
+
299
+ //----------------------------------------------------------------------------
300
+ // VLOOKUP
301
+ //----------------------------------------------------------------------------
302
+
303
+ describe("VLOOKUP formula", () => {
304
+ describe("sorted values with different type", () => {
305
+ test("with undefined values", () => {
306
+ // prettier-ignore
307
+ const rangesGrid = {
308
+ A1: "42", B1: "42", C1: undefined, D1: undefined, E1: undefined, Z1: "1",
309
+ A2: undefined, B2: undefined, C2: undefined, D2: undefined, E2: undefined, Z2: "2",
310
+ A3: undefined, B3: "42", C3: undefined, D3: "42", E3: undefined, Z3: "3",
311
+ A4: undefined, B4: undefined, C4: undefined, D4: undefined, E4: undefined, Z4: "4",
312
+ A5: undefined, B5: undefined, C5: "42", D5: "42", E5: undefined, Z5: "5",
313
+ };
314
+ const grid = evaluateGrid({
315
+ ...rangesGrid,
316
+ A9: "=VLOOKUP(42, A1:Z5, 26, TRUE)",
317
+ B9: "=VLOOKUP(42, B1:Z5, 25, TRUE)",
318
+ C9: "=VLOOKUP(42, C1:Z5, 24, TRUE)",
319
+ D9: "=VLOOKUP(42, D1:Z5, 23, TRUE)",
320
+ E9: "=VLOOKUP(42, E1:Z5, 22, TRUE)",
321
+ });
322
+ expect(grid.A9).toBe(1);
323
+ expect(grid.B9).toBe(3);
324
+ expect(grid.C9).toBe(5);
325
+ expect(grid.D9).toBe(5);
326
+ expect(grid.E9).toBe("#ERROR");
327
+ });
328
+
329
+ test("lookup string with string and number values", () => {
330
+ // prettier-ignore
331
+ const rangesGrid = {
332
+ A1: "coucou", B1: "coucou", C1: "42", D1: "42", E1: "42", F1: "42", Z1: "1",
333
+ A2: "42", B2: "42", C2: "42", D2: "42", E2: "42", F2: "42", Z2: "2",
334
+ A3: "42", B3: "coucou", C3: "42", D3: "coucou", E3: "42", F3: `="42"`, Z3: "3",
335
+ A4: "42", B4: "42", C4: "42", D4: "42", E4: "42", F4: "42", Z4: "4",
336
+ A5: "42", B5: "42", C5:"coucou", D5: "coucou", E5: "42", F5: "42", Z5: "5",
337
+ };
338
+
339
+ const grid = evaluateGrid({
340
+ ...rangesGrid,
341
+ A9: '=VLOOKUP("coucou", A1:Z5, 26, TRUE)',
342
+ B9: '=VLOOKUP("coucou", B1:Z5, 25, TRUE)',
343
+ C9: '=VLOOKUP("coucou", C1:Z5, 24, TRUE)',
344
+ D9: '=VLOOKUP("coucou", D1:Z5, 23, TRUE)',
345
+ E9: '=VLOOKUP("coucou", E1:Z5, 22, TRUE)',
346
+ F9: '=VLOOKUP("42", F1:Z5, 21, TRUE)',
347
+ });
348
+ expect(grid.A9).toBe(1);
349
+ expect(grid.B9).toBe(3);
350
+ expect(grid.C9).toBe(5);
351
+ expect(grid.D9).toBe(5);
352
+ expect(grid.E9).toBe("#ERROR");
353
+ expect(grid.F9).toBe(3);
354
+ });
355
+
356
+ test("lookup number with number and string values", () => {
357
+ // prettier-ignore
358
+ const rangesGrid = {
359
+ A1: "666", B1: "666", C1: "abc", D1: "abc", E1: "abc", Z1: "1",
360
+ A2: "abc", B2: "abc", C2: "abc", D2: "abc", E2: "abc", Z2: "2",
361
+ A3: "abc", B3: "666", C3: "abc", D3: "666", E3: "abc", Z3: "3",
362
+ A4: "abc", B4: "abc", C4: "abc", D4: "abc", E4: "abc", Z4: "4",
363
+ A5: "abc", B5: "abc", C5: "666", D5: "666", E5: "abc", Z5: "5",
364
+ };
365
+ const grid = evaluateGrid({
366
+ ...rangesGrid,
367
+ A9: "=VLOOKUP(666, A1:Z5, 26, TRUE)",
368
+ B9: "=VLOOKUP(666, B1:Z5, 25, TRUE)",
369
+ C9: "=VLOOKUP(666, C1:Z5, 24, TRUE)",
370
+ D9: "=VLOOKUP(666, D1:Z5, 23, TRUE)",
371
+ E9: "=VLOOKUP(666, E1:Z5, 22, TRUE)",
372
+ });
373
+ expect(grid.A9).toBe(1);
374
+ expect(grid.B9).toBe(3);
375
+ expect(grid.C9).toBe(5);
376
+ expect(grid.D9).toBe(5);
377
+ expect(grid.E9).toBe("#ERROR");
378
+ });
379
+ });
380
+
381
+ // prettier-ignore
382
+ const commonGrid = {
383
+ B1: "B1", C1: "C1", D1: "D1", E1: "E1",
384
+ B2: "B2", C2: "C2", D2: "D2", E2: "E2",
385
+ B3: "B3", C3: "C3", D3: "D3", E3: "E3",
386
+ B4: "B4", C4: "C4", D4: "D4", E4: "E4",
387
+ B5: "B5", C5: "C5", D5: "D5", E5: "E5",
388
+ B6: "B6", C6: "C6", D6: "D6", E6: "E6",
389
+ };
390
+ test("if index not between 1 and the number of columns --> return #ERROR", () => {
391
+ const grid = evaluateGrid({
392
+ ...commonGrid,
393
+ Z1: '=VLOOKUP( "B4", B1:E5, 0)',
394
+ Z2: '=VLOOKUP( "B4", B1:E5, 5)',
395
+ });
396
+ expect(grid.Z1).toBe("#ERROR"); // @compatibility: on googlesheets, return #VALUE!
397
+ expect(grid.Z2).toBe("#ERROR"); // @compatibility: on googlesheets, return #VALUE!
398
+ });
399
+ test("if float index --> index rounded down", () => {
400
+ const grid = evaluateGrid({
401
+ ...commonGrid,
402
+ Z1: '=VLOOKUP( "B4", B1:E5, 2.9)',
403
+ Z2: '=VLOOKUP( "B4", B1:E5, 4.3)',
404
+ });
405
+ expect(grid.Z1).toBe("C4");
406
+ expect(grid.Z2).toBe("E4");
407
+ });
408
+ // prettier-ignore
409
+ const numSorted = {
410
+ A1: "1", A2: "2", A3: "=A2", A4: "3", A5: "5", A6: "=A5",
411
+ X1: "4", X2: "6", X3: "-3", X4: "0" // other testing values
412
+ };
413
+ // prettier-ignore
414
+ const numUnsorted = {
415
+ A1: "1", A2: "2", A3: "5", A4: "3", A5: "=A2", A6: "=A3",
416
+ X1: "4", X2: "6" // other testing values
417
+ };
418
+ // prettier-ignore
419
+ const stringSorted = {
420
+ A1: 'ab', A2: 'abc', A3: "=A2", A4: 'abcd', A5: 'ba', A6: "=A5",
421
+ X1: "abcde", X2: "bac", X3: "a", X4: "aa" // other testing values
422
+ };
423
+ // prettier-ignore
424
+ const stringUnsorted = {
425
+ A1: 'ab', A2: 'abc', A3: 'ba', A4: 'abcd', A5: '=A2', A6: '=A3',
426
+ X1: "abcde", X2: "bac" // other testing values
427
+ };
428
+ describe.each([
429
+ ["numerical values", numSorted, numUnsorted],
430
+ ["string values", stringSorted, stringUnsorted],
431
+ ])("search on %s", (typeValues, colSorted, colUnsorted) => {
432
+ const gridSorted = { ...colSorted, ...commonGrid };
433
+ const gridUnsorted = { ...colUnsorted, ...commonGrid };
434
+ describe("if values are evaluated as sorted", () => {
435
+ test("if find a value --> return the match value (normal behavior)", () => {
436
+ const grid = evaluateGrid({
437
+ ...gridSorted,
438
+ Z1: "=VLOOKUP( A4, A1:E6, 3, TRUE )",
439
+ Z2: "=VLOOKUP( A1, A1:E6, 4, TRUE )",
440
+ });
441
+ expect(grid.Z1).toBe("C4");
442
+ expect(grid.Z2).toBe("D1");
443
+ });
444
+ test("if find multiple values --> return match to last value", () => {
445
+ const grid = evaluateGrid({
446
+ ...gridSorted,
447
+ Z1: "=VLOOKUP( A2, A1:E6, 3, TRUE )",
448
+ Z2: "=VLOOKUP( A5, A1:E6, 3, TRUE )",
449
+ });
450
+ expect(grid.Z1).toBe("C3");
451
+ expect(grid.Z2).toBe("C6");
452
+ });
453
+ test("if not find value --> return match to the nearest value (less than the search key)", () => {
454
+ const grid = evaluateGrid({
455
+ ...gridSorted,
456
+ Z1: "=VLOOKUP( X1, A1:E6, 3, TRUE )",
457
+ Z2: "=VLOOKUP( X2, A1:E6, 3, TRUE )",
458
+ Z3: "=VLOOKUP( X2, A10:A16, 1, TRUE )",
459
+ });
460
+ expect(grid.Z1).toBe("C4");
461
+ expect(grid.Z2).toBe("C6");
462
+ expect(grid.Z3).toBe("#ERROR"); // @compatibility: on google sheets return #N/A
463
+ });
464
+
465
+ test("if all values in the search column are greater than the search key --> return #ERROR ", () => {
466
+ const grid = evaluateGrid({
467
+ ...gridSorted,
468
+ Z1: "=VLOOKUP( X3, A1:E6, 3, TRUE )",
469
+ Z2: "=VLOOKUP( X4, A1:E6, 3, TRUE )",
470
+ });
471
+ expect(grid.Z1).toBe("#ERROR"); // @compatibility: on google sheets return #N/A
472
+ expect(grid.Z2).toBe("#ERROR"); // @compatibility: on google sheets return #N/A
473
+ });
474
+ });
475
+ describe("if values are evaluated as unsorted", () => {
476
+ test("if find a value --> return the match value (normal behavior)", () => {
477
+ const gridS = evaluateGrid({
478
+ ...gridSorted,
479
+ Z1: "=VLOOKUP( A4, A1:E6, 3, FALSE )",
480
+ Z2: "=VLOOKUP( A1, A1:E6, 4, FALSE )",
481
+ });
482
+ expect(gridS.Z1).toBe("C4");
483
+ expect(gridS.Z2).toBe("D1");
484
+ const gridU = evaluateGrid({
485
+ ...gridUnsorted,
486
+ Z1: "=VLOOKUP( A4, A1:E6, 3, FALSE )",
487
+ Z2: "=VLOOKUP( A1, A1:E6, 4, FALSE )",
488
+ });
489
+ expect(gridU.Z1).toBe("C4");
490
+ expect(gridU.Z2).toBe("D1");
491
+ });
492
+ test("if find multiple values --> return match to first value", () => {
493
+ const gridS = evaluateGrid({
494
+ ...gridSorted,
495
+ Z1: "=VLOOKUP( A2, A1:E6, 3, FALSE )",
496
+ Z2: "=VLOOKUP( A5, A1:E6, 3, FALSE )",
497
+ });
498
+ expect(gridS.Z1).toBe("C2");
499
+ expect(gridS.Z2).toBe("C5");
500
+ const gridU = evaluateGrid({
501
+ ...gridUnsorted,
502
+ Z1: "=VLOOKUP( A2, A1:E6, 3, FALSE )",
503
+ Z2: "=VLOOKUP( A3, A1:E6, 3, FALSE )",
504
+ });
505
+ expect(gridU.Z1).toBe("C2");
506
+ expect(gridU.Z2).toBe("C3");
507
+ });
508
+ test("if not find value --> #ERROR is returned ", () => {
509
+ const formulas = {
510
+ Z1: "=VLOOKUP( X1, A1:E6, 3, FALSE )",
511
+ Z2: "=VLOOKUP( X2, A1:E6, 3, FALSE )",
512
+ };
513
+ const gridS = evaluateGrid({ ...gridSorted, ...formulas });
514
+ expect(gridS.Z1).toBe("#ERROR"); // @compatibility: on google sheets return #N/A
515
+ expect(gridS.Z2).toBe("#ERROR"); // @compatibility: on google sheets return #N/A
516
+ const gridU = evaluateGrid({ ...gridUnsorted, ...formulas });
517
+ expect(gridU.Z1).toBe("#ERROR"); // @compatibility: on google sheets return #N/A
518
+ expect(gridU.Z2).toBe("#ERROR"); // @compatibility: on google sheets return #N/A
519
+ });
520
+ });
521
+ });
522
+ });
523
+
524
+ test("VLOOKUP: lookup dates", () => {
525
+ // prettier-ignore
526
+ const grid = {
527
+ A1: "01/03/2020", B1: "999", C1: "15", D1: "01/03/2020", E1: "01/04/2000",
528
+ A2: "touché", B2: "missed1", C2: "missed2",
529
+
530
+ A4: "=VLOOKUP(D1, A1:C2, 2, 0)",
531
+ A5: "=VLOOKUP(D1, A1:C2, 2, 1)",
532
+ A6: "=VLOOKUP(E1, A1:C2, 2, 0)",
533
+ A7: "=VLOOKUP(E1, A1:C2, 2, 1)",
534
+ }
535
+ const evaluatedGrid = evaluateGrid(grid);
536
+ expect(evaluatedGrid.A4).toBe(999);
537
+ expect(evaluatedGrid.A5).toBe(999);
538
+ expect(evaluatedGrid.A6).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
539
+ expect(evaluatedGrid.A7).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
540
+ });
541
+ });