Skip to content

Commit c31c788

Browse files
committed
[IMP] composer: prettify v3
max length before split ~ 60 chars Tofixup ? task: 4735172
1 parent 3c0fb50 commit c31c788

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

src/components/composer/composer/prettifier_content.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ function fits(width: number, x: SubRule): boolean {
207207
// ---------------------------------------
208208

209209
export function prettify(ast: AST) {
210-
return "=" + print(astToPp(ast), 39); // 39 but 40 with the `= ` at the beginning
210+
return "=" + print(astToPp(ast), 59); // 59 but 60 with the `=` at the beginning
211211
}
212212

213213
/** transform an AST composed of sub-ASTs into a PrettifyPossibility composed of sub-PrettifyPossibility.*/

tests/composer/composer_store.test.ts

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,31 +1232,36 @@ describe("edition", () => {
12321232
});
12331233

12341234
test("Split the content in multiple lines when it is too long", () => {
1235-
setCellContent(model, "A1", "=SUM(11111111,22222222,33333333)"); // 41 characters
1235+
setCellContent(model, "A1", "=SUM(11111111,22222222,33333333,44444444,55555555)"); // 41 characters
12361236
composerStore.startEdition();
1237-
expect(composerStore.currentContent).toBe("=SUM(11111111, 22222222, 33333333)");
1237+
expect(composerStore.currentContent).toBe(
1238+
"=SUM(11111111, 22222222, 33333333, 44444444, 55555555)"
1239+
);
12381240

1239-
setCellContent(model, "A1", "=SUM(11111111,22222222,33333333,44444444)"); // 41 characters
1241+
setCellContent(model, "A1", "=SUM(11111111,22222222,33333333,44444444,55555555,66666666)"); // 41 characters
12401242
composerStore.startEdition();
12411243
expect(composerStore.currentContent).toBe(
12421244
// prettier-ignore
12431245
"=SUM(\n" +
12441246
"\t11111111, \n" +
12451247
"\t22222222, \n" +
12461248
"\t33333333, \n" +
1247-
"\t44444444\n" +
1249+
"\t44444444, \n" +
1250+
"\t55555555, \n" +
1251+
"\t66666666\n" +
12481252
")"
12491253
);
12501254
});
12511255

12521256
test("nested functions are properly indented", () => {
1253-
setCellContent(model, "A1", "=SUM(AVERAGE(1,2,3,4), MAX(5,6,7,8))");
1257+
setCellContent(model, "A1", "=SUM(AVERAGE(1,2,3,4), MAX(5,6,7,8), MIN(10,11,12,13))");
12541258
composerStore.startEdition();
12551259
expect(composerStore.currentContent).toBe(
12561260
// prettier-ignore
12571261
"=SUM(\n" +
12581262
"\tAVERAGE(1, 2, 3, 4), \n" +
1259-
"\tMAX(5, 6, 7, 8)\n" +
1263+
"\tMAX(5, 6, 7, 8), \n" +
1264+
"\tMIN(10, 11, 12, 13)\n" +
12601265
")"
12611266
);
12621267
});
@@ -1265,18 +1270,20 @@ describe("edition", () => {
12651270
setCellContent(
12661271
model,
12671272
"A1",
1268-
"=SUM(AVERAGE(COUNT(4,5,6,7),COUNT(10,11,12,13)), MAX(COUNT(4,5,6,7),COUNT(10,11,12,13)))"
1273+
"=SUM(AVERAGE(COUNT(4,5,6,7),COUNT(10,11,12,13),COUNT(14,15,16,17)), MAX(COUNT(4,5,6,7),COUNT(10,11,12,13),COUNT(14,15,16,17)))"
12691274
);
12701275
composerStore.startEdition();
12711276
expect(composerStore.currentContent).toBe(
12721277
"=SUM(\n" +
12731278
"\tAVERAGE(\n" +
12741279
"\t\tCOUNT(4, 5, 6, 7), \n" +
1275-
"\t\tCOUNT(10, 11, 12, 13)\n" +
1280+
"\t\tCOUNT(10, 11, 12, 13), \n" +
1281+
"\t\tCOUNT(14, 15, 16, 17)\n" +
12761282
"\t), \n" +
12771283
"\tMAX(\n" +
12781284
"\t\tCOUNT(4, 5, 6, 7), \n" +
1279-
"\t\tCOUNT(10, 11, 12, 13)\n" +
1285+
"\t\tCOUNT(10, 11, 12, 13), \n" +
1286+
"\t\tCOUNT(14, 15, 16, 17)\n" +
12801287
"\t)\n" +
12811288
")"
12821289
);
@@ -1286,15 +1293,15 @@ describe("edition", () => {
12861293
setCellContent(
12871294
model,
12881295
"A1",
1289-
"=SUM(1111 + 2222 + 3333 + 4444 + 5555 + 6666 + 7777 + 8888 + 9999)"
1296+
"=SUM(1111 + 2222 + 3333 + 4444 + 5555 + 6666 + 7777 + 8888 + 9999 + 11111 + 22222 + 33333 + 44444)"
12901297
);
12911298
composerStore.startEdition();
12921299
expect(composerStore.currentContent).toBe(
12931300
//prettier-ignore
12941301
"=SUM(\n" +
1295-
"\t1111+2222+3333+4444+5555+6666+7777+\n" +
1296-
"\t\t8888+\n" +
1297-
"\t\t9999\n" +
1302+
"\t1111+2222+3333+4444+5555+6666+7777+8888+9999+11111+22222+\n" +
1303+
"\t\t33333+\n" +
1304+
"\t\t44444\n" +
12981305
")"
12991306
);
13001307
});
@@ -1303,29 +1310,33 @@ describe("edition", () => {
13031310
setCellContent(
13041311
model,
13051312
"A1",
1306-
"=SUM(1111 + 2222 + 3333 + 4444 + 5555 + 6666 + 7777 + 8888 * 9999 - 10000 + 20000 / 30000 )"
1313+
"=SUM(1111 + 2222 + 3333 + 4444 + 5555 + 6666 + 7777 + 8888 + 9999 + 11111 + 22222 + 33333 * 44444 - 55555 + 66666 / 77777 )"
13071314
);
13081315
composerStore.startEdition();
13091316
expect(composerStore.currentContent).toBe(
13101317
"=SUM(\n" +
1311-
"\t1111+2222+3333+4444+5555+6666+7777+\n" +
1312-
"\t\t8888*9999-\n" +
1313-
"\t\t10000+\n" +
1314-
"\t\t20000/30000\n" +
1318+
"\t1111+2222+3333+4444+5555+6666+7777+8888+9999+11111+22222+\n" +
1319+
"\t\t33333*44444-\n" +
1320+
"\t\t55555+\n" +
1321+
"\t\t66666/77777\n" +
13151322
")"
13161323
);
13171324
});
13181325

13191326
test("long functions with nested parenthesis for mathematical operation are properly indented with sub-lvls", () => {
1320-
setCellContent(model, "A1", "=1*(2-2-2-2-2-2-2-(3+3+3+3+3+3+3+3+3/(4+5+6+7+5+6+7+8+9)))");
1327+
setCellContent(
1328+
model,
1329+
"A1",
1330+
"=1*(2-2-2-2-2-2-2-(3+3+3+3+3+3+3+3+3-(4+4+4+4+4+4+4+4+4/(4+5+6+7+5+6+7+8+9))))"
1331+
);
13211332
composerStore.startEdition();
13221333
expect(composerStore.currentContent).toBe(
13231334
"=1*\n" +
13241335
"\t(\n" +
13251336
"\t\t2-2-2-2-2-2-2-\n" +
13261337
"\t\t\t(\n" +
1327-
"\t\t\t\t3+3+3+3+3+3+3+3+\n" +
1328-
"\t\t\t\t\t3/(4+5+6+7+5+6+7+8+9)\n" +
1338+
"\t\t\t\t3+3+3+3+3+3+3+3+3-\n" +
1339+
"\t\t\t\t\t(4+4+4+4+4+4+4+4+4/(4+5+6+7+5+6+7+8+9))\n" +
13291340
"\t\t\t)\n" +
13301341
"\t)"
13311342
);

0 commit comments

Comments
 (0)