From ce1ae413cb634d4e03ae0698793f7831fff1f690 Mon Sep 17 00:00:00 2001 From: Dobromir Marinov Date: Wed, 3 Nov 2021 18:06:05 +0000 Subject: [PATCH] * Fixed recognition around records. * Added more unit tests. --- .../java/org/swim/formatting/ReconFormattingModelBuilder.java | 1 + src/main/java/org/swim/language/Recon.bnf | 2 +- src/test/java/ReconCodeFormattingTests.java | 2 ++ .../testData/formatting/expected/attr-record-no-change.recon | 2 ++ .../testData/formatting/expected/record-after-literal.recon | 3 +++ src/test/testData/formatting/input/attr-record-no-change.recon | 2 ++ src/test/testData/formatting/input/record-after-literal.recon | 3 +++ 7 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/test/testData/formatting/expected/attr-record-no-change.recon create mode 100644 src/test/testData/formatting/expected/record-after-literal.recon create mode 100644 src/test/testData/formatting/input/attr-record-no-change.recon create mode 100644 src/test/testData/formatting/input/record-after-literal.recon diff --git a/src/main/java/org/swim/formatting/ReconFormattingModelBuilder.java b/src/main/java/org/swim/formatting/ReconFormattingModelBuilder.java index fe4467a..7206994 100644 --- a/src/main/java/org/swim/formatting/ReconFormattingModelBuilder.java +++ b/src/main/java/org/swim/formatting/ReconFormattingModelBuilder.java @@ -55,6 +55,7 @@ private static SpacingBuilder createSpaceBuilder(CodeStyleSettings settings) { builder.before(ReconTypes.SEP).spaces(0); builder.before(ReconTypes.SLOTS).blankLines(0); + builder.between(ReconTypes.SLOTS, ReconTypes.RECORD).lineBreakInCode(); builder.after(ReconTypes.OPEN_BRACK).spaces(0); builder.before(ReconTypes.OPEN_BRACK).spaces(0); diff --git a/src/main/java/org/swim/language/Recon.bnf b/src/main/java/org/swim/language/Recon.bnf index 65bfc0e..f9aeb6a 100644 --- a/src/main/java/org/swim/language/Recon.bnf +++ b/src/main/java/org/swim/language/Recon.bnf @@ -40,6 +40,6 @@ empty_slot ::= blockItem whiteSpace* COL block ::= whiteSpace* slots whiteSpace* -record ::= OPEN_CRL_BRACK block? whiteSpace* CLOSE_CRL_BRACK +record ::= whiteSpace* OPEN_CRL_BRACK block? whiteSpace* CLOSE_CRL_BRACK whiteSpace ::= NL | SP \ No newline at end of file diff --git a/src/test/java/ReconCodeFormattingTests.java b/src/test/java/ReconCodeFormattingTests.java index 033097d..c045df9 100644 --- a/src/test/java/ReconCodeFormattingTests.java +++ b/src/test/java/ReconCodeFormattingTests.java @@ -13,6 +13,7 @@ public void testFormatting() { tests.add("attr-after-slot-expand.recon"); tests.add("attr-collapse.recon"); tests.add("attr-expand.recon"); + tests.add("attr-record-no-change.recon"); tests.add("attr-spaces-between.recon"); tests.add("cellular-collapse.recon"); tests.add("cellular-expand.recon"); @@ -21,6 +22,7 @@ public void testFormatting() { tests.add("comment-collapse.recon"); tests.add("extant-slots.recon"); tests.add("operations-collapse.recon"); + tests.add("record-after-literal.recon"); tests.add("rosa-expand.recon"); tests.add("slot-after-attr-collapse.recon"); tests.add("slots-collapse-extant.recon"); diff --git a/src/test/testData/formatting/expected/attr-record-no-change.recon b/src/test/testData/formatting/expected/attr-record-no-change.recon new file mode 100644 index 0000000..38c7022 --- /dev/null +++ b/src/test/testData/formatting/expected/attr-record-no-change.recon @@ -0,0 +1,2 @@ +@atr() { +} \ No newline at end of file diff --git a/src/test/testData/formatting/expected/record-after-literal.recon b/src/test/testData/formatting/expected/record-after-literal.recon new file mode 100644 index 0000000..5aee868 --- /dev/null +++ b/src/test/testData/formatting/expected/record-after-literal.recon @@ -0,0 +1,3 @@ +1 +{ +} \ No newline at end of file diff --git a/src/test/testData/formatting/input/attr-record-no-change.recon b/src/test/testData/formatting/input/attr-record-no-change.recon new file mode 100644 index 0000000..38c7022 --- /dev/null +++ b/src/test/testData/formatting/input/attr-record-no-change.recon @@ -0,0 +1,2 @@ +@atr() { +} \ No newline at end of file diff --git a/src/test/testData/formatting/input/record-after-literal.recon b/src/test/testData/formatting/input/record-after-literal.recon new file mode 100644 index 0000000..4e8a0c9 --- /dev/null +++ b/src/test/testData/formatting/input/record-after-literal.recon @@ -0,0 +1,3 @@ +1{ + + } \ No newline at end of file