@odoo/o-spreadsheet 14.0.1 → 15.0.0
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.
- package/dist/o_spreadsheet.cjs.js +31302 -0
- package/dist/o_spreadsheet.d.ts +6604 -0
- package/dist/o_spreadsheet.esm.js +31257 -0
- package/dist/o_spreadsheet.iife.js +31304 -0
- package/dist/o_spreadsheet.iife.min.js +3071 -0
- package/package.json +57 -15
- package/.eslintrc.json +0 -20
- package/.husky/post-checkout +0 -9
- package/.husky/pre-commit +0 -39
- package/.prettierignore +0 -1
- package/astToFormula.patch +0 -0
- package/demo/data.js +0 -255
- package/demo/index.html +0 -9
- package/demo/libs/Chart.bundle.js +0 -20755
- package/demo/main.js +0 -101
- package/doc/readme.md +0 -46
- package/rollup.config.js +0 -23
- package/src/base_plugin.ts +0 -102
- package/src/components/autofill.ts +0 -146
- package/src/components/bottom_bar.ts +0 -199
- package/src/components/color_picker.ts +0 -150
- package/src/components/composer/autocomplete_dropdown.ts +0 -135
- package/src/components/composer/composer.ts +0 -487
- package/src/components/composer/content_editable_helper.ts +0 -146
- package/src/components/figures/chart.ts +0 -70
- package/src/components/figures/container.ts +0 -268
- package/src/components/figures/text_figure.ts +0 -36
- package/src/components/grid.ts +0 -635
- package/src/components/helpers/dom_helpers.ts +0 -7
- package/src/components/helpers/drag_and_drop.ts +0 -17
- package/src/components/icons.ts +0 -36
- package/src/components/index.ts +0 -1
- package/src/components/menu.ts +0 -288
- package/src/components/overlay.ts +0 -457
- package/src/components/scrollbar.ts +0 -22
- package/src/components/selection_input.ts +0 -168
- package/src/components/side_panel/cell_is_rule_editor.ts +0 -169
- package/src/components/side_panel/chart_panel.ts +0 -104
- package/src/components/side_panel/color_scale_rule_editor.ts +0 -145
- package/src/components/side_panel/conditional_formatting.ts +0 -396
- package/src/components/side_panel/side_panel.ts +0 -127
- package/src/components/side_panel/translations_terms.ts +0 -45
- package/src/components/spreadsheet.ts +0 -198
- package/src/components/top_bar.ts +0 -535
- package/src/constants.ts +0 -26
- package/src/data.ts +0 -149
- package/src/fonts.ts +0 -41
- package/src/formulas/compiler.ts +0 -258
- package/src/formulas/composer_tokenizer.ts +0 -70
- package/src/formulas/index.ts +0 -15
- package/src/formulas/normalize.ts +0 -52
- package/src/formulas/parser.ts +0 -280
- package/src/formulas/range_tokenizer.ts +0 -97
- package/src/formulas/tokenizer.ts +0 -242
- package/src/functions/arguments.ts +0 -114
- package/src/functions/dates.ts +0 -302
- package/src/functions/helpers.ts +0 -592
- package/src/functions/index.ts +0 -52
- package/src/functions/module_database.ts +0 -282
- package/src/functions/module_date.ts +0 -743
- package/src/functions/module_info.ts +0 -69
- package/src/functions/module_logical.ts +0 -208
- package/src/functions/module_lookup.ts +0 -185
- package/src/functions/module_math.ts +0 -1252
- package/src/functions/module_operators.ts +0 -291
- package/src/functions/module_statistical.ts +0 -882
- package/src/functions/module_text.ts +0 -370
- package/src/helpers/color.ts +0 -30
- package/src/helpers/coordinates.ts +0 -71
- package/src/helpers/grid_manipulation.ts +0 -68
- package/src/helpers/index.ts +0 -7
- package/src/helpers/misc.ts +0 -76
- package/src/helpers/numbers.ts +0 -117
- package/src/helpers/uuid.ts +0 -19
- package/src/helpers/zones.ts +0 -263
- package/src/history.ts +0 -186
- package/src/index.ts +0 -84
- package/src/model.ts +0 -261
- package/src/plugins/autofill.ts +0 -412
- package/src/plugins/chart.ts +0 -404
- package/src/plugins/clipboard.ts +0 -461
- package/src/plugins/conditional_format.ts +0 -445
- package/src/plugins/core.ts +0 -1502
- package/src/plugins/edition.ts +0 -157
- package/src/plugins/evaluation.ts +0 -428
- package/src/plugins/figures.ts +0 -123
- package/src/plugins/formatting.ts +0 -630
- package/src/plugins/highlight.ts +0 -187
- package/src/plugins/index.ts +0 -32
- package/src/plugins/merge.ts +0 -524
- package/src/plugins/renderer.ts +0 -571
- package/src/plugins/selection.ts +0 -562
- package/src/plugins/selection_inputs.ts +0 -326
- package/src/registries/autofill_modifiers.ts +0 -76
- package/src/registries/autofill_rules.ts +0 -98
- package/src/registries/figure_registry.ts +0 -30
- package/src/registries/index.ts +0 -7
- package/src/registries/menu_items_registry.ts +0 -110
- package/src/registries/menus/cell_menu_registry.ts +0 -79
- package/src/registries/menus/col_menu_registry.ts +0 -63
- package/src/registries/menus/index.ts +0 -6
- package/src/registries/menus/menu_items_actions.ts +0 -425
- package/src/registries/menus/row_menu_registry.ts +0 -63
- package/src/registries/menus/sheet_menu_registry.ts +0 -75
- package/src/registries/menus/topbar_menu_registry.ts +0 -204
- package/src/registries/side_panel_registry.ts +0 -26
- package/src/registries/topbar_component_registry.ts +0 -12
- package/src/registry.ts +0 -51
- package/src/translation.ts +0 -44
- package/src/types/autofill.ts +0 -48
- package/src/types/chart.ts +0 -26
- package/src/types/commands.ts +0 -716
- package/src/types/conditional_formatting.ts +0 -124
- package/src/types/env.ts +0 -13
- package/src/types/functions.ts +0 -35
- package/src/types/getters.ts +0 -103
- package/src/types/index.ts +0 -20
- package/src/types/misc.ts +0 -143
- package/src/types/rendering.ts +0 -41
- package/src/types/workbook_data.ts +0 -62
- package/tests/__mocks__/uuid.ts +0 -7
- package/tests/canvas.mock.ts +0 -34
- package/tests/components/__mocks__/content_editable_helper.ts +0 -79
- package/tests/components/__mocks__/scrollbar.ts +0 -18
- package/tests/components/__snapshots__/autocomplete_dropdown_test.ts.snap +0 -29
- package/tests/components/__snapshots__/bottom_bar_test.ts.snap +0 -75
- package/tests/components/__snapshots__/context_menu_test.ts.snap +0 -88
- package/tests/components/__snapshots__/grid_test.ts.snap +0 -60
- package/tests/components/__snapshots__/spreadsheet_test.ts.snap +0 -455
- package/tests/components/__snapshots__/top_bar_test.ts.snap +0 -705
- package/tests/components/autocomplete_dropdown_test.ts +0 -315
- package/tests/components/autofill_test.ts +0 -167
- package/tests/components/bottom_bar_test.ts +0 -262
- package/tests/components/chart_side_panel_test.ts +0 -123
- package/tests/components/composer_test.ts +0 -400
- package/tests/components/context_menu_test.ts +0 -825
- package/tests/components/grid_manipulation_test.ts +0 -163
- package/tests/components/grid_test.ts +0 -581
- package/tests/components/overlay_test.ts +0 -541
- package/tests/components/selection_input_test.ts +0 -259
- package/tests/components/side_panel_test.ts +0 -148
- package/tests/components/spreadsheet_test.ts +0 -194
- package/tests/components/top_bar_test.ts +0 -427
- package/tests/data_test.ts +0 -175
- package/tests/dom_helper.ts +0 -42
- package/tests/formulas/__snapshots__/compiler_test.ts.snap +0 -302
- package/tests/formulas/compiler_test.ts +0 -266
- package/tests/formulas/composer_tokenizer_test.ts +0 -137
- package/tests/formulas/expressions_test.ts +0 -57
- package/tests/formulas/formulas_test.ts +0 -80
- package/tests/formulas/normalize_test.ts +0 -82
- package/tests/formulas/parser_test.ts +0 -224
- package/tests/formulas/range_tokenizer_test.ts +0 -187
- package/tests/formulas/tokenizer_test.ts +0 -164
- package/tests/functions/arguments_test.ts +0 -141
- package/tests/functions/dates_test.ts +0 -1081
- package/tests/functions/functions_test.ts +0 -53
- package/tests/functions/helper_test.ts +0 -98
- package/tests/functions/module_database_test.ts +0 -311
- package/tests/functions/module_date_test.ts +0 -941
- package/tests/functions/module_info_test.ts +0 -139
- package/tests/functions/module_logical_test.ts +0 -369
- package/tests/functions/module_lookup_test.ts +0 -541
- package/tests/functions/module_math_test.ts +0 -2482
- package/tests/functions/module_operators_test.ts +0 -955
- package/tests/functions/module_statistical_test.ts +0 -2014
- package/tests/functions/module_text_test.ts +0 -667
- package/tests/helpers/coordinates_test.ts +0 -25
- package/tests/helpers/misc_test.ts +0 -95
- package/tests/helpers/numbers_test.ts +0 -196
- package/tests/helpers/zones_test.ts +0 -97
- package/tests/helpers.ts +0 -384
- package/tests/menu_items_registry_test.ts +0 -540
- package/tests/model/plugins/__snapshots__/chart_test.ts.snap +0 -90
- package/tests/model/plugins/chart_test.ts +0 -562
- package/tests/model_test.ts +0 -82
- package/tests/plugins/__snapshots__/conditional_formatting_test.ts.snap +0 -131
- package/tests/plugins/__snapshots__/renderer_test.ts.snap +0 -371
- package/tests/plugins/autofill_test.ts +0 -457
- package/tests/plugins/borders_test.ts +0 -295
- package/tests/plugins/clipboard_test.ts +0 -1180
- package/tests/plugins/conditional_formatting_test.ts +0 -1253
- package/tests/plugins/core_test.ts +0 -614
- package/tests/plugins/edition_test.ts +0 -100
- package/tests/plugins/evaluation_async_test.ts +0 -332
- package/tests/plugins/evaluation_dates_test.ts +0 -79
- package/tests/plugins/evaluation_test.ts +0 -901
- package/tests/plugins/figures_test.ts +0 -327
- package/tests/plugins/formatting_test.ts +0 -391
- package/tests/plugins/grid_manipulation_test.ts +0 -1366
- package/tests/plugins/highlight_test.ts +0 -413
- package/tests/plugins/history_test.ts +0 -142
- package/tests/plugins/import_export_test.ts +0 -276
- package/tests/plugins/merges_test.ts +0 -490
- package/tests/plugins/navigation_test.ts +0 -181
- package/tests/plugins/plugins/evaluation_test.ts +0 -111
- package/tests/plugins/renderer_test.ts +0 -598
- package/tests/plugins/resizing_test.ts +0 -152
- package/tests/plugins/selection_input_test.ts +0 -409
- package/tests/plugins/selection_test.ts +0 -442
- package/tests/plugins/sheets_test.ts +0 -643
- package/tests/plugins/style_test.ts +0 -90
- package/tsconfig.json +0 -22
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import { rangeTokenize } from "../../src/formulas";
|
|
2
|
-
|
|
3
|
-
describe("rangeTokenizer", () => {
|
|
4
|
-
test("only range", () => {
|
|
5
|
-
expect(rangeTokenize("=A1:A2")).toEqual([
|
|
6
|
-
{ type: "OPERATOR", value: "=" },
|
|
7
|
-
{ type: "SYMBOL", value: "A1:A2" },
|
|
8
|
-
]);
|
|
9
|
-
});
|
|
10
|
-
test("operation and no range", () => {
|
|
11
|
-
expect(rangeTokenize("=A3+A1")).toEqual([
|
|
12
|
-
{ type: "OPERATOR", value: "=" },
|
|
13
|
-
{ type: "SYMBOL", value: "A3" },
|
|
14
|
-
{ type: "OPERATOR", value: "+" },
|
|
15
|
-
{ type: "SYMBOL", value: "A1" },
|
|
16
|
-
]);
|
|
17
|
-
});
|
|
18
|
-
test("operation and range", () => {
|
|
19
|
-
expect(rangeTokenize("=A3+A1:A2")).toEqual([
|
|
20
|
-
{ type: "OPERATOR", value: "=" },
|
|
21
|
-
{ type: "SYMBOL", value: "A3" },
|
|
22
|
-
{ type: "OPERATOR", value: "+" },
|
|
23
|
-
{ type: "SYMBOL", value: "A1:A2" },
|
|
24
|
-
]);
|
|
25
|
-
});
|
|
26
|
-
test("operation and range with spaces", () => {
|
|
27
|
-
expect(rangeTokenize("=A3+ A1 : A2 ")).toEqual([
|
|
28
|
-
{ type: "OPERATOR", value: "=" },
|
|
29
|
-
{ type: "SYMBOL", value: "A3" },
|
|
30
|
-
{ type: "OPERATOR", value: "+" },
|
|
31
|
-
{ type: "SYMBOL", value: "A1:A2" },
|
|
32
|
-
]);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test("range with spaces then operation", () => {
|
|
36
|
-
expect(rangeTokenize("= A1 : A2 +a3")).toEqual([
|
|
37
|
-
{ type: "OPERATOR", value: "=" },
|
|
38
|
-
{ type: "SYMBOL", value: "A1:A2" },
|
|
39
|
-
{ type: "OPERATOR", value: "+" },
|
|
40
|
-
{ type: "SYMBOL", value: "a3" },
|
|
41
|
-
]);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test("= SUM ( C4 : C5 )", () => {
|
|
45
|
-
expect(rangeTokenize("= SUM ( C4 : C5 )")).toEqual([
|
|
46
|
-
{ type: "OPERATOR", value: "=" },
|
|
47
|
-
{ type: "SPACE", value: " " },
|
|
48
|
-
{ type: "FUNCTION", value: "SUM" },
|
|
49
|
-
{ type: "SPACE", value: " " },
|
|
50
|
-
{ type: "LEFT_PAREN", value: "(" },
|
|
51
|
-
{ type: "SYMBOL", value: "C4:C5" },
|
|
52
|
-
{ type: "RIGHT_PAREN", value: ")" },
|
|
53
|
-
]);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
describe("knows what's a reference and what's not", () => {
|
|
58
|
-
test("lowercase cell reference", () => {
|
|
59
|
-
expect(rangeTokenize("=a1")).toEqual([
|
|
60
|
-
{ type: "OPERATOR", value: "=" },
|
|
61
|
-
{ type: "SYMBOL", value: "a1" },
|
|
62
|
-
]);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test("single cell reference", () => {
|
|
66
|
-
expect(rangeTokenize("=AA1")).toEqual([
|
|
67
|
-
{ type: "OPERATOR", value: "=" },
|
|
68
|
-
{ type: "SYMBOL", value: "AA1" },
|
|
69
|
-
]);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test("large single cell reference", () => {
|
|
73
|
-
expect(rangeTokenize("=AA100")).toEqual([
|
|
74
|
-
{ type: "OPERATOR", value: "=" },
|
|
75
|
-
{ type: "SYMBOL", value: "AA100" },
|
|
76
|
-
]);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test("fixed cell", () => {
|
|
80
|
-
expect(rangeTokenize("=$a$1")).toEqual([
|
|
81
|
-
{ type: "OPERATOR", value: "=" },
|
|
82
|
-
{ type: "SYMBOL", value: "$a$1" },
|
|
83
|
-
]);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test("fixed row", () => {
|
|
87
|
-
expect(rangeTokenize("=a$1")).toEqual([
|
|
88
|
-
{ type: "OPERATOR", value: "=" },
|
|
89
|
-
{ type: "SYMBOL", value: "a$1" },
|
|
90
|
-
]);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test("fixed column", () => {
|
|
94
|
-
expect(rangeTokenize("=$a1")).toEqual([
|
|
95
|
-
{ type: "OPERATOR", value: "=" },
|
|
96
|
-
{ type: "SYMBOL", value: "$a1" },
|
|
97
|
-
]);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test("sheet, with lowercase cell reference", () => {
|
|
101
|
-
expect(rangeTokenize("=Sheet3!a1")).toEqual([
|
|
102
|
-
{ type: "OPERATOR", value: "=" },
|
|
103
|
-
{ type: "SYMBOL", value: "Sheet3!a1" },
|
|
104
|
-
]);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
test("sheet, fixed cell", () => {
|
|
108
|
-
expect(rangeTokenize("=Sheet3!$a$1")).toEqual([
|
|
109
|
-
{ type: "OPERATOR", value: "=" },
|
|
110
|
-
{ type: "SYMBOL", value: "Sheet3!$a$1" },
|
|
111
|
-
]);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
test("sheet, fixed row", () => {
|
|
115
|
-
expect(rangeTokenize("=Sheet3!a$1")).toEqual([
|
|
116
|
-
{ type: "OPERATOR", value: "=" },
|
|
117
|
-
{ type: "SYMBOL", value: "Sheet3!a$1" },
|
|
118
|
-
]);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
test("sheet, fixed column", () => {
|
|
122
|
-
expect(rangeTokenize("=Sheet3!$a1")).toEqual([
|
|
123
|
-
{ type: "OPERATOR", value: "=" },
|
|
124
|
-
{ type: "SYMBOL", value: "Sheet3!$a1" },
|
|
125
|
-
]);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
test("sheet with quotes and spaces", () => {
|
|
129
|
-
expect(rangeTokenize("='Sheet3'!a1")).toEqual([
|
|
130
|
-
{ type: "OPERATOR", value: "=" },
|
|
131
|
-
{ type: "SYMBOL", value: "'Sheet3'!a1" },
|
|
132
|
-
]);
|
|
133
|
-
expect(rangeTokenize("='S h i t'!a1")).toEqual([
|
|
134
|
-
{ type: "OPERATOR", value: "=" },
|
|
135
|
-
{ type: "SYMBOL", value: "'S h i t'!a1" },
|
|
136
|
-
]);
|
|
137
|
-
expect(rangeTokenize("='S ''h i t'!a1")).toEqual([
|
|
138
|
-
{ type: "OPERATOR", value: "=" },
|
|
139
|
-
{ type: "SYMBOL", value: "'S ''h i t'!a1" },
|
|
140
|
-
]);
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
describe("tokenize ranges", () => {
|
|
145
|
-
test("normal range", () => {
|
|
146
|
-
expect(rangeTokenize("=A1:B2")).toEqual([
|
|
147
|
-
{ type: "OPERATOR", value: "=" },
|
|
148
|
-
{ type: "SYMBOL", value: "A1:B2" },
|
|
149
|
-
]);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
test("invalid range should be corrected", () => {
|
|
153
|
-
expect(rangeTokenize("=B1:A2")).toEqual([
|
|
154
|
-
{ type: "OPERATOR", value: "=" },
|
|
155
|
-
{ type: "SYMBOL", value: "B1:A2" },
|
|
156
|
-
]);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
test.skip("column", () => {
|
|
160
|
-
expect(rangeTokenize("=A:A")).toEqual({
|
|
161
|
-
type: "BIN_OPERATION",
|
|
162
|
-
value: ":",
|
|
163
|
-
left: {
|
|
164
|
-
type: "REFERENCE",
|
|
165
|
-
value: "A",
|
|
166
|
-
},
|
|
167
|
-
right: {
|
|
168
|
-
type: "REFERENCE",
|
|
169
|
-
value: "A",
|
|
170
|
-
},
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
test.skip("row", () => {
|
|
174
|
-
expect(rangeTokenize("=1:1")).toEqual({
|
|
175
|
-
type: "BIN_OPERATION",
|
|
176
|
-
value: ":",
|
|
177
|
-
left: {
|
|
178
|
-
type: "REFERENCE",
|
|
179
|
-
value: "1",
|
|
180
|
-
},
|
|
181
|
-
right: {
|
|
182
|
-
type: "REFERENCE",
|
|
183
|
-
value: "1",
|
|
184
|
-
},
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
});
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { tokenize } from "../../src/formulas";
|
|
2
|
-
|
|
3
|
-
describe("tokenizer", () => {
|
|
4
|
-
test("simple token", () => {
|
|
5
|
-
expect(tokenize("1")).toEqual([{ type: "NUMBER", value: "1" }]);
|
|
6
|
-
});
|
|
7
|
-
test("number with decimal token", () => {
|
|
8
|
-
expect(tokenize("=1.5")).toEqual([
|
|
9
|
-
{ type: "OPERATOR", value: "=" },
|
|
10
|
-
{ type: "NUMBER", value: "1.5" },
|
|
11
|
-
]);
|
|
12
|
-
});
|
|
13
|
-
test("formula token", () => {
|
|
14
|
-
expect(tokenize("=1")).toEqual([
|
|
15
|
-
{ type: "OPERATOR", value: "=" },
|
|
16
|
-
{ type: "NUMBER", value: "1" },
|
|
17
|
-
]);
|
|
18
|
-
});
|
|
19
|
-
test("longer operators >=", () => {
|
|
20
|
-
expect(tokenize("= >= <= <")).toEqual([
|
|
21
|
-
{ type: "OPERATOR", value: "=" },
|
|
22
|
-
{ type: "SPACE", value: " " },
|
|
23
|
-
{ type: "OPERATOR", value: ">=" },
|
|
24
|
-
{ type: "SPACE", value: " " },
|
|
25
|
-
{ type: "OPERATOR", value: "<=" },
|
|
26
|
-
{ type: "SPACE", value: " " },
|
|
27
|
-
{ type: "OPERATOR", value: "<" },
|
|
28
|
-
]);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test("concat operator", () => {
|
|
32
|
-
expect(tokenize("=&")).toEqual([
|
|
33
|
-
{ type: "OPERATOR", value: "=" },
|
|
34
|
-
{ type: "OPERATOR", value: "&" },
|
|
35
|
-
]);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test("not equal operator", () => {
|
|
39
|
-
expect(tokenize("=<>")).toEqual([
|
|
40
|
-
{ type: "OPERATOR", value: "=" },
|
|
41
|
-
{ type: "OPERATOR", value: "<>" },
|
|
42
|
-
]);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test("can tokenize various number expressions", () => {
|
|
46
|
-
expect(tokenize("1%")).toEqual([{ type: "NUMBER", value: "1%" }]);
|
|
47
|
-
expect(tokenize("1 %")).toEqual([{ type: "NUMBER", value: "1 %" }]);
|
|
48
|
-
expect(tokenize("1.1")).toEqual([{ type: "NUMBER", value: "1.1" }]);
|
|
49
|
-
expect(tokenize("1e3")).toEqual([{ type: "NUMBER", value: "1e3" }]);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test("debug formula token", () => {
|
|
53
|
-
expect(tokenize("=?1")).toEqual([
|
|
54
|
-
{ type: "OPERATOR", value: "=" },
|
|
55
|
-
{ type: "DEBUGGER", value: "?" },
|
|
56
|
-
{ type: "NUMBER", value: "1" },
|
|
57
|
-
]);
|
|
58
|
-
});
|
|
59
|
-
test("String", () => {
|
|
60
|
-
expect(tokenize('"hello"')).toEqual([{ type: "STRING", value: '"hello"' }]);
|
|
61
|
-
expect(tokenize("'hello'")).toEqual([{ type: "SYMBOL", value: "'hello'" }]);
|
|
62
|
-
expect(tokenize("'hello")).toEqual([{ type: "UNKNOWN", value: "'hello" }]);
|
|
63
|
-
expect(tokenize('"he\\"l\\"lo"')).toEqual([{ type: "STRING", value: '"he\\"l\\"lo"' }]);
|
|
64
|
-
expect(tokenize("\"hel'l'o\"")).toEqual([{ type: "STRING", value: "\"hel'l'o\"" }]);
|
|
65
|
-
expect(tokenize('"hello""test"')).toEqual([
|
|
66
|
-
{ type: "STRING", value: '"hello"' },
|
|
67
|
-
{ type: "STRING", value: '"test"' },
|
|
68
|
-
]);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test.each(['"hello', `"hello'`, '"hello\\"'])("String without closing double quotes", (str) => {
|
|
72
|
-
expect(tokenize(str)).toEqual([{ type: "STRING", value: str }]);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
test("Function token", () => {
|
|
76
|
-
expect(tokenize("SUM")).toEqual([{ type: "FUNCTION", value: "SUM" }]);
|
|
77
|
-
expect(tokenize("RAND")).toEqual([{ type: "FUNCTION", value: "RAND" }]);
|
|
78
|
-
expect(tokenize("rand")).toEqual([{ type: "FUNCTION", value: "rand" }]);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test("Function token with point", () => {
|
|
82
|
-
expect(tokenize("CEILING.MATH")).toEqual([{ type: "FUNCTION", value: "CEILING.MATH" }]);
|
|
83
|
-
expect(tokenize("ceiling.math")).toEqual([{ type: "FUNCTION", value: "ceiling.math" }]);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test("Boolean", () => {
|
|
87
|
-
expect(tokenize("true")).toEqual([{ type: "SYMBOL", value: "true" }]);
|
|
88
|
-
expect(tokenize("false")).toEqual([
|
|
89
|
-
{
|
|
90
|
-
type: "SYMBOL",
|
|
91
|
-
value: "false",
|
|
92
|
-
},
|
|
93
|
-
]);
|
|
94
|
-
expect(tokenize("=AND(true,false)")).toEqual([
|
|
95
|
-
{ type: "OPERATOR", value: "=" },
|
|
96
|
-
{ type: "FUNCTION", value: "AND" },
|
|
97
|
-
{ type: "LEFT_PAREN", value: "(" },
|
|
98
|
-
{ type: "SYMBOL", value: "true" },
|
|
99
|
-
{ type: "COMMA", value: "," },
|
|
100
|
-
{ type: "SYMBOL", value: "false" },
|
|
101
|
-
{ type: "RIGHT_PAREN", value: ")" },
|
|
102
|
-
]);
|
|
103
|
-
expect(tokenize("=trueee")).toEqual([
|
|
104
|
-
{ type: "OPERATOR", value: "=" },
|
|
105
|
-
{ type: "SYMBOL", value: "trueee" },
|
|
106
|
-
]);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test("$references", () => {
|
|
110
|
-
expect(tokenize("=$A$1")).toEqual([
|
|
111
|
-
{ type: "OPERATOR", value: "=" },
|
|
112
|
-
{ type: "SYMBOL", value: "$A$1" },
|
|
113
|
-
]);
|
|
114
|
-
expect(tokenize("=C$1")).toEqual([
|
|
115
|
-
{ type: "OPERATOR", value: "=" },
|
|
116
|
-
{ type: "SYMBOL", value: "C$1" },
|
|
117
|
-
]);
|
|
118
|
-
expect(tokenize("=$C1")).toEqual([
|
|
119
|
-
{ type: "OPERATOR", value: "=" },
|
|
120
|
-
{ type: "SYMBOL", value: "$C1" },
|
|
121
|
-
]);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
test("reference and sheets", () => {
|
|
125
|
-
expect(tokenize("=Sheet1!A1")).toEqual([
|
|
126
|
-
{ type: "OPERATOR", value: "=" },
|
|
127
|
-
{ type: "SYMBOL", value: "Sheet1!A1" },
|
|
128
|
-
]);
|
|
129
|
-
expect(tokenize("='Sheet1'!A1")).toEqual([
|
|
130
|
-
{ type: "OPERATOR", value: "=" },
|
|
131
|
-
{ type: "SYMBOL", value: "'Sheet1'!A1" },
|
|
132
|
-
]);
|
|
133
|
-
expect(tokenize("='Aryl Nibor Xela Nalim'!A1")).toEqual([
|
|
134
|
-
{ type: "OPERATOR", value: "=" },
|
|
135
|
-
{ type: "SYMBOL", value: "'Aryl Nibor Xela Nalim'!A1" },
|
|
136
|
-
]);
|
|
137
|
-
expect(tokenize("=Sheet1!$A1")).toEqual([
|
|
138
|
-
{ type: "OPERATOR", value: "=" },
|
|
139
|
-
{ type: "SYMBOL", value: "Sheet1!$A1" },
|
|
140
|
-
]);
|
|
141
|
-
expect(tokenize("=Sheet1!A$1")).toEqual([
|
|
142
|
-
{ type: "OPERATOR", value: "=" },
|
|
143
|
-
{ type: "SYMBOL", value: "Sheet1!A$1" },
|
|
144
|
-
]);
|
|
145
|
-
expect(tokenize("='a '' b'!A1")).toEqual([
|
|
146
|
-
{ type: "OPERATOR", value: "=" },
|
|
147
|
-
{ type: "SYMBOL", value: "'a '' b'!A1" },
|
|
148
|
-
]);
|
|
149
|
-
|
|
150
|
-
// note the missing ' in the following test:
|
|
151
|
-
expect(tokenize("='Sheet1!A1")).toEqual([
|
|
152
|
-
{ type: "OPERATOR", value: "=" },
|
|
153
|
-
{ type: "UNKNOWN", value: "'Sheet1!A1" },
|
|
154
|
-
]);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
test("Unknown characters", () => {
|
|
158
|
-
expect(tokenize("=ù4")).toEqual([
|
|
159
|
-
{ type: "OPERATOR", value: "=" },
|
|
160
|
-
{ type: "UNKNOWN", value: "ù" },
|
|
161
|
-
{ type: "NUMBER", value: "4" },
|
|
162
|
-
]);
|
|
163
|
-
});
|
|
164
|
-
});
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { args } from "../../src/functions/arguments";
|
|
2
|
-
|
|
3
|
-
describe("args", () => {
|
|
4
|
-
test("various", () => {
|
|
5
|
-
expect(args(``)).toEqual([]);
|
|
6
|
-
expect(args(`test (number) some number`)).toEqual([
|
|
7
|
-
{
|
|
8
|
-
type: ["NUMBER"],
|
|
9
|
-
description: "some number",
|
|
10
|
-
name: "test",
|
|
11
|
-
},
|
|
12
|
-
]);
|
|
13
|
-
|
|
14
|
-
expect(
|
|
15
|
-
args(`
|
|
16
|
-
test (number) some number
|
|
17
|
-
test2 (number) some other number
|
|
18
|
-
`)
|
|
19
|
-
).toEqual([
|
|
20
|
-
{
|
|
21
|
-
type: ["NUMBER"],
|
|
22
|
-
description: "some number",
|
|
23
|
-
name: "test",
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
type: ["NUMBER"],
|
|
27
|
-
description: "some other number",
|
|
28
|
-
name: "test2",
|
|
29
|
-
},
|
|
30
|
-
]);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test("empty description", () => {
|
|
34
|
-
expect(args(`test (number)`)).toEqual([
|
|
35
|
-
{
|
|
36
|
-
type: ["NUMBER"],
|
|
37
|
-
name: "test",
|
|
38
|
-
description: "",
|
|
39
|
-
},
|
|
40
|
-
]);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test("default number value", () => {
|
|
44
|
-
expect(args(`test (number,default=10) descr`)).toEqual([
|
|
45
|
-
{
|
|
46
|
-
type: ["NUMBER"],
|
|
47
|
-
name: "test",
|
|
48
|
-
description: "descr",
|
|
49
|
-
default: 10,
|
|
50
|
-
},
|
|
51
|
-
]);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test("default string value", () => {
|
|
55
|
-
expect(args(`test (number,default="asdf") descr`)).toEqual([
|
|
56
|
-
{
|
|
57
|
-
type: ["NUMBER"],
|
|
58
|
-
name: "test",
|
|
59
|
-
description: "descr",
|
|
60
|
-
default: "asdf",
|
|
61
|
-
},
|
|
62
|
-
]);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test("with parenthesis in the description", () => {
|
|
66
|
-
expect(args(`test (number) descr( hahaha )`)).toEqual([
|
|
67
|
-
{
|
|
68
|
-
type: ["NUMBER"],
|
|
69
|
-
name: "test",
|
|
70
|
-
description: "descr( hahaha )",
|
|
71
|
-
},
|
|
72
|
-
]);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
test("does not care if lower or uppercase", () => {
|
|
76
|
-
expect(args(`test (NUMBER)`)).toEqual([
|
|
77
|
-
{
|
|
78
|
-
type: ["NUMBER"],
|
|
79
|
-
name: "test",
|
|
80
|
-
description: "",
|
|
81
|
-
},
|
|
82
|
-
]);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test("accept all basic types", () => {
|
|
86
|
-
expect(args(`test (boolean)`)[0].type).toEqual(["BOOLEAN"]);
|
|
87
|
-
expect(args(`test (any)`)[0].type).toEqual(["ANY"]);
|
|
88
|
-
expect(args(`test (NumBer)`)[0].type).toEqual(["NUMBER"]);
|
|
89
|
-
expect(args(`test (string)`)[0].type).toEqual(["STRING"]);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test("accept all range types", () => {
|
|
93
|
-
expect(args(`test (range)`)[0].type).toEqual(["RANGE"]);
|
|
94
|
-
expect(args(`test (range<any>)`)[0].type).toEqual(["RANGE"]);
|
|
95
|
-
expect(args(`test (range<boolean>)`)[0].type).toEqual(["RANGE<BOOLEAN>"]);
|
|
96
|
-
expect(args(`test (range<number>)`)[0].type).toEqual(["RANGE<NUMBER>"]);
|
|
97
|
-
expect(args(`test (range<string>)`)[0].type).toEqual(["RANGE<STRING>"]);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test("accept multiple types", () => {
|
|
101
|
-
expect(args(`test (boolean,string)`)[0].type).toEqual(["BOOLEAN", "STRING"]);
|
|
102
|
-
expect(args(`test (string,any)`)[0].type).toEqual(["STRING", "ANY"]);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test("accept optional flag", () => {
|
|
106
|
-
expect(args(`test (boolean,optional)`)).toEqual([
|
|
107
|
-
{
|
|
108
|
-
description: "",
|
|
109
|
-
name: "test",
|
|
110
|
-
type: ["BOOLEAN"],
|
|
111
|
-
optional: true,
|
|
112
|
-
},
|
|
113
|
-
]);
|
|
114
|
-
expect(args(`test (boolean,optional,string)`)).toEqual([
|
|
115
|
-
{
|
|
116
|
-
description: "",
|
|
117
|
-
name: "test",
|
|
118
|
-
type: ["BOOLEAN", "STRING"],
|
|
119
|
-
optional: true,
|
|
120
|
-
},
|
|
121
|
-
]);
|
|
122
|
-
});
|
|
123
|
-
test("accept repeating flag", () => {
|
|
124
|
-
expect(args(`test (boolean,repeating)`)).toEqual([
|
|
125
|
-
{
|
|
126
|
-
description: "",
|
|
127
|
-
name: "test",
|
|
128
|
-
type: ["BOOLEAN"],
|
|
129
|
-
repeating: true,
|
|
130
|
-
},
|
|
131
|
-
]);
|
|
132
|
-
expect(args(`test (boolean,repeating,number)`)).toEqual([
|
|
133
|
-
{
|
|
134
|
-
description: "",
|
|
135
|
-
name: "test",
|
|
136
|
-
type: ["BOOLEAN", "NUMBER"],
|
|
137
|
-
repeating: true,
|
|
138
|
-
},
|
|
139
|
-
]);
|
|
140
|
-
});
|
|
141
|
-
});
|