From ae1a1619ffc99f838b4648738226fabbeac47120 Mon Sep 17 00:00:00 2001 From: Joao Azevedo Date: Thu, 29 Aug 2024 10:38:09 +0000 Subject: [PATCH] Fix break propagation of Alignment_Tables Do not group segments before/between/after table separators --- src/prettier_ada-documents-builders.adb | 22 +- src/prettier_ada-documents-implementation.adb | 61 +++- src/prettier_ada-documents-implementation.ads | 10 + src/prettier_ada-documents-json.adb | 5 +- testsuite/tests/builders/test.out | 303 +++++++++--------- testsuite/tests/table_alignment/doc.json | 1 + .../must_break_false/doc.json | 164 ++++++++++ .../must_break_false/test.out | 6 + .../must_break_false/test.yaml | 4 + .../must_break_true/doc.json | 157 +++++++++ .../must_break_true/test.out | 4 + .../must_break_true/test.yaml | 4 + 12 files changed, 569 insertions(+), 172 deletions(-) create mode 100644 testsuite/tests/table_break_propagation/must_break_false/doc.json create mode 100644 testsuite/tests/table_break_propagation/must_break_false/test.out create mode 100644 testsuite/tests/table_break_propagation/must_break_false/test.yaml create mode 100644 testsuite/tests/table_break_propagation/must_break_true/doc.json create mode 100644 testsuite/tests/table_break_propagation/must_break_true/test.out create mode 100644 testsuite/tests/table_break_propagation/must_break_true/test.yaml diff --git a/src/prettier_ada-documents-builders.adb b/src/prettier_ada-documents-builders.adb index 0963825..17bc861 100644 --- a/src/prettier_ada-documents-builders.adb +++ b/src/prettier_ada-documents-builders.adb @@ -558,7 +558,7 @@ package body Prettier_Ada.Documents.Builders is (Elements_Aggregate.First_Element); else - Row_Elements.Append (Group (Elements_Aggregate)); + Row_Elements.Append (List (Elements_Aggregate)); end if; Elements_Aggregate.Clear; @@ -577,14 +577,14 @@ package body Prettier_Ada.Documents.Builders is -- Elements_Aggregate won't be empty. If so, add it to -- Row_Elements. - if not Elements_Aggregate.Is_Empty then - if Elements_Aggregate.Length = 1 then - Row_Elements.Append (Elements_Aggregate.First_Element); + if not Elements_Aggregate.Is_Empty then + if Elements_Aggregate.Length = 1 then + Row_Elements.Append (Elements_Aggregate.First_Element); - else - Row_Elements.Append (Group (Elements_Aggregate)); - end if; + else + Row_Elements.Append (List (Elements_Aggregate)); end if; + end if; -- Flush this row's elements and separators Elements.Append (Row_Elements); @@ -593,16 +593,20 @@ package body Prettier_Ada.Documents.Builders is end loop; end Normalize_Table; + use type Ada.Containers.Count_Type; + begin Normalize_Table; return Wrap_Command (new Command_Type' - (Kind => Command_Alignment_Table, + (Kind => Command_Alignment_Table, Alignment_Table_Elements => Elements, Alignment_Table_Separators => Separators, - Alignment_Table_Must_Break => Must_Break)); + Alignment_Table_Must_Break => Must_Break, + Break_Parents => + Must_Break and Elements.Length > 1)); end Alignment_Table; ------------------------------- diff --git a/src/prettier_ada-documents-implementation.adb b/src/prettier_ada-documents-implementation.adb index 919a08a..1df51d1 100644 --- a/src/prettier_ada-documents-implementation.adb +++ b/src/prettier_ada-documents-implementation.adb @@ -117,6 +117,11 @@ package body Prettier_Ada.Documents.Implementation is (Group_Stack : in out Document_Vector); -- TODO: Description + procedure Break_Parent_Table + (Table_Stack : in out Document_Vector); + -- Sets Alignment_Table_Must_Break and Break_Parents to True for the last + -- element of Table_Stack. + function Fits (Next : Print_Command_Type; Rest_Commands : Print_Command_Type_Vector; @@ -269,6 +274,27 @@ package body Prettier_Ada.Documents.Implementation is end if; end Break_Parent_Group; + ------------------------ + -- Break_Parent_Table -- + ------------------------ + + procedure Break_Parent_Table + (Table_Stack : in out Document_Vector) is + begin + if not Table_Stack.Is_Empty then + Table_Stack + .Last_Element + .Bare_Document + .Command + .Alignment_Table_Must_Break := True; + Table_Stack + .Last_Element + .Bare_Document + .Command + .Break_Parents := True; + end if; + end Break_Parent_Table; + ---------- -- Fits -- ---------- @@ -2529,6 +2555,7 @@ package body Prettier_Ada.Documents.Implementation is procedure Propagate_Breaks (Document : Document_Type) is Already_Visited : Document_Hashed_Set; Group_Stack : Document_Vector; + Table_Stack : Document_Vector; function Propagate_Breaks_On_Enter (Document : Document_Type) @@ -2559,6 +2586,7 @@ package body Prettier_Ada.Documents.Implementation is case Document.Bare_Document.Command.Kind is when Command_Break_Parent => Break_Parent_Group (Group_Stack); + Break_Parent_Table (Table_Stack); when Command_Group => Group_Stack.Append (Document); @@ -2569,6 +2597,15 @@ package body Prettier_Ada.Documents.Implementation is end if; Already_Visited.Insert (Document); + when Command_Alignment_Table => + Table_Stack.Append (Document); + if Already_Visited.Contains (Document) then + return + Optional_Boolean' + (Is_Set => True, Value => False); + end if; + Already_Visited.Insert (Document); + when others => null; end case; @@ -2604,8 +2641,25 @@ package body Prettier_Ada.Documents.Implementation is Group_Stack.Delete_Last; if Group.Bare_Document.Command.Break then Break_Parent_Group (Group_Stack); + Break_Parent_Table (Table_Stack); + end if; + end; + + elsif Document.Bare_Document.Command.Kind + in Command_Alignment_Table + then + declare + Table : constant Document_Type := + Table_Stack.Last_Element; + + begin + Table_Stack.Delete_Last; + if Table.Bare_Document.Command.Break_Parents then + Break_Parent_Group (Group_Stack); + Break_Parent_Table (Table_Stack); end if; end; + end if; when others => @@ -2963,7 +3017,7 @@ package body Prettier_Ada.Documents.Implementation is .Command .Alignment_Table_Elements .Constant_Reference (Row_Index) - .Last_Index; + .First_Index; Last_Column_Index : constant Positive := Doc .Bare_Document @@ -3095,7 +3149,10 @@ package body Prettier_Ada.Documents.Implementation is end if; Item.Text := Item.Text.Slice (MF, ML); - Item.Display_Width := @ - Trim_Count; + Item.Display_Width := + (if Trim_Count > Item.Display_Width + then 0 + else Item.Display_Width - Trim_Count); end Trim; ---------- diff --git a/src/prettier_ada-documents-implementation.ads b/src/prettier_ada-documents-implementation.ads index ec5e6ee..98a86fe 100644 --- a/src/prettier_ada-documents-implementation.ads +++ b/src/prettier_ada-documents-implementation.ads @@ -148,6 +148,16 @@ private package Prettier_Ada.Documents.Implementation is Alignment_Table_Elements : Document_Table; Alignment_Table_Separators : Document_Table; Alignment_Table_Must_Break : Boolean; + -- If True, adds a Hardline between table rows. If the table has + -- more than one row, also breaks parents (and implies that + -- Break_Parents = True). + + Break_Parents : Boolean; + -- Flag used by the Propagate_Breaks procedure. If True, breaks + -- parent documents. This is initially set by the + -- Alignment_Table builder based on the Must_Break value and rows + -- count. The Propagate_Breaks procedure can change this value to + -- True if it detects Break_Parent commands inside the table rows. when Command_Alignment_Table_Separator => Alignment_Table_Separator_Text : Prettier_String; diff --git a/src/prettier_ada-documents-json.adb b/src/prettier_ada-documents-json.adb index d3831e2..5bfa65c 100644 --- a/src/prettier_ada-documents-json.adb +++ b/src/prettier_ada-documents-json.adb @@ -271,6 +271,8 @@ package body Prettier_Ada.Documents.Json is From_Document_Table (Command.Alignment_Table_Separators)); Result.Set_Field ("mustBreak", Command.Alignment_Table_Must_Break); + Result.Set_Field + ("breakParents", Command.Break_Parents); when Command_Alignment_Table_Separator => Result.Set_Field ("command", "alignmentTableSeparator"); @@ -935,7 +937,8 @@ package body Prettier_Ada.Documents.Json is To_Document_Table (Get (Json, "elements")), Alignment_Table_Separators => To_Document_Table (Get (Json, "separators")), - Alignment_Table_Must_Break => Get (Json, "mustBreak")); + Alignment_Table_Must_Break => Get (Json, "mustBreak"), + Break_Parents => Get (Json, "breakParents")); end To_Command_Alignment_Table; -------------------------------- diff --git a/testsuite/tests/builders/test.out b/testsuite/tests/builders/test.out index 167075e..4c582a4 100644 --- a/testsuite/tests/builders/test.out +++ b/testsuite/tests/builders/test.out @@ -210,11 +210,11 @@ begin "command": "group", "expandedStates": null, "groupContents": { - "id": 83, + "id": 82, "kind": "list", "list": [ { - "id": 77, + "id": 76, "kind": "text", "text": "record" }, @@ -222,7 +222,7 @@ begin "command": { "command": "indent", "indentContents": { - "id": 79, + "id": 78, "kind": "list", "list": [ { @@ -232,44 +232,35 @@ begin "literal": false, "soft": false }, - "id": 78, + "id": 77, "kind": "command" }, { "command": { + "breakParents": true, "command": "alignmentTable", "elements": [ [ { - "command": { - "break": false, - "command": "group", - "expandedStates": null, - "groupContents": { - "id": 74, - "kind": "list", - "list": [ - { - "command": { - "command": "line", - "hard": true, - "literal": false, - "soft": false - }, - "id": 0, - "kind": "command" - }, - { - "id": 1, - "kind": "text", - "text": "A " - } - ] + "id": 74, + "kind": "list", + "list": [ + { + "command": { + "command": "line", + "hard": true, + "literal": false, + "soft": false + }, + "id": 0, + "kind": "command" }, - "id": 0 - }, - "id": 75, - "kind": "command" + { + "id": 1, + "kind": "text", + "text": "A " + } + ] }, { "command": { @@ -817,13 +808,13 @@ begin ] ] }, - "id": 76, + "id": 75, "kind": "command" } ] } }, - "id": 80, + "id": 79, "kind": "command" }, { @@ -833,11 +824,11 @@ begin "literal": false, "soft": false }, - "id": 81, + "id": 80, "kind": "command" }, { - "id": 82, + "id": 81, "kind": "text", "text": "end record" } @@ -845,7 +836,7 @@ begin }, "id": 0 }, - "id": 84, + "id": 83, "kind": "command" } > Alignment_Table_1 Document Formatted: @@ -863,11 +854,11 @@ end record "command": "group", "expandedStates": null, "groupContents": { - "id": 168, + "id": 166, "kind": "list", "list": [ { - "id": 162, + "id": 160, "kind": "text", "text": "record" }, @@ -875,7 +866,7 @@ end record "command": { "command": "indent", "indentContents": { - "id": 164, + "id": 162, "kind": "list", "list": [ { @@ -885,44 +876,35 @@ end record "literal": false, "soft": false }, - "id": 163, + "id": 161, "kind": "command" }, { "command": { + "breakParents": true, "command": "alignmentTable", "elements": [ [ { - "command": { - "break": false, - "command": "group", - "expandedStates": null, - "groupContents": { - "id": 159, - "kind": "list", - "list": [ - { - "command": { - "command": "line", - "hard": true, - "literal": false, - "soft": false - }, - "id": 85, - "kind": "command" - }, - { - "id": 86, - "kind": "text", - "text": "A " - } - ] + "id": 158, + "kind": "list", + "list": [ + { + "command": { + "command": "line", + "hard": true, + "literal": false, + "soft": false + }, + "id": 84, + "kind": "command" }, - "id": 0 - }, - "id": 160, - "kind": "command" + { + "id": 85, + "kind": "text", + "text": "A " + } + ] }, { "command": { @@ -933,7 +915,7 @@ end record "command": { "command": "indent", "indentContents": { - "id": 90, + "id": 89, "kind": "list", "list": [ { @@ -943,23 +925,23 @@ end record "literal": false, "soft": false }, - "id": 88, + "id": 87, "kind": "command" }, { - "id": 89, + "id": 88, "kind": "text", "text": "B " } ] } }, - "id": 91, + "id": 90, "kind": "command" }, "id": 5 }, - "id": 92, + "id": 91, "kind": "command" }, { @@ -976,7 +958,7 @@ end record "command": "group", "expandedStates": null, "groupContents": { - "id": 97, + "id": 96, "kind": "list", "list": [ { @@ -986,16 +968,16 @@ end record "literal": false, "soft": false }, - "id": 94, + "id": 93, "kind": "command" }, { - "id": 95, + "id": 94, "kind": "text", "text": "C" }, { - "id": 96, + "id": 95, "kind": "text", "text": ";" } @@ -1003,15 +985,15 @@ end record }, "id": 0 }, - "id": 98, + "id": 97, "kind": "command" } }, - "id": 99, + "id": 98, "kind": "command" } }, - "id": 100, + "id": 99, "kind": "command" }, "command": "ifBreak", @@ -1024,7 +1006,7 @@ end record "command": "group", "expandedStates": null, "groupContents": { - "id": 104, + "id": 103, "kind": "list", "list": [ { @@ -1034,16 +1016,16 @@ end record "literal": false, "soft": false }, - "id": 101, + "id": 100, "kind": "command" }, { - "id": 102, + "id": 101, "kind": "text", "text": "C" }, { - "id": 103, + "id": 102, "kind": "text", "text": ";" } @@ -1051,22 +1033,22 @@ end record }, "id": 0 }, - "id": 105, + "id": 104, "kind": "command" } }, - "id": 106, + "id": 105, "kind": "command" }, "ifBreakGroupId": 5 }, - "id": 107, + "id": 106, "kind": "command" } ], [ { - "id": 108, + "id": 107, "kind": "text", "text": "AA " }, @@ -1079,7 +1061,7 @@ end record "command": { "command": "indent", "indentContents": { - "id": 112, + "id": 111, "kind": "list", "list": [ { @@ -1089,23 +1071,23 @@ end record "literal": false, "soft": false }, - "id": 110, + "id": 109, "kind": "command" }, { - "id": 111, + "id": 110, "kind": "text", "text": "BB " } ] } }, - "id": 113, + "id": 112, "kind": "command" }, "id": 6 }, - "id": 114, + "id": 113, "kind": "command" }, { @@ -1122,7 +1104,7 @@ end record "command": "group", "expandedStates": null, "groupContents": { - "id": 119, + "id": 118, "kind": "list", "list": [ { @@ -1132,16 +1114,16 @@ end record "literal": false, "soft": false }, - "id": 116, + "id": 115, "kind": "command" }, { - "id": 117, + "id": 116, "kind": "text", "text": "CC" }, { - "id": 118, + "id": 117, "kind": "text", "text": ";" } @@ -1149,15 +1131,15 @@ end record }, "id": 0 }, - "id": 120, + "id": 119, "kind": "command" } }, - "id": 121, + "id": 120, "kind": "command" } }, - "id": 122, + "id": 121, "kind": "command" }, "command": "ifBreak", @@ -1170,7 +1152,7 @@ end record "command": "group", "expandedStates": null, "groupContents": { - "id": 126, + "id": 125, "kind": "list", "list": [ { @@ -1180,16 +1162,16 @@ end record "literal": false, "soft": false }, - "id": 123, + "id": 122, "kind": "command" }, { - "id": 124, + "id": 123, "kind": "text", "text": "CC" }, { - "id": 125, + "id": 124, "kind": "text", "text": ";" } @@ -1197,22 +1179,22 @@ end record }, "id": 0 }, - "id": 127, + "id": 126, "kind": "command" } }, - "id": 128, + "id": 127, "kind": "command" }, "ifBreakGroupId": 6 }, - "id": 129, + "id": 128, "kind": "command" } ], [ { - "id": 130, + "id": 129, "kind": "text", "text": "AAA " }, @@ -1225,7 +1207,7 @@ end record "command": { "command": "indent", "indentContents": { - "id": 134, + "id": 133, "kind": "list", "list": [ { @@ -1235,29 +1217,29 @@ end record "literal": false, "soft": false }, - "id": 132, + "id": 131, "kind": "command" }, { - "id": 133, + "id": 132, "kind": "text", "text": "BBBBBBBBB;" } ] } }, - "id": 135, + "id": 134, "kind": "command" }, "id": 7 }, - "id": 136, + "id": 135, "kind": "command" } ], [ { - "id": 137, + "id": 136, "kind": "text", "text": "AAAA " }, @@ -1270,7 +1252,7 @@ end record "command": { "command": "indent", "indentContents": { - "id": 141, + "id": 140, "kind": "list", "list": [ { @@ -1280,23 +1262,23 @@ end record "literal": false, "soft": false }, - "id": 139, + "id": 138, "kind": "command" }, { - "id": 140, + "id": 139, "kind": "text", "text": "BBBB " } ] } }, - "id": 142, + "id": 141, "kind": "command" }, "id": 8 }, - "id": 143, + "id": 142, "kind": "command" }, { @@ -1313,7 +1295,7 @@ end record "command": "group", "expandedStates": null, "groupContents": { - "id": 148, + "id": 147, "kind": "list", "list": [ { @@ -1323,16 +1305,16 @@ end record "literal": false, "soft": false }, - "id": 145, + "id": 144, "kind": "command" }, { - "id": 146, + "id": 145, "kind": "text", "text": "CCCC" }, { - "id": 147, + "id": 146, "kind": "text", "text": ";" } @@ -1340,15 +1322,15 @@ end record }, "id": 0 }, - "id": 149, + "id": 148, "kind": "command" } }, - "id": 150, + "id": 149, "kind": "command" } }, - "id": 151, + "id": 150, "kind": "command" }, "command": "ifBreak", @@ -1361,7 +1343,7 @@ end record "command": "group", "expandedStates": null, "groupContents": { - "id": 155, + "id": 154, "kind": "list", "list": [ { @@ -1371,16 +1353,16 @@ end record "literal": false, "soft": false }, - "id": 152, + "id": 151, "kind": "command" }, { - "id": 153, + "id": 152, "kind": "text", "text": "CCCC" }, { - "id": 154, + "id": 153, "kind": "text", "text": ";" } @@ -1388,16 +1370,16 @@ end record }, "id": 0 }, - "id": 156, + "id": 155, "kind": "command" } }, - "id": 157, + "id": 156, "kind": "command" }, "ifBreakGroupId": 8 }, - "id": 158, + "id": 157, "kind": "command" } ] @@ -1410,7 +1392,7 @@ end record "command": "alignmentTableSeparator", "text": ":" }, - "id": 87, + "id": 86, "kind": "command" }, { @@ -1418,7 +1400,7 @@ end record "command": "alignmentTableSeparator", "text": ":=" }, - "id": 93, + "id": 92, "kind": "command" } ], @@ -1428,7 +1410,7 @@ end record "command": "alignmentTableSeparator", "text": ":" }, - "id": 109, + "id": 108, "kind": "command" }, { @@ -1436,7 +1418,7 @@ end record "command": "alignmentTableSeparator", "text": ":=" }, - "id": 115, + "id": 114, "kind": "command" } ], @@ -1446,7 +1428,7 @@ end record "command": "alignmentTableSeparator", "text": ":" }, - "id": 131, + "id": 130, "kind": "command" } ], @@ -1456,7 +1438,7 @@ end record "command": "alignmentTableSeparator", "text": ":" }, - "id": 138, + "id": 137, "kind": "command" }, { @@ -1464,19 +1446,19 @@ end record "command": "alignmentTableSeparator", "text": ":=" }, - "id": 144, + "id": 143, "kind": "command" } ] ] }, - "id": 161, + "id": 159, "kind": "command" } ] } }, - "id": 165, + "id": 163, "kind": "command" }, { @@ -1486,11 +1468,11 @@ end record "literal": false, "soft": false }, - "id": 166, + "id": 164, "kind": "command" }, { - "id": 167, + "id": 165, "kind": "text", "text": "end record" } @@ -1498,7 +1480,7 @@ end record }, "id": 0 }, - "id": 169, + "id": 167, "kind": "command" } > Alignment_Table_2 Document Formatted: @@ -1524,11 +1506,12 @@ end record "expandedStates": null, "groupContents": { "command": { + "breakParents": true, "command": "alignmentTable", "elements": [ [ { - "id": 170, + "id": 168, "kind": "text", "text": "with Prettier_Ada.Documents;" }, @@ -1538,7 +1521,7 @@ end record "command": "group", "expandedStates": null, "groupContents": { - "id": 176, + "id": 174, "kind": "list", "list": [ { @@ -1548,11 +1531,11 @@ end record "literal": false, "soft": false }, - "id": 174, + "id": 172, "kind": "command" }, { - "id": 175, + "id": 173, "kind": "text", "text": "use Prettier_Ada.Documents;" } @@ -1560,13 +1543,13 @@ end record }, "id": 0 }, - "id": 177, + "id": 175, "kind": "command" } ], [ { - "id": 178, + "id": 176, "kind": "text", "text": "with Prettier_Ada.Documents.Builders;" }, @@ -1576,7 +1559,7 @@ end record "command": "group", "expandedStates": null, "groupContents": { - "id": 183, + "id": 181, "kind": "list", "list": [ { @@ -1586,11 +1569,11 @@ end record "literal": false, "soft": false }, - "id": 181, + "id": 179, "kind": "command" }, { - "id": 182, + "id": 180, "kind": "text", "text": "use Prettier_Ada.Documents;" } @@ -1598,7 +1581,7 @@ end record }, "id": 0 }, - "id": 184, + "id": 182, "kind": "command" } ] @@ -1611,7 +1594,7 @@ end record "command": "alignmentTableSeparator", "text": "" }, - "id": 171, + "id": 169, "kind": "command" } ], @@ -1621,18 +1604,18 @@ end record "command": "alignmentTableSeparator", "text": "" }, - "id": 179, + "id": 177, "kind": "command" } ] ] }, - "id": 185, + "id": 183, "kind": "command" }, "id": 0 }, - "id": 186, + "id": 184, "kind": "command" } > Alignment_Table_3 Document Formatted: diff --git a/testsuite/tests/table_alignment/doc.json b/testsuite/tests/table_alignment/doc.json index 5bba1e1..57d87bf 100644 --- a/testsuite/tests/table_alignment/doc.json +++ b/testsuite/tests/table_alignment/doc.json @@ -16,6 +16,7 @@ "command": { "alignContents": { "command": { + "breakParents": false, "command": "alignmentTable", "elements": [ [ diff --git a/testsuite/tests/table_break_propagation/must_break_false/doc.json b/testsuite/tests/table_break_propagation/must_break_false/doc.json new file mode 100644 index 0000000..86cf70d --- /dev/null +++ b/testsuite/tests/table_break_propagation/must_break_false/doc.json @@ -0,0 +1,164 @@ +{ + "command": { + "break": false, + "command": "group", + "expandedStates": null, + "groupContents": { + "command": { + "breakParents": false, + "command": "alignmentTable", + "elements": [ + [ + { + "id": 54, + "kind": "list", + "list": [ + { + "id": 38, + "kind": "text", + "text": "A" + }, + { + "command": { + "command": "line", + "hard": false, + "literal": false, + "soft": false + }, + "id": 39, + "kind": "command" + }, + { + "id": 40, + "kind": "text", + "text": "B" + } + ] + }, + { + "id": 55, + "kind": "list", + "list": [ + { + "id": 42, + "kind": "text", + "text": "C" + }, + { + "command": { + "command": "line", + "hard": false, + "literal": false, + "soft": false + }, + "id": 43, + "kind": "command" + }, + { + "id": 44, + "kind": "text", + "text": "D" + } + ] + } + ], + [ + { + "id": 56, + "kind": "list", + "list": [ + { + "id": 45, + "kind": "text", + "text": "A" + }, + { + "id": 48, + "kind": "list", + "list": [ + { + "command": { + "command": "line", + "hard": true, + "literal": false, + "soft": false + }, + "id": 46, + "kind": "command" + }, + { + "command": { + "command": "breakParent" + }, + "id": 47, + "kind": "command" + } + ] + }, + { + "id": 49, + "kind": "text", + "text": "BB" + } + ] + }, + { + "id": 57, + "kind": "list", + "list": [ + { + "id": 51, + "kind": "text", + "text": "C" + }, + { + "command": { + "command": "line", + "hard": false, + "literal": false, + "soft": false + }, + "id": 52, + "kind": "command" + }, + { + "id": 53, + "kind": "text", + "text": "D" + } + ] + } + ] + ], + "mustBreak": false, + "separators": [ + [ + { + "command": { + "command": "alignmentTableSeparator", + "text": "" + }, + "id": 41, + "kind": "command" + } + ], + [ + { + "command": { + "command": "alignmentTableSeparator", + "text": "" + }, + "id": 50, + "kind": "command" + } + ] + ] + }, + "id": 58, + "kind": "command" + }, + "id": 0 + }, + "id": 59, + "kind": "command" +} diff --git a/testsuite/tests/table_break_propagation/must_break_false/test.out b/testsuite/tests/table_break_propagation/must_break_false/test.out new file mode 100644 index 0000000..0786c16 --- /dev/null +++ b/testsuite/tests/table_break_propagation/must_break_false/test.out @@ -0,0 +1,6 @@ +A +B C +D +A +BBC +D diff --git a/testsuite/tests/table_break_propagation/must_break_false/test.yaml b/testsuite/tests/table_break_propagation/must_break_false/test.yaml new file mode 100644 index 0000000..53a2e97 --- /dev/null +++ b/testsuite/tests/table_break_propagation/must_break_false/test.yaml @@ -0,0 +1,4 @@ +title: Table_Alignment Must_Break propagation +driver: document_formatter +description: | + Test that Hardlines inside Aligment_Tables propagate to the whole table. diff --git a/testsuite/tests/table_break_propagation/must_break_true/doc.json b/testsuite/tests/table_break_propagation/must_break_true/doc.json new file mode 100644 index 0000000..f8b8fec --- /dev/null +++ b/testsuite/tests/table_break_propagation/must_break_true/doc.json @@ -0,0 +1,157 @@ +{ + "command": { + "break": false, + "command": "group", + "expandedStates": null, + "groupContents": { + "command": { + "breakParents": true, + "command": "alignmentTable", + "elements": [ + [ + { + "id": 19, + "kind": "text", + "text": "with GNATCOLL.Traces;" + }, + { + "id": 35, + "kind": "list", + "list": [ + { + "command": { + "command": "line", + "hard": false, + "literal": false, + "soft": false + }, + "id": 21, + "kind": "command" + }, + { + "id": 22, + "kind": "text", + "text": "use GNATCOLL.Traces;" + } + ] + } + ], + [ + { + "id": 23, + "kind": "text", + "text": "with Prettier_Ada.Documents;" + }, + { + "command": { + "break": false, + "command": "group", + "expandedStates": null, + "groupContents": { + "id": 27, + "kind": "list", + "list": [ + { + "command": { + "command": "line", + "hard": false, + "literal": false, + "soft": false + }, + "id": 25, + "kind": "command" + }, + { + "id": 26, + "kind": "text", + "text": "use Prettier_Ada.Documents;" + } + ] + }, + "id": 0 + }, + "id": 28, + "kind": "command" + } + ], + [ + { + "id": 29, + "kind": "text", + "text": "with Prettier_Ada.Documents.Builders;" + }, + { + "command": { + "break": false, + "command": "group", + "expandedStates": null, + "groupContents": { + "id": 33, + "kind": "list", + "list": [ + { + "command": { + "command": "line", + "hard": false, + "literal": false, + "soft": false + }, + "id": 31, + "kind": "command" + }, + { + "id": 32, + "kind": "text", + "text": "use Prettier_Ada.Documents.Builders;" + } + ] + }, + "id": 0 + }, + "id": 34, + "kind": "command" + } + ] + ], + "mustBreak": true, + "separators": [ + [ + { + "command": { + "command": "alignmentTableSeparator", + "text": "" + }, + "id": 20, + "kind": "command" + } + ], + [ + { + "command": { + "command": "alignmentTableSeparator", + "text": "" + }, + "id": 24, + "kind": "command" + } + ], + [ + { + "command": { + "command": "alignmentTableSeparator", + "text": "" + }, + "id": 30, + "kind": "command" + } + ] + ] + }, + "id": 36, + "kind": "command" + }, + "id": 0 + }, + "id": 37, + "kind": "command" +} diff --git a/testsuite/tests/table_break_propagation/must_break_true/test.out b/testsuite/tests/table_break_propagation/must_break_true/test.out new file mode 100644 index 0000000..6aadf5f --- /dev/null +++ b/testsuite/tests/table_break_propagation/must_break_true/test.out @@ -0,0 +1,4 @@ +with GNATCOLL.Traces; +use GNATCOLL.Traces; +with Prettier_Ada.Documents; use Prettier_Ada.Documents; +with Prettier_Ada.Documents.Builders; use Prettier_Ada.Documents.Builders; diff --git a/testsuite/tests/table_break_propagation/must_break_true/test.yaml b/testsuite/tests/table_break_propagation/must_break_true/test.yaml new file mode 100644 index 0000000..c9fb497 --- /dev/null +++ b/testsuite/tests/table_break_propagation/must_break_true/test.yaml @@ -0,0 +1,4 @@ +title: Table_Alignment Must_Break propagation +driver: document_formatter +description: | + Test that Aligment_Table Must_Break propagates to rows.