This repository was archived by the owner on Jul 12, 2022. It is now read-only.
File tree 2 files changed +86
-1
lines changed
Microsoft.DotNet.CodeFormatting/Rules
Microsoft.DotNet.CodeFormatting.Tests/Rules 2 files changed +86
-1
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,25 @@ class C
29
29
30
30
var expected = @"// test
31
31
32
+ class C
33
+ {
34
+ }" ;
35
+ Verify ( source , expected ) ;
36
+
37
+ }
38
+
39
+ [ Fact ]
40
+ public void CSharpSimpleMultiline ( )
41
+ {
42
+ _options . CopyrightHeader = ImmutableArray . Create ( "test1" , "test2" ) ;
43
+ var source = @"
44
+ class C
45
+ {
46
+ }" ;
47
+
48
+ var expected = @"// test1
49
+ // test2
50
+
32
51
class C
33
52
{
34
53
}" ;
@@ -48,6 +67,62 @@ class C
48
67
49
68
var expected = @"// test
50
69
70
+ class C
71
+ {
72
+ }" ;
73
+ Verify ( source , expected ) ;
74
+
75
+ }
76
+
77
+ [ Fact ]
78
+ public void CSharpPreserveExistingMultiline ( )
79
+ {
80
+ _options . CopyrightHeader = ImmutableArray . Create ( "test1" , "test2" ) ;
81
+ var source = @"// test1
82
+ // test2
83
+
84
+ class C
85
+ {
86
+ }" ;
87
+
88
+ var expected = @"// test1
89
+ // test2
90
+
91
+ class C
92
+ {
93
+ }" ;
94
+ Verify ( source , expected ) ;
95
+
96
+ }
97
+
98
+ [ Fact ]
99
+ public void CSharpPreserveExistingWithCommentMultiline ( )
100
+ {
101
+ _options . CopyrightHeader = ImmutableArray . Create ( "test1" , "test2" ) ;
102
+ var source = @"// test1
103
+ // test2
104
+
105
+
106
+
107
+
108
+
109
+ // test3
110
+
111
+
112
+ class C
113
+ {
114
+ }" ;
115
+
116
+ var expected = @"// test1
117
+ // test2
118
+
119
+
120
+
121
+
122
+
123
+ // test3
124
+
125
+
51
126
class C
52
127
{
53
128
}" ;
Original file line number Diff line number Diff line change @@ -79,6 +79,7 @@ private List<string> GetExistingHeader(SyntaxTriviaList triviaList)
79
79
{
80
80
headerList . Add ( GetCommentText ( triviaList [ i ] . ToFullString ( ) ) ) ;
81
81
i ++ ;
82
+ MoveToNextLineOrTrivia ( triviaList , ref i ) ;
82
83
}
83
84
84
85
return headerList ;
@@ -113,10 +114,19 @@ private SyntaxTriviaList RemoveExistingHeader(SyntaxTriviaList oldList)
113
114
114
115
private void MovePastBlankLines ( SyntaxTriviaList list , ref int index )
115
116
{
116
- while ( index < list . Count && IsWhiteSpaceOrNewLine ( list [ index ] ) )
117
+ while ( MoveToNextLineOrTrivia ( list , ref index ) )
118
+ {
119
+ }
120
+ }
121
+
122
+ private bool MoveToNextLineOrTrivia ( SyntaxTriviaList list , ref int index )
123
+ {
124
+ bool moved = index < list . Count && IsWhiteSpaceOrNewLine ( list [ index ] ) ;
125
+ if ( moved )
117
126
{
118
127
index ++ ;
119
128
}
129
+ return moved ;
120
130
}
121
131
122
132
protected abstract SyntaxTriviaList CreateTriviaList ( IEnumerable < SyntaxTrivia > e ) ;
You can’t perform that action at this time.
0 commit comments