From 2382f783c5d2ac889f3d9e8ecdd16248c83b4772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Azevedo?= Date: Tue, 20 Feb 2024 13:30:39 +0000 Subject: [PATCH] Unparsing: add ElsifStmtPart and IfStmt configs --- extensions/default_unparsing_config.json | 156 ++++++- .../if_stmt/complete/doc-baseline.json | 402 +++++++++++++++++ .../unparsing/if_stmt/complete/input.ada | 1 + .../tests/unparsing/if_stmt/complete/test.out | 9 + .../unparsing/if_stmt/complete/test.yaml | 5 + .../long_elsif_cond_expr/doc-baseline.json | 405 ++++++++++++++++++ .../if_stmt/long_elsif_cond_expr/input.ada | 1 + .../if_stmt/long_elsif_cond_expr/test.out | 10 + .../if_stmt/long_elsif_cond_expr/test.yaml | 5 + .../if_stmt/long_if/doc-baseline.json | 173 ++++++++ .../tests/unparsing/if_stmt/long_if/input.ada | 1 + .../tests/unparsing/if_stmt/long_if/test.out | 4 + .../tests/unparsing/if_stmt/long_if/test.yaml | 5 + .../long_if_cond_expr/doc-baseline.json | 173 ++++++++ .../if_stmt/long_if_cond_expr/input.ada | 2 + .../if_stmt/long_if_cond_expr/test.out | 5 + .../if_stmt/long_if_cond_expr/test.yaml | 6 + 17 files changed, 1349 insertions(+), 14 deletions(-) create mode 100644 testsuite/tests/unparsing/if_stmt/complete/doc-baseline.json create mode 100644 testsuite/tests/unparsing/if_stmt/complete/input.ada create mode 100644 testsuite/tests/unparsing/if_stmt/complete/test.out create mode 100644 testsuite/tests/unparsing/if_stmt/complete/test.yaml create mode 100644 testsuite/tests/unparsing/if_stmt/long_elsif_cond_expr/doc-baseline.json create mode 100644 testsuite/tests/unparsing/if_stmt/long_elsif_cond_expr/input.ada create mode 100644 testsuite/tests/unparsing/if_stmt/long_elsif_cond_expr/test.out create mode 100644 testsuite/tests/unparsing/if_stmt/long_elsif_cond_expr/test.yaml create mode 100644 testsuite/tests/unparsing/if_stmt/long_if/doc-baseline.json create mode 100644 testsuite/tests/unparsing/if_stmt/long_if/input.ada create mode 100644 testsuite/tests/unparsing/if_stmt/long_if/test.out create mode 100644 testsuite/tests/unparsing/if_stmt/long_if/test.yaml create mode 100644 testsuite/tests/unparsing/if_stmt/long_if_cond_expr/doc-baseline.json create mode 100644 testsuite/tests/unparsing/if_stmt/long_if_cond_expr/input.ada create mode 100644 testsuite/tests/unparsing/if_stmt/long_if_cond_expr/test.out create mode 100644 testsuite/tests/unparsing/if_stmt/long_if_cond_expr/test.yaml diff --git a/extensions/default_unparsing_config.json b/extensions/default_unparsing_config.json index 480a7df73..d88cd00ca 100644 --- a/extensions/default_unparsing_config.json +++ b/extensions/default_unparsing_config.json @@ -179,7 +179,7 @@ { "kind": "text", "text": "is" - }, + }, "line", { "kind": "recurse_field", @@ -195,7 +195,7 @@ } ] } - } + } }, "DecimalFixedPointDef":{ "node": { @@ -205,7 +205,7 @@ "kind": "text", "text": "delta" }, - "whitespace", + "whitespace", { "kind": "recurse_field", "field": "f_delta" @@ -215,7 +215,7 @@ "kind": "text", "text": "digits" }, - "whitespace", + "whitespace", { "kind": "recurse_field", "field": "f_digits" @@ -233,9 +233,9 @@ "kind": "innerRoot", "contents": "recurse" } - ] + ] } - }, + }, "DottedName": { "node": { "kind": "innerRoot", @@ -282,7 +282,57 @@ "text": ")" } ] - } + } + }, + "ElsifStmtPart": { + "node": { + "kind": "group", + "document": [ + { + "kind": "group", + "document": [ + { + "kind": "text", + "text": "elsif" + }, + "whitespace", + { + "kind": "align", + "width": 2, + "contents": { + "kind": "group", + "document": { + "kind": "recurse_field", + "field": "f_cond_expr" + } + } + }, + "line", + { + "kind": "text", + "text": "then" + } + ] + }, + { + "kind": "indent", + "contents": [ + "hardlineWithoutBreakParent", + { + "kind": "recurse_field", + "field": "f_stmts" + } + ] + }, + "hardlineWithoutBreakParent" + ] + } + }, + "ElsifExprPartList": { + "sep": [ + "recurse", + "hardlineWithoutBreakParent" + ] }, "FloatingPointDef":{ "node": { @@ -292,7 +342,7 @@ "kind": "text", "text": "digits" }, - "whitespace", + "whitespace", { "kind": "recurse_field", "field": "f_num_digits" @@ -310,8 +360,86 @@ "kind": "innerRoot", "contents": "recurse" } - ] - } + ] + } + }, + "IfStmt": { + "node": { + "kind": "group", + "document": [ + { + "kind": "group", + "document": [ + { + "kind": "text", + "text": "if" + }, + "whitespace", + { + "kind": "align", + "width": 2, + "contents": { + "kind": "recurse_field", + "field": "f_cond_expr" + } + }, + "line", + { + "kind": "text", + "text": "then" + } + ] + }, + { + "kind": "indent", + "contents": [ + "hardlineWithoutBreakParent", + { + "kind": "recurse_field", + "field": "f_then_stmts" + } + ] + }, + "hardlineWithoutBreakParent", + { + "kind": "recurse_field", + "field": "f_alternatives" + }, + { + "kind": "recurse_field", + "field": "f_else_stmts" + }, + { + "kind": "text", + "text": "end" + }, + "whitespace", + { + "kind": "text", + "text": "if" + }, + { + "kind": "text", + "text": ";" + } + ] + }, + "fields": { + "f_alternatives": { + "kind": "group", + "document": "recurse" + }, + "f_else_stmts": [ + { + "kind": "indent", + "contents": [ + "hardlineWithoutBreakParent", + "recurse" + ] + }, + "hardlineWithoutBreakParent" + ] + } }, "NameList":{ "sep":["recurse", "line"] @@ -324,7 +452,7 @@ "kind": "text", "text": "delta" }, - "whitespace", + "whitespace", { "kind": "recurse_field", "field": "f_delta" @@ -338,7 +466,7 @@ } } ] - } + } }, "PackageBody": { "node": [ @@ -532,7 +660,7 @@ } ] } - } + } }, "ReturnStmt": { "node": { @@ -554,7 +682,7 @@ "node": { "kind": "recurse_field", "field": "f_range" - } + } }, "UsePackageClause": { "node": { diff --git a/testsuite/tests/unparsing/if_stmt/complete/doc-baseline.json b/testsuite/tests/unparsing/if_stmt/complete/doc-baseline.json new file mode 100644 index 000000000..6735e9c3f --- /dev/null +++ b/testsuite/tests/unparsing/if_stmt/complete/doc-baseline.json @@ -0,0 +1,402 @@ +{ + "id": 52, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 51, + "kind": "list", + "list": [ + { + "id": 6, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 5, + "kind": "list", + "list": [ + { + "id": 0, + "kind": "text", + "text": "if " + }, + { + "id": 2, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "width", + "n": 2 + }, + "alignContents": { + "id": 1, + "kind": "text", + "text": "Foo" + } + } + }, + { + "id": 3, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 4, + "kind": "text", + "text": "then" + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 10, + "kind": "command", + "command": { + "command": "indent", + "indentContents": { + "id": 9, + "kind": "list", + "list": [ + { + "id": 7, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": true + } + }, + { + "id": 8, + "kind": "text", + "text": "null;" + } + ] + } + } + }, + { + "id": 11, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": true + } + }, + { + "id": 43, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 42, + "kind": "list", + "list": [ + { + "id": 26, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 25, + "kind": "list", + "list": [ + { + "id": 19, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 18, + "kind": "list", + "list": [ + { + "id": 12, + "kind": "text", + "text": "elsif " + }, + { + "id": 15, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "width", + "n": 2 + }, + "alignContents": { + "id": 14, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 13, + "kind": "text", + "text": "Bar" + }, + "break": false, + "expandedStates": null + } + } + } + }, + { + "id": 16, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 17, + "kind": "text", + "text": "then" + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 23, + "kind": "command", + "command": { + "command": "indent", + "indentContents": { + "id": 22, + "kind": "list", + "list": [ + { + "id": 20, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": true + } + }, + { + "id": 21, + "kind": "text", + "text": "null;" + } + ] + } + } + }, + { + "id": 24, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": true + } + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 41, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 40, + "kind": "list", + "list": [ + { + "id": 34, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 33, + "kind": "list", + "list": [ + { + "id": 27, + "kind": "text", + "text": "elsif " + }, + { + "id": 30, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "width", + "n": 2 + }, + "alignContents": { + "id": 29, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 28, + "kind": "text", + "text": "Baz" + }, + "break": false, + "expandedStates": null + } + } + } + }, + { + "id": 31, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 32, + "kind": "text", + "text": "then" + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 38, + "kind": "command", + "command": { + "command": "indent", + "indentContents": { + "id": 37, + "kind": "list", + "list": [ + { + "id": 35, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": true + } + }, + { + "id": 36, + "kind": "text", + "text": "null;" + } + ] + } + } + }, + { + "id": 39, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": true + } + } + ] + }, + "break": false, + "expandedStates": null + } + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 44, + "kind": "text", + "text": "else" + }, + { + "id": 48, + "kind": "command", + "command": { + "command": "indent", + "indentContents": { + "id": 47, + "kind": "list", + "list": [ + { + "id": 45, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": true + } + }, + { + "id": 46, + "kind": "text", + "text": "null;" + } + ] + } + } + }, + { + "id": 49, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": true + } + }, + { + "id": 50, + "kind": "text", + "text": "end if;" + } + ] + }, + "break": false, + "expandedStates": null + } +} diff --git a/testsuite/tests/unparsing/if_stmt/complete/input.ada b/testsuite/tests/unparsing/if_stmt/complete/input.ada new file mode 100644 index 000000000..5a24477c6 --- /dev/null +++ b/testsuite/tests/unparsing/if_stmt/complete/input.ada @@ -0,0 +1 @@ +if Foo then null; elsif Bar then null; elsif Baz then null; else null; end if; diff --git a/testsuite/tests/unparsing/if_stmt/complete/test.out b/testsuite/tests/unparsing/if_stmt/complete/test.out new file mode 100644 index 000000000..f73d85d43 --- /dev/null +++ b/testsuite/tests/unparsing/if_stmt/complete/test.out @@ -0,0 +1,9 @@ +if Foo then + null; +elsif Bar then + null; +elsif Baz then + null; +else + null; +end if; diff --git a/testsuite/tests/unparsing/if_stmt/complete/test.yaml b/testsuite/tests/unparsing/if_stmt/complete/test.yaml new file mode 100644 index 000000000..b4a8f625f --- /dev/null +++ b/testsuite/tests/unparsing/if_stmt/complete/test.yaml @@ -0,0 +1,5 @@ +driver: unparser +rule: stmt +description: | + Base test case for an `IfStmt`. The `if`, `elsif` and `else` are in + separate lines and their respective statements are indented. diff --git a/testsuite/tests/unparsing/if_stmt/long_elsif_cond_expr/doc-baseline.json b/testsuite/tests/unparsing/if_stmt/long_elsif_cond_expr/doc-baseline.json new file mode 100644 index 000000000..b06c8a667 --- /dev/null +++ b/testsuite/tests/unparsing/if_stmt/long_elsif_cond_expr/doc-baseline.json @@ -0,0 +1,405 @@ +{ + "id": 52, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 51, + "kind": "list", + "list": [ + { + "id": 6, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 5, + "kind": "list", + "list": [ + { + "id": 0, + "kind": "text", + "text": "if " + }, + { + "id": 2, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "width", + "n": 2 + }, + "alignContents": { + "id": 1, + "kind": "text", + "text": "Bar" + } + } + }, + { + "id": 3, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 4, + "kind": "text", + "text": "then" + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 10, + "kind": "command", + "command": { + "command": "indent", + "indentContents": { + "id": 9, + "kind": "list", + "list": [ + { + "id": 7, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": true + } + }, + { + "id": 8, + "kind": "text", + "text": "null;" + } + ] + } + } + }, + { + "id": 11, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": true + } + }, + { + "id": 49, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 48, + "kind": "list", + "list": [ + { + "id": 26, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 25, + "kind": "list", + "list": [ + { + "id": 19, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 18, + "kind": "list", + "list": [ + { + "id": 12, + "kind": "text", + "text": "elsif " + }, + { + "id": 15, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "width", + "n": 2 + }, + "alignContents": { + "id": 14, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 13, + "kind": "text", + "text": "Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar" + }, + "break": false, + "expandedStates": null + } + } + } + }, + { + "id": 16, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 17, + "kind": "text", + "text": "then" + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 23, + "kind": "command", + "command": { + "command": "indent", + "indentContents": { + "id": 22, + "kind": "list", + "list": [ + { + "id": 20, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": true + } + }, + { + "id": 21, + "kind": "text", + "text": "null;" + } + ] + } + } + }, + { + "id": 24, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": true + } + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 47, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 46, + "kind": "list", + "list": [ + { + "id": 40, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 39, + "kind": "list", + "list": [ + { + "id": 27, + "kind": "text", + "text": "elsif " + }, + { + "id": 36, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "width", + "n": 2 + }, + "alignContents": { + "id": 35, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 34, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 33, + "kind": "list", + "list": [ + { + "id": 28, + "kind": "text", + "text": "Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar" + }, + { + "id": 29, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 30, + "kind": "text", + "text": "and then " + }, + { + "id": 32, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 31, + "kind": "text", + "text": "Baz" + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + }, + "break": false, + "expandedStates": null + } + } + } + }, + { + "id": 37, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 38, + "kind": "text", + "text": "then" + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 44, + "kind": "command", + "command": { + "command": "indent", + "indentContents": { + "id": 43, + "kind": "list", + "list": [ + { + "id": 41, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": true + } + }, + { + "id": 42, + "kind": "text", + "text": "null;" + } + ] + } + } + }, + { + "id": 45, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": true + } + } + ] + }, + "break": false, + "expandedStates": null + } + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 50, + "kind": "text", + "text": "end if;" + } + ] + }, + "break": false, + "expandedStates": null + } +} diff --git a/testsuite/tests/unparsing/if_stmt/long_elsif_cond_expr/input.ada b/testsuite/tests/unparsing/if_stmt/long_elsif_cond_expr/input.ada new file mode 100644 index 000000000..dfd913c64 --- /dev/null +++ b/testsuite/tests/unparsing/if_stmt/long_elsif_cond_expr/input.ada @@ -0,0 +1 @@ +if Bar then null; elsif Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar then null; elsif Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar and then Baz then null; end if; diff --git a/testsuite/tests/unparsing/if_stmt/long_elsif_cond_expr/test.out b/testsuite/tests/unparsing/if_stmt/long_elsif_cond_expr/test.out new file mode 100644 index 000000000..32f12c796 --- /dev/null +++ b/testsuite/tests/unparsing/if_stmt/long_elsif_cond_expr/test.out @@ -0,0 +1,10 @@ +if Bar then + null; +elsif Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar +then + null; +elsif Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar + and then Baz +then + null; +end if; diff --git a/testsuite/tests/unparsing/if_stmt/long_elsif_cond_expr/test.yaml b/testsuite/tests/unparsing/if_stmt/long_elsif_cond_expr/test.yaml new file mode 100644 index 000000000..8f806e696 --- /dev/null +++ b/testsuite/tests/unparsing/if_stmt/long_elsif_cond_expr/test.yaml @@ -0,0 +1,5 @@ +driver: unparser +rule: stmt +description: | + Test that long `ElsifStmtPart` first break before the `then` keyword and then + the underlying `f_cond_expr` field. diff --git a/testsuite/tests/unparsing/if_stmt/long_if/doc-baseline.json b/testsuite/tests/unparsing/if_stmt/long_if/doc-baseline.json new file mode 100644 index 000000000..421063133 --- /dev/null +++ b/testsuite/tests/unparsing/if_stmt/long_if/doc-baseline.json @@ -0,0 +1,173 @@ +{ + "id": 22, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 21, + "kind": "list", + "list": [ + { + "id": 12, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 11, + "kind": "list", + "list": [ + { + "id": 0, + "kind": "text", + "text": "if " + }, + { + "id": 8, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "width", + "n": 2 + }, + "alignContents": { + "id": 7, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 6, + "kind": "list", + "list": [ + { + "id": 1, + "kind": "text", + "text": "Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar" + }, + { + "id": 2, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 3, + "kind": "text", + "text": "and then " + }, + { + "id": 5, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 4, + "kind": "text", + "text": "Qux" + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + } + } + }, + { + "id": 9, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 10, + "kind": "text", + "text": "then" + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 16, + "kind": "command", + "command": { + "command": "indent", + "indentContents": { + "id": 15, + "kind": "list", + "list": [ + { + "id": 13, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": true + } + }, + { + "id": 14, + "kind": "text", + "text": "null;" + } + ] + } + } + }, + { + "id": 17, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": true + } + }, + { + "id": 19, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 18, + "kind": "list", + "list": [ + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 20, + "kind": "text", + "text": "end if;" + } + ] + }, + "break": false, + "expandedStates": null + } +} diff --git a/testsuite/tests/unparsing/if_stmt/long_if/input.ada b/testsuite/tests/unparsing/if_stmt/long_if/input.ada new file mode 100644 index 000000000..2cfffcd84 --- /dev/null +++ b/testsuite/tests/unparsing/if_stmt/long_if/input.ada @@ -0,0 +1 @@ +if Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar and then Qux then null; end if; diff --git a/testsuite/tests/unparsing/if_stmt/long_if/test.out b/testsuite/tests/unparsing/if_stmt/long_if/test.out new file mode 100644 index 000000000..ac99752bc --- /dev/null +++ b/testsuite/tests/unparsing/if_stmt/long_if/test.out @@ -0,0 +1,4 @@ +if Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar and then Qux +then + null; +end if; diff --git a/testsuite/tests/unparsing/if_stmt/long_if/test.yaml b/testsuite/tests/unparsing/if_stmt/long_if/test.yaml new file mode 100644 index 000000000..f3d45fe1d --- /dev/null +++ b/testsuite/tests/unparsing/if_stmt/long_if/test.yaml @@ -0,0 +1,5 @@ +driver: unparser +rule: stmt +description: | + Test that if the `f_cond_expr` field of an `IfStmt` is long, the `IfStmt` + first breaks before the `then` keyword. diff --git a/testsuite/tests/unparsing/if_stmt/long_if_cond_expr/doc-baseline.json b/testsuite/tests/unparsing/if_stmt/long_if_cond_expr/doc-baseline.json new file mode 100644 index 000000000..50ebc2cff --- /dev/null +++ b/testsuite/tests/unparsing/if_stmt/long_if_cond_expr/doc-baseline.json @@ -0,0 +1,173 @@ +{ + "id": 22, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 21, + "kind": "list", + "list": [ + { + "id": 12, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 11, + "kind": "list", + "list": [ + { + "id": 0, + "kind": "text", + "text": "if " + }, + { + "id": 8, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "width", + "n": 2 + }, + "alignContents": { + "id": 7, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 6, + "kind": "list", + "list": [ + { + "id": 1, + "kind": "text", + "text": "Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar" + }, + { + "id": 2, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 3, + "kind": "text", + "text": "and then " + }, + { + "id": 5, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 4, + "kind": "text", + "text": "Qux" + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + } + } + }, + { + "id": 9, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 10, + "kind": "text", + "text": "then" + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 16, + "kind": "command", + "command": { + "command": "indent", + "indentContents": { + "id": 15, + "kind": "list", + "list": [ + { + "id": 13, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": true + } + }, + { + "id": 14, + "kind": "text", + "text": "null;" + } + ] + } + } + }, + { + "id": 17, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": true + } + }, + { + "id": 19, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 18, + "kind": "list", + "list": [ + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 20, + "kind": "text", + "text": "end if;" + } + ] + }, + "break": false, + "expandedStates": null + } +} \ No newline at end of file diff --git a/testsuite/tests/unparsing/if_stmt/long_if_cond_expr/input.ada b/testsuite/tests/unparsing/if_stmt/long_if_cond_expr/input.ada new file mode 100644 index 000000000..4d273f09b --- /dev/null +++ b/testsuite/tests/unparsing/if_stmt/long_if_cond_expr/input.ada @@ -0,0 +1,2 @@ +if Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar and then Qux then null; end if; + diff --git a/testsuite/tests/unparsing/if_stmt/long_if_cond_expr/test.out b/testsuite/tests/unparsing/if_stmt/long_if_cond_expr/test.out new file mode 100644 index 000000000..f4faad51f --- /dev/null +++ b/testsuite/tests/unparsing/if_stmt/long_if_cond_expr/test.out @@ -0,0 +1,5 @@ +if Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar + and then Qux +then + null; +end if; diff --git a/testsuite/tests/unparsing/if_stmt/long_if_cond_expr/test.yaml b/testsuite/tests/unparsing/if_stmt/long_if_cond_expr/test.yaml new file mode 100644 index 000000000..70cd20fa1 --- /dev/null +++ b/testsuite/tests/unparsing/if_stmt/long_if_cond_expr/test.yaml @@ -0,0 +1,6 @@ +driver: unparser +rule: stmt +description: | + Test that if the `f_cond_expr` field of an `IfStmt` is long, the `IfStmt` + first breaks before the `then` keyword and then in underlying `f_cond_expr` + field.