Skip to content

Commit

Permalink
Implement formatter ; add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gmickus committed Sep 27, 2024
1 parent 5756e89 commit 4f49ffe
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 41 deletions.
21 changes: 21 additions & 0 deletions resources/functionalTests/enum/1-enum-with-values/input.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* formatterSettingsOverride */
/* { "AblFormatter.bodyFormatting": true,
"AblFormatter.enumFormatting": true}*/

ENUM Oper:
DEFINE ENUM
Invalid = 0
Create = 1
Delete = 2
BeforeUpdate = 3
AfterUpdate = 4
FieldDelete = 5
PartitionDrop = 6
PartitionTruncate = 7
PartitionDeallocate = 8
MTPartitionDeallocate = 9
MTPartitionDrop = 10
MergePartitionDrop = 11
FieldAdd = 12.
END ENUM.

20 changes: 20 additions & 0 deletions resources/functionalTests/enum/1-enum-with-values/target.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* formatterSettingsOverride */
/* { "AblFormatter.bodyFormatting": true,
"AblFormatter.enumFormatting": true}*/

ENUM Oper:
define ENUM Invalid = 0
Create = 1
Delete = 2
BeforeUpdate = 3
AfterUpdate = 4
FieldDelete = 5
PartitionDrop = 6
PartitionTruncate = 7
PartitionDeallocate = 8
MTPartitionDeallocate = 9
MTPartitionDrop = 10
MergePartitionDrop = 11
FieldAdd = 12.
END ENUM.

14 changes: 14 additions & 0 deletions resources/functionalTests/enum/1-flag/input.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* formatterSettingsOverride */
/* { "AblFormatter.bodyFormatting": true,
"AblFormatter.enumFormatting": true}*/

ENUM LiteraryMood FLAGS:
define ENUM None = 0
Joyful
Melancholy
Heroic
Whimsical
Epic
JoyfulMelancholy = Joyful,Melancholy
Tragic = Epic.
END ENUM.
10 changes: 10 additions & 0 deletions resources/functionalTests/enum/1-simple/input.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": true}*/

ENUM Weather:
define ENUM Rainy
Default = Sunny
Cloudy
Snowy
Apocalyptic .
END ENUM.
10 changes: 10 additions & 0 deletions resources/functionalTests/enum/1-simple/target.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": true}*/

ENUM Weather:
define ENUM Rainy
Default = Sunny
Cloudy
Snowy
Apocalyptic.
END ENUM.
10 changes: 10 additions & 0 deletions resources/functionalTests/enum/2-multiple-enums/input.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* formatterSettingsOverride */
/* { "AblFormatter.bodyFormatting": true,
"AblFormatter.enumFormatting": true}*/

ENUM Direction:
define ENUM North
South.
define ENUM Dog
Cat.
END ENUM.
14 changes: 0 additions & 14 deletions resources/functionalTests/enum/6do-start copy 2/target.p

This file was deleted.

14 changes: 0 additions & 14 deletions resources/functionalTests/enum/6do-start copy 3/target.p

This file was deleted.

5 changes: 0 additions & 5 deletions resources/functionalTests/enum/6do-start copy/input.p

This file was deleted.

6 changes: 0 additions & 6 deletions resources/functionalTests/enum/6do-start copy/target.p

This file was deleted.

9 changes: 7 additions & 2 deletions src/v2/formatters/enum/EnumFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export class EnumFormatter extends AFormatter implements IFormatter {
const oldText = FormatterHelper.getCurrentText(node, fullText);

const newText = this.collectEnumStructure(node, fullText);
console.log("Enum:\n" + newText);
return this.getCodeEdit(node, oldText, newText, fullText);
}

Expand All @@ -57,6 +56,8 @@ export class EnumFormatter extends AFormatter implements IFormatter {
}
resultString = resultString.concat(childString);
});
// Look over this after #215 closed, as the dot should no longer be needed!
resultString += ".";
return resultString;
}

Expand All @@ -66,9 +67,13 @@ export class EnumFormatter extends AFormatter implements IFormatter {
foundFirstMember: boolean
): string {
let newString = "";
console.log("childType: " + node.type);

switch (node.type) {
case SyntaxNodeType.DefineKeyword:
newString =
fullText.eolDelimiter +
FormatterHelper.getCurrentText(node, fullText).trim();
break;
case SyntaxNodeType.EnumMember:
newString = foundFirstMember
? fullText.eolDelimiter +
Expand Down

0 comments on commit 4f49ffe

Please sign in to comment.