-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Getting trailing comma inserted before trailing comma.
closes #1354
- Loading branch information
Showing
2 changed files
with
276 additions
and
0 deletions.
There are no files selected for viewing
146 changes: 146 additions & 0 deletions
146
...CSharpier.Tests/FormattingTests/TestFiles/cs/TrailingComma_TrailingComments.expected.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
int[] shortCollectionExpressionTrailingComma = [1, 2, 3, 4, 5, 6, 7, 8]; | ||
|
||
int[] shortCollectionExpressionNoTrailingComma = [1, 2, 3, 4, 5, 6, 7, 8]; | ||
|
||
int[][] longCollectionExpressionTrailingComma = | ||
[ | ||
[1, 2, 3], | ||
[4, 5, 6], | ||
[7, 8, 9], | ||
]; | ||
|
||
int[][] longCollectionExpressionNoTrailingComma = | ||
[ | ||
[1, 2, 3], | ||
[4, 5, 6], | ||
[7, 8, 9], | ||
]; | ||
|
||
public dynamic shortAnonymousObjectCreationExpressionTrailingComma = new { Property = true }; | ||
|
||
public dynamic shortAnonymousObjectCreationExpressionNoTrailingComma = new { Property = true }; | ||
|
||
public dynamic longAnonymousObjectCreationExpressionTrailingComma = new | ||
{ | ||
One = "One", | ||
Two = "Two", | ||
ThreeThreeThree = "ThreeThreeThree", | ||
}; | ||
|
||
public dynamic longAnonymousObjectCreationExpressionNoTrailingComma = new | ||
{ | ||
One = "One", | ||
Two = "Two", | ||
ThreeThreeThree = "ThreeThreeThree", | ||
}; | ||
|
||
int[] shortInitializerExpressionTrailingComma = { 1, 2 }; | ||
|
||
int[] shortInitializerExpressionNoTrailingComma = { 1, 2 }; | ||
|
||
string[] longInitializerExpressionTrailingComma = | ||
{ | ||
"someLongValue_____________________________________", | ||
"someLongValue_____________________________________", | ||
}; | ||
|
||
string[] longInitializerExpressionNoTrailingComma = | ||
{ | ||
"someLongValue_____________________________________", | ||
"someLongValue_____________________________________", | ||
}; | ||
|
||
int switchExpressionTrailingComma() | ||
{ | ||
return 1 switch | ||
{ | ||
1 => 100, | ||
_ => throw new global::System.Exception(), | ||
}; | ||
} | ||
|
||
int switchExpressionNoTrailingComma() | ||
{ | ||
return 1 switch | ||
{ | ||
1 => 100, | ||
_ => throw new global::System.Exception(), | ||
}; | ||
} | ||
|
||
object listPatternTrailingComma(object list) | ||
{ | ||
return list switch | ||
{ | ||
[var elem] => elem * elem, | ||
[] => 0, | ||
[..] elems => elems.Sum(e => e + e), | ||
}; | ||
} | ||
|
||
object listPatternNoTrailingComma(object list) | ||
{ | ||
return list switch | ||
{ | ||
[var elem] => elem * elem, | ||
[] => 0, | ||
[..] elems => elems.Sum(e => e + e), | ||
}; | ||
} | ||
|
||
public enum EnumDeclarationTrailingComma | ||
{ | ||
Foo = 1, | ||
} | ||
|
||
public enum EnumDeclarationNoTrailingCommand | ||
{ | ||
Foo = 1, | ||
} | ||
|
||
public enum EnumDeclarationWithDirective | ||
{ | ||
Foo = 1, | ||
#if DEBUG | ||
Bar = 2, | ||
#endif | ||
Abc = 3, | ||
} | ||
|
||
public enum EnumDeclarationWithDirectiveBeforeBracket | ||
{ | ||
Foo = 1, | ||
#if DEBUG | ||
Bar = 2, | ||
#endif | ||
} | ||
|
||
public enum EnumDeclarationWithLeadingCommaInDirective | ||
{ | ||
Foo = 1 | ||
#if DEBUG | ||
, | ||
Bar = 2 | ||
#endif | ||
, | ||
Abc = 3, | ||
} | ||
|
||
public enum EnumDeclarationWithLeadingCommaInDirectiveBeforeBracket | ||
{ | ||
Foo = 1 | ||
#if DEBUG | ||
, | ||
Bar = 2 | ||
#endif | ||
} | ||
|
||
public enum EnumDeclarationWithLeadingCommaInDirectiveAndTrailingComma | ||
{ | ||
Foo = 1 | ||
#if DEBUG | ||
, | ||
Bar = 2 | ||
#endif | ||
, | ||
} |
130 changes: 130 additions & 0 deletions
130
Src/CSharpier.Tests/FormattingTests/TestFiles/cs/TrailingComma_TrailingComments.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
int[] shortCollectionExpressionTrailingComma = [1, 2, 3, 4, 5, 6, 7, 8,]; | ||
|
||
int[] shortCollectionExpressionNoTrailingComma = [1, 2, 3, 4, 5, 6, 7, 8]; | ||
|
||
int[][] longCollectionExpressionTrailingComma = | ||
[ | ||
[1, 2, 3], | ||
[4, 5, 6], | ||
[7, 8, 9], | ||
]; | ||
|
||
int[][] longCollectionExpressionNoTrailingComma = | ||
[ | ||
[1, 2, 3], | ||
[4, 5, 6], | ||
[7, 8, 9] | ||
]; | ||
|
||
public dynamic shortAnonymousObjectCreationExpressionTrailingComma = new { Property = true, }; | ||
|
||
public dynamic shortAnonymousObjectCreationExpressionNoTrailingComma = new { Property = true }; | ||
|
||
public dynamic longAnonymousObjectCreationExpressionTrailingComma = new | ||
{ | ||
One = "One", | ||
Two = "Two", | ||
ThreeThreeThree = "ThreeThreeThree", | ||
}; | ||
|
||
public dynamic longAnonymousObjectCreationExpressionNoTrailingComma = new | ||
{ | ||
One = "One", | ||
Two = "Two", | ||
ThreeThreeThree = "ThreeThreeThree" | ||
}; | ||
|
||
int[] shortInitializerExpressionTrailingComma = { 1, 2, }; | ||
|
||
int[] shortInitializerExpressionNoTrailingComma = { 1, 2 }; | ||
|
||
string[] longInitializerExpressionTrailingComma = | ||
{ | ||
"someLongValue_____________________________________", | ||
"someLongValue_____________________________________", | ||
}; | ||
|
||
string[] longInitializerExpressionNoTrailingComma = | ||
{ | ||
"someLongValue_____________________________________", | ||
"someLongValue_____________________________________" | ||
}; | ||
|
||
int switchExpressionTrailingComma() | ||
{ | ||
return 1 switch { 1 => 100, _ => throw new global::System.Exception(), }; | ||
} | ||
|
||
int switchExpressionNoTrailingComma() | ||
{ | ||
return 1 switch | ||
{ | ||
1 => 100, | ||
_ => throw new global::System.Exception() | ||
}; | ||
} | ||
|
||
object listPatternTrailingComma(object list) | ||
{ | ||
return list switch { [var elem] => elem * elem, [] => 0, [..] elems => elems.Sum(e => e + e), }; | ||
} | ||
|
||
object listPatternNoTrailingComma(object list) | ||
{ | ||
return list switch | ||
{ | ||
[var elem] => elem * elem, | ||
[] => 0, | ||
[..] elems => elems.Sum(e => e + e) | ||
}; | ||
} | ||
|
||
public enum EnumDeclarationTrailingComma { Foo = 1, } | ||
|
||
public enum EnumDeclarationNoTrailingCommand | ||
{ | ||
Foo = 1 | ||
} | ||
|
||
public enum EnumDeclarationWithDirective { | ||
Foo = 1, | ||
#if DEBUG | ||
Bar = 2, | ||
#endif | ||
Abc = 3, | ||
} | ||
|
||
public enum EnumDeclarationWithDirectiveBeforeBracket { | ||
Foo = 1, | ||
#if DEBUG | ||
Bar = 2, | ||
#endif | ||
} | ||
|
||
public enum EnumDeclarationWithLeadingCommaInDirective { | ||
Foo = 1 | ||
#if DEBUG | ||
, | ||
Bar = 2 | ||
#endif | ||
, | ||
Abc = 3 | ||
} | ||
|
||
public enum EnumDeclarationWithLeadingCommaInDirectiveBeforeBracket { | ||
Foo = 1 | ||
#if DEBUG | ||
, | ||
Bar = 2 | ||
#endif | ||
} | ||
|
||
public enum EnumDeclarationWithLeadingCommaInDirectiveAndTrailingComma | ||
{ | ||
Foo = 1 | ||
#if DEBUG | ||
, | ||
Bar = 2 | ||
#endif | ||
, | ||
} |