@@ -10,20 +10,29 @@ public class IncludeFormatingTest
1010 private static string sourceCode_NoBlanks =
1111@"#include ""a.h""
1212#include <b.hpp>
13+ #include ""a.h""
1314#include ""filename.h""
15+ #include <b.hpp>
1416#include <d_firstanyways>
1517#include <e_secondanyways>
16- #include <c.hpp>" ;
18+ #include <e_secondanyways>
19+ #include <c.hpp>
20+ #include <d_firstanyways>" ;
1721
1822 private static string sourceCode_WithBlanks =
1923@"#include ""c_third""
2024
2125#include ""filename.h""
2226
27+ #include ""z_first""
28+
29+ #include <b_second>
2330#include <b_second>
2431// A comment
25- #include ""z_first""" ;
32+ #include ""z_first""
2633
34+ #include <b_second>
35+ #include ""filename.h""" ;
2736
2837 [ TestMethod ]
2938 public void Sorting_BlanksAfterRegexGroup ( )
@@ -45,8 +54,10 @@ public void Sorting_BlanksAfterRegexGroup()
4554#include <b_second>
4655
4756#include ""c_third""
57+
58+ #include ""z_first""
4859// A comment
49- #include ""z_first"" ";
60+ " ;
5061
5162
5263 var settings = new IncludeToolbox . FormatterOptionsPage ( ) ;
@@ -85,8 +96,10 @@ public void Sorting_AngleBracketsFirst()
8596#include ""filename.h""
8697
8798#include ""c_third""
99+
100+ #include ""z_first""
88101// A comment
89- #include ""z_first"" ";
102+ " ;
90103
91104
92105 var settings = new IncludeToolbox . FormatterOptionsPage ( ) ;
@@ -106,15 +119,64 @@ public void Sorting_AngleBracketsFirst()
106119 }
107120
108121 [ TestMethod ]
109- public void RemoveEmptyLines ( )
122+ public void Sorting_DontRemoveDuplicates ( )
110123 {
124+ // With sort by type.
125+ string expectedFormatedCode_NoBlanks =
126+ @"#include ""filename.h""
127+
128+ #include <d_firstanyways>
129+ #include <d_firstanyways>
130+ #include <e_secondanyways>
131+ #include <e_secondanyways>
132+
133+ #include ""a.h""
134+ #include ""a.h""
135+ #include <b.hpp>
136+ #include <b.hpp>
137+ #include <c.hpp>" ;
138+
139+
111140 string expectedFormatedCode_WithBlanks =
112141@"#include ""filename.h""
142+ #include ""filename.h""
143+
144+ #include <b_second>
145+ #include <b_second>
113146#include <b_second>
114- #include ""c_third""
115147// A comment
148+ #include ""c_third""
149+ #include ""z_first""
116150#include ""z_first""" ;
117151
152+
153+ var settings = new IncludeToolbox . FormatterOptionsPage ( ) ;
154+ settings . SortByType = IncludeToolbox . FormatterOptionsPage . TypeSorting . None ;
155+ settings . PrecedenceRegexes = new string [ ]
156+ {
157+ IncludeToolbox . RegexUtils . CurrentFileNameKey ,
158+ ".+_.+"
159+ } ;
160+ settings . BlankAfterRegexGroupMatch = true ;
161+ settings . RemoveEmptyLines = true ;
162+ settings . RemoveDuplicates = false ;
163+
164+ string formatedCode = IncludeFormatter . FormatIncludes ( sourceCode_NoBlanks , "filename.cpp" , new string [ ] { } , settings ) ;
165+ Assert . AreEqual ( expectedFormatedCode_NoBlanks , formatedCode ) ;
166+ formatedCode = IncludeFormatter . FormatIncludes ( sourceCode_WithBlanks , "filename.cpp" , new string [ ] { } , settings ) ;
167+ Assert . AreEqual ( expectedFormatedCode_WithBlanks , formatedCode ) ;
168+ }
169+
170+ [ TestMethod ]
171+ public void RemoveEmptyLines ( )
172+ {
173+ string expectedFormatedCode_WithBlanks =
174+ @"#include ""filename.h""
175+ #include <b_second>
176+ #include ""c_third""
177+ #include ""z_first""
178+ // A comment" ;
179+
118180 var settings = new IncludeToolbox . FormatterOptionsPage ( ) ;
119181 settings . SortByType = IncludeToolbox . FormatterOptionsPage . TypeSorting . None ;
120182 settings . PrecedenceRegexes = new string [ ] { IncludeToolbox . RegexUtils . CurrentFileNameKey } ;
@@ -148,13 +210,16 @@ public void OtherPreprocessorDirectives()
148210@"#pragma once
149211// SomeComment
150212#include ""z""
213+ #include <b>
151214
152215#include ""filename.h""
153216
154217#if test
155218#include <d>
156219// A comment
157220#include ""a9""
221+ #include <d>
222+ #include <c>
158223#else
159224#include <d>
160225
@@ -163,17 +228,21 @@ public void OtherPreprocessorDirectives()
163228
164229#include <a2>
165230#endif
231+ #include <b>
166232#include <a1>" ;
167233
168234 string expectedFormatedCode =
169235@"#pragma once
170236// SomeComment
237+ #include <b>
171238#include ""filename.h""
172239
173240#include ""z""
241+
174242#if test
175- #include <d >
243+ #include <c >
176244// A comment
245+ #include <d>
177246#include ""a9""
178247#else
179248#include <a2>
@@ -183,7 +252,8 @@ public void OtherPreprocessorDirectives()
183252
184253#include <d>
185254#endif
186- #include <a1>" ;
255+ #include <a1>
256+ #include <b>" ;
187257
188258 var settings = new IncludeToolbox . FormatterOptionsPage ( ) ;
189259 settings . SortByType = IncludeToolbox . FormatterOptionsPage . TypeSorting . AngleBracketsFirst ;
0 commit comments