From 2ca9b06bfc91c84f4bfe7e848f6d01d522789709 Mon Sep 17 00:00:00 2001 From: Monika Kurovszky Date: Wed, 17 Apr 2024 16:26:27 +0200 Subject: [PATCH 1/3] Adding ContractCases, ContractCaseAssoc and ContractCaseAssocList configs --- extensions/default_unparsing_config.json | 60 ++ .../contract_cases/long/doc-baseline.json | 538 ++++++++++++++++++ .../unparsing/contract_cases/long/input.ada | 2 + .../unparsing/contract_cases/long/test.out | 2 + .../unparsing/contract_cases/long/test.yaml | 8 + .../contract_cases/short/doc-baseline.json | 538 ++++++++++++++++++ .../unparsing/contract_cases/short/input.ada | 1 + .../unparsing/contract_cases/short/test.out | 1 + .../unparsing/contract_cases/short/test.yaml | 6 + .../contract_cases/special/doc-baseline.json | 538 ++++++++++++++++++ .../contract_cases/special/input.ada | 2 + .../unparsing/contract_cases/special/test.out | 3 + .../contract_cases/special/test.yaml | 9 + 13 files changed, 1708 insertions(+) create mode 100644 testsuite/tests/unparsing/contract_cases/long/doc-baseline.json create mode 100644 testsuite/tests/unparsing/contract_cases/long/input.ada create mode 100644 testsuite/tests/unparsing/contract_cases/long/test.out create mode 100644 testsuite/tests/unparsing/contract_cases/long/test.yaml create mode 100644 testsuite/tests/unparsing/contract_cases/short/doc-baseline.json create mode 100644 testsuite/tests/unparsing/contract_cases/short/input.ada create mode 100644 testsuite/tests/unparsing/contract_cases/short/test.out create mode 100644 testsuite/tests/unparsing/contract_cases/short/test.yaml create mode 100644 testsuite/tests/unparsing/contract_cases/special/doc-baseline.json create mode 100644 testsuite/tests/unparsing/contract_cases/special/input.ada create mode 100644 testsuite/tests/unparsing/contract_cases/special/test.out create mode 100644 testsuite/tests/unparsing/contract_cases/special/test.yaml diff --git a/extensions/default_unparsing_config.json b/extensions/default_unparsing_config.json index 0a0f79067..2c3989f1f 100644 --- a/extensions/default_unparsing_config.json +++ b/extensions/default_unparsing_config.json @@ -426,6 +426,7 @@ "kind": "text", "text": "use" }, + "line", { "kind": "align", "width": 2, @@ -1106,6 +1107,65 @@ "line" ] }, + "ContractCases": { + "node": { + "kind": "group", + "document": { + "kind": "align", + "width": 1, + "contents": [ + { + "kind": "text", + "text": "(" + }, + { + "kind": "innerRoot", + "contents": { + "kind": "recurse_field", + "field": "f_contract_cases" + } + }, + { + "kind": "text", + "text": ")" + } + ] + } + } + }, + "ContractCaseAssoc": { + "node": { + "kind": "group", + "document": [ + { + "kind": "recurse_field", + "field": "f_guard" + }, + "whitespace", + { + "kind": "text", + "text": "=>" + }, + { + "kind": "align", + "width": 2, + "contents": [ + "line", + { + "kind": "recurse_field", + "field": "f_consequence" + } + ] + } + ] + } + }, + "ContractCaseAssocList": { + "sep": [ + "recurse", + "line" + ] + }, "ConcreteFormalSubpDecl": { "node": { "kind": "align", diff --git a/testsuite/tests/unparsing/contract_cases/long/doc-baseline.json b/testsuite/tests/unparsing/contract_cases/long/doc-baseline.json new file mode 100644 index 000000000..103204454 --- /dev/null +++ b/testsuite/tests/unparsing/contract_cases/long/doc-baseline.json @@ -0,0 +1,538 @@ +{ + "id": 70, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 69, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "width", + "n": 1 + }, + "alignContents": { + "id": 68, + "kind": "list", + "list": [ + { + "id": 0, + "kind": "text", + "text": "(" + }, + { + "id": 66, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 65, + "kind": "list", + "list": [ + { + "id": 34, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 33, + "kind": "list", + "list": [ + { + "id": 13, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 12, + "kind": "list", + "list": [ + { + "id": 7, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 6, + "kind": "list", + "list": [ + { + "id": 1, + "kind": "text", + "text": "X" + }, + { + "id": 2, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 3, + "kind": "text", + "text": "* " + }, + { + "id": 5, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 4, + "kind": "text", + "text": "Y" + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 8, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 9, + "kind": "text", + "text": "< " + }, + { + "id": 11, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 10, + "kind": "text", + "text": "10_000" + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 14, + "kind": "text", + "text": " =>" + }, + { + "id": 32, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "width", + "n": 2 + }, + "alignContents": { + "id": 31, + "kind": "list", + "list": [ + { + "id": 15, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 30, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 29, + "kind": "list", + "list": [ + { + "id": 18, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 17, + "kind": "list", + "list": [ + { + "id": 16, + "kind": "text", + "text": "Mult'Result" + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 19, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 20, + "kind": "text", + "text": "= " + }, + { + "id": 28, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 27, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 26, + "kind": "list", + "list": [ + { + "id": 21, + "kind": "text", + "text": "X" + }, + { + "id": 22, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 23, + "kind": "text", + "text": "* " + }, + { + "id": 25, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 24, + "kind": "text", + "text": "Y" + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + } + ] + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 35, + "kind": "text", + "text": "," + }, + { + "id": 36, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 64, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 63, + "kind": "list", + "list": [ + { + "id": 49, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 48, + "kind": "list", + "list": [ + { + "id": 43, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 42, + "kind": "list", + "list": [ + { + "id": 37, + "kind": "text", + "text": "X" + }, + { + "id": 38, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 39, + "kind": "text", + "text": "* " + }, + { + "id": 41, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 40, + "kind": "text", + "text": "Y" + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 44, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 45, + "kind": "text", + "text": ">= " + }, + { + "id": 47, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 46, + "kind": "text", + "text": "10_000" + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 50, + "kind": "text", + "text": " =>" + }, + { + "id": 62, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "width", + "n": 2 + }, + "alignContents": { + "id": 61, + "kind": "list", + "list": [ + { + "id": 51, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 60, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 59, + "kind": "list", + "list": [ + { + "id": 54, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 53, + "kind": "list", + "list": [ + { + "id": 52, + "kind": "text", + "text": "Mult'Result" + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 55, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 56, + "kind": "text", + "text": "= " + }, + { + "id": 58, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 57, + "kind": "text", + "text": "10_000" + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + } + ] + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + } + ] + } + } + }, + { + "id": 67, + "kind": "text", + "text": ")" + } + ] + } + } + }, + "break": false, + "expandedStates": null + } +} diff --git a/testsuite/tests/unparsing/contract_cases/long/input.ada b/testsuite/tests/unparsing/contract_cases/long/input.ada new file mode 100644 index 000000000..af9f0dd21 --- /dev/null +++ b/testsuite/tests/unparsing/contract_cases/long/input.ada @@ -0,0 +1,2 @@ +(X * Y < 10_000 => Mult'Result = X * Y, + X * Y >= 10_000 => Mult'Result = 10_000) diff --git a/testsuite/tests/unparsing/contract_cases/long/test.out b/testsuite/tests/unparsing/contract_cases/long/test.out new file mode 100644 index 000000000..715e70443 --- /dev/null +++ b/testsuite/tests/unparsing/contract_cases/long/test.out @@ -0,0 +1,2 @@ +(X * Y < 10_000 => Mult'Result = X * Y, + X * Y >= 10_000 => Mult'Result = 10_000) diff --git a/testsuite/tests/unparsing/contract_cases/long/test.yaml b/testsuite/tests/unparsing/contract_cases/long/test.yaml new file mode 100644 index 000000000..db9941701 --- /dev/null +++ b/testsuite/tests/unparsing/contract_cases/long/test.yaml @@ -0,0 +1,8 @@ +description: | + This test checks the formatting of contract cases expression. + It is expected the declaration breaks at the end of the first + contract case association and the new line is aligned relative + to the first association. + +driver: unparser +rule: contract_cases_expr diff --git a/testsuite/tests/unparsing/contract_cases/short/doc-baseline.json b/testsuite/tests/unparsing/contract_cases/short/doc-baseline.json new file mode 100644 index 000000000..c613361de --- /dev/null +++ b/testsuite/tests/unparsing/contract_cases/short/doc-baseline.json @@ -0,0 +1,538 @@ +{ + "id": 70, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 69, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "width", + "n": 1 + }, + "alignContents": { + "id": 68, + "kind": "list", + "list": [ + { + "id": 0, + "kind": "text", + "text": "(" + }, + { + "id": 66, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 65, + "kind": "list", + "list": [ + { + "id": 34, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 33, + "kind": "list", + "list": [ + { + "id": 13, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 12, + "kind": "list", + "list": [ + { + "id": 7, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 6, + "kind": "list", + "list": [ + { + "id": 1, + "kind": "text", + "text": "X" + }, + { + "id": 2, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 3, + "kind": "text", + "text": "+ " + }, + { + "id": 5, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 4, + "kind": "text", + "text": "Y" + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 8, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 9, + "kind": "text", + "text": "< " + }, + { + "id": 11, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 10, + "kind": "text", + "text": "10_000" + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 14, + "kind": "text", + "text": " =>" + }, + { + "id": 32, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "width", + "n": 2 + }, + "alignContents": { + "id": 31, + "kind": "list", + "list": [ + { + "id": 15, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 30, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 29, + "kind": "list", + "list": [ + { + "id": 18, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 17, + "kind": "list", + "list": [ + { + "id": 16, + "kind": "text", + "text": "Add'Result" + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 19, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 20, + "kind": "text", + "text": "= " + }, + { + "id": 28, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 27, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 26, + "kind": "list", + "list": [ + { + "id": 21, + "kind": "text", + "text": "X" + }, + { + "id": 22, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 23, + "kind": "text", + "text": "+ " + }, + { + "id": 25, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 24, + "kind": "text", + "text": "Y" + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + } + ] + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 35, + "kind": "text", + "text": "," + }, + { + "id": 36, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 64, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 63, + "kind": "list", + "list": [ + { + "id": 49, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 48, + "kind": "list", + "list": [ + { + "id": 43, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 42, + "kind": "list", + "list": [ + { + "id": 37, + "kind": "text", + "text": "X" + }, + { + "id": 38, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 39, + "kind": "text", + "text": "+ " + }, + { + "id": 41, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 40, + "kind": "text", + "text": "Y" + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 44, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 45, + "kind": "text", + "text": ">= " + }, + { + "id": 47, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 46, + "kind": "text", + "text": "10_000" + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 50, + "kind": "text", + "text": " =>" + }, + { + "id": 62, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "width", + "n": 2 + }, + "alignContents": { + "id": 61, + "kind": "list", + "list": [ + { + "id": 51, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 60, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 59, + "kind": "list", + "list": [ + { + "id": 54, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 53, + "kind": "list", + "list": [ + { + "id": 52, + "kind": "text", + "text": "Add'Result" + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 55, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 56, + "kind": "text", + "text": "= " + }, + { + "id": 58, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 57, + "kind": "text", + "text": "10_000" + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + } + ] + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + } + ] + } + } + }, + { + "id": 67, + "kind": "text", + "text": ")" + } + ] + } + } + }, + "break": false, + "expandedStates": null + } +} diff --git a/testsuite/tests/unparsing/contract_cases/short/input.ada b/testsuite/tests/unparsing/contract_cases/short/input.ada new file mode 100644 index 000000000..253e951ce --- /dev/null +++ b/testsuite/tests/unparsing/contract_cases/short/input.ada @@ -0,0 +1 @@ + (X + Y < 10_000 => Add'Result = X + Y, X + Y >= 10_000 => Add'Result = 10_000) diff --git a/testsuite/tests/unparsing/contract_cases/short/test.out b/testsuite/tests/unparsing/contract_cases/short/test.out new file mode 100644 index 000000000..1e68046d3 --- /dev/null +++ b/testsuite/tests/unparsing/contract_cases/short/test.out @@ -0,0 +1 @@ +(X + Y < 10_000 => Add'Result = X + Y, X + Y >= 10_000 => Add'Result = 10_000) diff --git a/testsuite/tests/unparsing/contract_cases/short/test.yaml b/testsuite/tests/unparsing/contract_cases/short/test.yaml new file mode 100644 index 000000000..e60e402ae --- /dev/null +++ b/testsuite/tests/unparsing/contract_cases/short/test.yaml @@ -0,0 +1,6 @@ +description: | + This test checks the formatting of contract cases expression. + It is expected the declaration stays on a single line. + +driver: unparser +rule: contract_cases_expr diff --git a/testsuite/tests/unparsing/contract_cases/special/doc-baseline.json b/testsuite/tests/unparsing/contract_cases/special/doc-baseline.json new file mode 100644 index 000000000..3a71bba2e --- /dev/null +++ b/testsuite/tests/unparsing/contract_cases/special/doc-baseline.json @@ -0,0 +1,538 @@ +{ + "id": 70, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 69, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "width", + "n": 1 + }, + "alignContents": { + "id": 68, + "kind": "list", + "list": [ + { + "id": 0, + "kind": "text", + "text": "(" + }, + { + "id": 66, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 65, + "kind": "list", + "list": [ + { + "id": 34, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 33, + "kind": "list", + "list": [ + { + "id": 13, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 12, + "kind": "list", + "list": [ + { + "id": 7, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 6, + "kind": "list", + "list": [ + { + "id": 1, + "kind": "text", + "text": "X" + }, + { + "id": 2, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 3, + "kind": "text", + "text": "* " + }, + { + "id": 5, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 4, + "kind": "text", + "text": "Y" + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 8, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 9, + "kind": "text", + "text": "< " + }, + { + "id": 11, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 10, + "kind": "text", + "text": "10_000" + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 14, + "kind": "text", + "text": " =>" + }, + { + "id": 32, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "width", + "n": 2 + }, + "alignContents": { + "id": 31, + "kind": "list", + "list": [ + { + "id": 15, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 30, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 29, + "kind": "list", + "list": [ + { + "id": 18, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 17, + "kind": "list", + "list": [ + { + "id": 16, + "kind": "text", + "text": "Muuuuuuuuuuuuuuuuuuult'Resuuuuuuuuuuuuuuuuuuuuuuuult" + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 19, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 20, + "kind": "text", + "text": "= " + }, + { + "id": 28, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 27, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 26, + "kind": "list", + "list": [ + { + "id": 21, + "kind": "text", + "text": "X" + }, + { + "id": 22, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 23, + "kind": "text", + "text": "* " + }, + { + "id": 25, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 24, + "kind": "text", + "text": "Y" + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + } + ] + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 35, + "kind": "text", + "text": "," + }, + { + "id": 36, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 64, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 63, + "kind": "list", + "list": [ + { + "id": 49, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 48, + "kind": "list", + "list": [ + { + "id": 43, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 42, + "kind": "list", + "list": [ + { + "id": 37, + "kind": "text", + "text": "X" + }, + { + "id": 38, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 39, + "kind": "text", + "text": "* " + }, + { + "id": 41, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 40, + "kind": "text", + "text": "Y" + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 44, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 45, + "kind": "text", + "text": ">= " + }, + { + "id": 47, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 46, + "kind": "text", + "text": "10_000" + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 50, + "kind": "text", + "text": " =>" + }, + { + "id": 62, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "width", + "n": 2 + }, + "alignContents": { + "id": 61, + "kind": "list", + "list": [ + { + "id": 51, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 60, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 59, + "kind": "list", + "list": [ + { + "id": 54, + "kind": "command", + "command": { + "command": "group", + "id": 0, + "groupContents": { + "id": 53, + "kind": "list", + "list": [ + { + "id": 52, + "kind": "text", + "text": "Mult'Result" + } + ] + }, + "break": false, + "expandedStates": null + } + }, + { + "id": 55, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 56, + "kind": "text", + "text": "= " + }, + { + "id": 58, + "kind": "command", + "command": { + "command": "align", + "alignData": { + "kind": "innerRoot" + }, + "alignContents": { + "id": 57, + "kind": "text", + "text": "10_000" + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + } + ] + } + } + } + ] + }, + "break": false, + "expandedStates": null + } + } + ] + } + } + }, + { + "id": 67, + "kind": "text", + "text": ")" + } + ] + } + } + }, + "break": false, + "expandedStates": null + } +} diff --git a/testsuite/tests/unparsing/contract_cases/special/input.ada b/testsuite/tests/unparsing/contract_cases/special/input.ada new file mode 100644 index 000000000..0ff60023c --- /dev/null +++ b/testsuite/tests/unparsing/contract_cases/special/input.ada @@ -0,0 +1,2 @@ +(X * Y < 10_000 => Muuuuuuuuuuuuuuuuuuult'Resuuuuuuuuuuuuuuuuuuuuuuuult = X * Y, + X * Y >= 10_000 => Mult'Result = 10_000) diff --git a/testsuite/tests/unparsing/contract_cases/special/test.out b/testsuite/tests/unparsing/contract_cases/special/test.out new file mode 100644 index 000000000..4b004b870 --- /dev/null +++ b/testsuite/tests/unparsing/contract_cases/special/test.out @@ -0,0 +1,3 @@ +(X * Y < 10_000 => + Muuuuuuuuuuuuuuuuuuult'Resuuuuuuuuuuuuuuuuuuuuuuuult = X * Y, + X * Y >= 10_000 => Mult'Result = 10_000) diff --git a/testsuite/tests/unparsing/contract_cases/special/test.yaml b/testsuite/tests/unparsing/contract_cases/special/test.yaml new file mode 100644 index 000000000..5207437ab --- /dev/null +++ b/testsuite/tests/unparsing/contract_cases/special/test.yaml @@ -0,0 +1,9 @@ +description: | + This test checks the formatting of contract cases expression. + It is expected the declaration breaks after `=>` and at the + end of the first contract case association; first the new + be indented and the next one be aligned relative to the first + association. + +driver: unparser +rule: contract_cases_expr From 8b6527d668ed0f435f4808100e6ffeab5e87f9da Mon Sep 17 00:00:00 2001 From: Monika Kurovszky Date: Wed, 17 Apr 2024 16:43:49 +0200 Subject: [PATCH 2/3] Fixing AttributeDefClause to indent the expression when needed --- extensions/default_unparsing_config.json | 12 +++++----- .../attribute_def_clause/doc-baseline.json | 22 ++++++++++++++----- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/extensions/default_unparsing_config.json b/extensions/default_unparsing_config.json index 2c3989f1f..7ed5c2968 100644 --- a/extensions/default_unparsing_config.json +++ b/extensions/default_unparsing_config.json @@ -426,14 +426,16 @@ "kind": "text", "text": "use" }, - "line", { "kind": "align", "width": 2, - "contents": { - "kind": "recurse_field", - "field": "f_expr" - } + "contents": [ + "line", + { + "kind": "recurse_field", + "field": "f_expr" + } + ] }, { "kind": "text", diff --git a/testsuite/tests/unparsing/attribute_def_clause/doc-baseline.json b/testsuite/tests/unparsing/attribute_def_clause/doc-baseline.json index 013181523..b06573e11 100644 --- a/testsuite/tests/unparsing/attribute_def_clause/doc-baseline.json +++ b/testsuite/tests/unparsing/attribute_def_clause/doc-baseline.json @@ -1,11 +1,11 @@ { - "id": 10, + "id": 11, "kind": "command", "command": { "command": "group", "id": 0, "groupContents": { - "id": 9, + "id": 10, "kind": "list", "list": [ { @@ -40,7 +40,7 @@ "text": " use" }, { - "id": 7, + "id": 8, "kind": "command", "command": { "command": "align", @@ -49,20 +49,30 @@ "n": 2 }, "alignContents": { - "id": 6, + "id": 7, "kind": "list", "list": [ { "id": 5, + "kind": "command", + "command": { + "command": "line", + "literal": false, + "soft": false, + "hard": false + } + }, + { + "id": 6, "kind": "text", - "text": " 16" + "text": "16" } ] } } }, { - "id": 8, + "id": 9, "kind": "text", "text": ";" } From 83860665f3293541699424a6fc859c7fcbb322e4 Mon Sep 17 00:00:00 2001 From: Monika Kurovszky Date: Wed, 17 Apr 2024 17:30:15 +0200 Subject: [PATCH 3/3] Updating contract case test --- .../{special => long_f_consequence}/doc-baseline.json | 0 .../{special => long_f_consequence}/input.ada | 0 .../{special => long_f_consequence}/test.out | 0 .../unparsing/contract_cases/long_f_consequence/test.yaml | 7 +++++++ .../{special/test.yaml => long_f_consequence/test.yaml~} | 0 5 files changed, 7 insertions(+) rename testsuite/tests/unparsing/contract_cases/{special => long_f_consequence}/doc-baseline.json (100%) rename testsuite/tests/unparsing/contract_cases/{special => long_f_consequence}/input.ada (100%) rename testsuite/tests/unparsing/contract_cases/{special => long_f_consequence}/test.out (100%) create mode 100644 testsuite/tests/unparsing/contract_cases/long_f_consequence/test.yaml rename testsuite/tests/unparsing/contract_cases/{special/test.yaml => long_f_consequence/test.yaml~} (100%) diff --git a/testsuite/tests/unparsing/contract_cases/special/doc-baseline.json b/testsuite/tests/unparsing/contract_cases/long_f_consequence/doc-baseline.json similarity index 100% rename from testsuite/tests/unparsing/contract_cases/special/doc-baseline.json rename to testsuite/tests/unparsing/contract_cases/long_f_consequence/doc-baseline.json diff --git a/testsuite/tests/unparsing/contract_cases/special/input.ada b/testsuite/tests/unparsing/contract_cases/long_f_consequence/input.ada similarity index 100% rename from testsuite/tests/unparsing/contract_cases/special/input.ada rename to testsuite/tests/unparsing/contract_cases/long_f_consequence/input.ada diff --git a/testsuite/tests/unparsing/contract_cases/special/test.out b/testsuite/tests/unparsing/contract_cases/long_f_consequence/test.out similarity index 100% rename from testsuite/tests/unparsing/contract_cases/special/test.out rename to testsuite/tests/unparsing/contract_cases/long_f_consequence/test.out diff --git a/testsuite/tests/unparsing/contract_cases/long_f_consequence/test.yaml b/testsuite/tests/unparsing/contract_cases/long_f_consequence/test.yaml new file mode 100644 index 000000000..702a989ff --- /dev/null +++ b/testsuite/tests/unparsing/contract_cases/long_f_consequence/test.yaml @@ -0,0 +1,7 @@ +description: | + This test checks the formatting of contract cases expression. + Test that when `f_consequences` is long, a line break and + continuation-line indentation is added after `=>`. + +driver: unparser +rule: contract_cases_expr diff --git a/testsuite/tests/unparsing/contract_cases/special/test.yaml b/testsuite/tests/unparsing/contract_cases/long_f_consequence/test.yaml~ similarity index 100% rename from testsuite/tests/unparsing/contract_cases/special/test.yaml rename to testsuite/tests/unparsing/contract_cases/long_f_consequence/test.yaml~