-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
74 changed files
with
3,598 additions
and
2 deletions.
There are no files selected for viewing
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,15 @@ | ||
# Auto-detect text files so that they can be stored with LF endings | ||
# in github, and CRLF endings locally in Windows. | ||
* text=auto | ||
|
||
# Avoid potential misdetection of some common file types | ||
*.cs text | ||
*.csproj text | ||
*.Config text | ||
*.config text | ||
*.StyleCop text | ||
*.resx text | ||
|
||
# Apparently ReSharper uses LF line endings in its settings files, | ||
# so tell git that we know this to avoid warnings. | ||
*.DotSettings text eol=lf |
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
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,25 @@ | ||
<?xml version="1.0"?> | ||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> | ||
<metadata> | ||
<id>OrderUsings</id> | ||
<title>Order and space using directives</title> | ||
<version>1.0.0</version> | ||
<authors>Ian Griffiths</authors> | ||
<owners>Ian Griffiths</owners> | ||
<description>Enables configurable fine control over the ordering, grouping, and spacing of C# using directives. Instead of being limited to two groups - System*, and everything else - you can define any number of groups in any order to arrange using directives however makes most sense for your project.</description> | ||
<summary>Control over the ordering, grouping, and spacing of C# using directives.</summary> | ||
<copyright>Copyright © 2014 Ian Griffiths</copyright> | ||
<releaseNotes>• 1.0.0 - First release (supporting only ReSharper 8.1)</releaseNotes> | ||
<projectUrl>https://github.com/idg10/order-usings</projectUrl> | ||
<licenseUrl>https://github.com/idg10/order-usings/blob/master/LICENSE</licenseUrl> | ||
<dependencies> | ||
<dependency id="ReSharper" version="[8.1, 8.2)" /> | ||
</dependencies> | ||
</metadata> | ||
<files> | ||
<file src="..\src\ReSharper810\bin\Release\OrderUsings.ReSharper810.dll" | ||
target="ReSharper\v8.1\plugins" /> | ||
<file src="..\src\OrderUsings.Core\bin\Release\OrderUsings.Core.dll" | ||
target="ReSharper\v8.1\plugins" /> | ||
</files> | ||
</package> |
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="NUnit.Runners" version="2.6.3" /> | ||
</packages> |
102 changes: 102 additions & 0 deletions
102
...derUsings.Core.Tests/OrderAndSpacingDetermination/OrderAndSpacingDeterminationTestBase.cs
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,102 @@ | ||
namespace OrderUsings.Tests.OrderAndSpacingDetermination | ||
{ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
using NUnit.Framework; | ||
|
||
using OrderUsings.Configuration; | ||
using OrderUsings.Processing; | ||
|
||
public abstract class OrderAndSpacingDeterminationTestBase | ||
{ | ||
internal static readonly UsingDirective AliasSystemPathAsPath = new UsingDirective { Namespace = "System.IO.Path", Alias = "Path" }; | ||
internal static readonly UsingDirective AliasSystemLaterAsEarlier = new UsingDirective { Namespace = "System.Later", Alias = "Earlier" }; | ||
internal static readonly UsingDirective AliasSystemTextAsSystem = new UsingDirective { Namespace = "System.Text", Alias = "System" }; | ||
|
||
internal static readonly UsingDirective ImportSystem = new UsingDirective { Namespace = "System" }; | ||
internal static readonly UsingDirective ImportSystemCollectionsGeneric = new UsingDirective { Namespace = "System.Collections.Generic" }; | ||
internal static readonly UsingDirective ImportSystemLinq = new UsingDirective { Namespace = "System.Linq" }; | ||
|
||
internal static readonly UsingDirective ImportMicrosoftCSharp = new UsingDirective { Namespace = "Microsoft.CSharp" }; | ||
|
||
internal static readonly UsingDirective ImportOther = new UsingDirective { Namespace = "Other" }; | ||
internal static readonly UsingDirective ImportOtherA = new UsingDirective { Namespace = "Other.A" }; | ||
internal static readonly UsingDirective ImportOtherB = new UsingDirective { Namespace = "Other.B" }; | ||
|
||
internal static readonly UsingDirective ImportMyLocal = new UsingDirective { Namespace = "MyLocal" }; | ||
internal static readonly UsingDirective ImportMyLocalA = new UsingDirective { Namespace = "MyLocal.A" }; | ||
internal static readonly UsingDirective ImportMyLocalB = new UsingDirective { Namespace = "MyLocal.B" }; | ||
|
||
internal static readonly UsingDirective ImportRuhroh = new UsingDirective { Namespace = "Ruhroh" }; | ||
|
||
|
||
internal OrderUsingsConfiguration Configuration { get; private set; } | ||
|
||
[SetUp] | ||
public void BaseInitialize() | ||
{ | ||
Configuration = new OrderUsingsConfiguration | ||
{ | ||
GroupsAndSpaces = GetRules() | ||
}; | ||
} | ||
|
||
internal abstract List<ConfigurationRule> GetRules(); | ||
|
||
internal void Verify(UsingDirective[] directivesIn, params UsingDirective[][] expectedGroups) | ||
{ | ||
foreach (var permutation in AllOrderings(directivesIn)) | ||
{ | ||
var results = OrderAndSpacingGenerator.DetermineOrderAndSpacing( | ||
permutation, Configuration); | ||
|
||
Assert.AreEqual(expectedGroups.Length, results.Count); | ||
for (int i = 0; i < expectedGroups.Length; ++i) | ||
{ | ||
Assert.AreEqual(results[i].Count, expectedGroups[i].Length, "Item count in group " + i); | ||
for (int j = 0; j < expectedGroups[i].Length; ++j) | ||
{ | ||
UsingDirective expectedUsing = expectedGroups[i][j]; | ||
UsingDirective actualUsing = results[i][j]; | ||
string message = string.Format( | ||
"Expected {0} at {1},{2}, found {3}", expectedUsing, i, j, actualUsing); | ||
Assert.AreSame(expectedUsing, actualUsing, message); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// This is the same for all configurations. We only want to run the test | ||
// once per config, so we don't make this a [Test] in this base class - that | ||
// would run it once per derived class. Instead, just one derived classes | ||
// per config will defer to this. | ||
protected void VerifyEmptyHandling() | ||
{ | ||
Verify(new UsingDirective[0], new UsingDirective[0][]); | ||
} | ||
|
||
private static IEnumerable<IEnumerable<T>> AllOrderings<T>(IEnumerable<T> items) | ||
{ | ||
bool returnedAtLeastOne = false; | ||
int index = 0; | ||
// ReSharper disable PossibleMultipleEnumeration | ||
foreach (T item in items) | ||
{ | ||
returnedAtLeastOne = true; | ||
int thisIndex = index; | ||
foreach (var remainders in AllOrderings(items.Where((x, i) => i != thisIndex))) | ||
{ | ||
yield return new[] { item }.Concat(remainders); | ||
} | ||
index += 1; | ||
} | ||
// ReSharper restore PossibleMultipleEnumeration | ||
|
||
if (!returnedAtLeastOne) | ||
{ | ||
yield return Enumerable.Empty<T>(); | ||
} | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...s/OrderAndSpacingDetermination/SinglePatternMatchesAll/SinglePatternMatchesAllTestBase.cs
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,24 @@ | ||
namespace OrderUsings.Tests.OrderAndSpacingDetermination.SinglePatternMatchesAll | ||
{ | ||
using System.Collections.Generic; | ||
|
||
using OrderUsings.Configuration; | ||
|
||
public abstract class SinglePatternMatchesAllTestBase : OrderAndSpacingDeterminationTestBase | ||
{ | ||
internal override List<ConfigurationRule> GetRules() | ||
{ | ||
return new List<ConfigurationRule> | ||
{ | ||
ConfigurationRule.ForGroupRule(new GroupRule | ||
{ | ||
Type = MatchType.ImportOrAlias, | ||
NamespacePattern = "*", | ||
AliasPattern = "*", | ||
Priority = 1, | ||
OrderAliasesBy = OrderAliasBy.Alias | ||
}) | ||
}; | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...e.Tests/OrderAndSpacingDetermination/SinglePatternMatchesAll/WhenAliasesOrderedByAlias.cs
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,30 @@ | ||
namespace OrderUsings.Tests.OrderAndSpacingDetermination.SinglePatternMatchesAll | ||
{ | ||
using NUnit.Framework; | ||
|
||
public class WhenAliasesOrderedByAlias : SinglePatternMatchesAllTestBase | ||
{ | ||
[Test] | ||
public void ProducesSingleGroupOrderedByAliasWhenAliasesAndNamespaceOtherwise() | ||
{ | ||
Verify( | ||
new[] | ||
{ | ||
AliasSystemPathAsPath, | ||
ImportSystem, | ||
ImportRuhroh, | ||
AliasSystemLaterAsEarlier | ||
}, | ||
new[] | ||
{ | ||
new[] | ||
{ | ||
AliasSystemLaterAsEarlier, | ||
AliasSystemPathAsPath, | ||
ImportRuhroh, | ||
ImportSystem | ||
} | ||
}); | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...sts/OrderAndSpacingDetermination/SinglePatternMatchesAll/WhenAliasesOrderedByNamespace.cs
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,49 @@ | ||
namespace OrderUsings.Tests.OrderAndSpacingDetermination.SinglePatternMatchesAll | ||
{ | ||
using System.Collections.Generic; | ||
|
||
using NUnit.Framework; | ||
|
||
using OrderUsings.Configuration; | ||
|
||
public class WhenAliasesOrderedByNamespace : SinglePatternMatchesAllTestBase | ||
{ | ||
internal override List<ConfigurationRule> GetRules() | ||
{ | ||
var r = base.GetRules(); | ||
r[0].Rule.OrderAliasesBy = OrderAliasBy.Namespace; | ||
return r; | ||
} | ||
|
||
[Test] | ||
public void ProducesSingleGroupOrderedByNamespace() | ||
{ | ||
Verify( | ||
new[] | ||
{ | ||
AliasSystemPathAsPath, | ||
ImportSystem, | ||
ImportRuhroh, | ||
AliasSystemLaterAsEarlier | ||
}, | ||
new[] | ||
{ | ||
new[] | ||
{ | ||
ImportRuhroh, | ||
ImportSystem, | ||
AliasSystemPathAsPath, | ||
AliasSystemLaterAsEarlier | ||
} | ||
}); | ||
} | ||
|
||
// This class introduces a change in config, so we should verify that | ||
// empty input handling still works. | ||
[Test] | ||
public void EmptyUsingsProducesNoGroups() | ||
{ | ||
VerifyEmptyHandling(); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...Tests/OrderAndSpacingDetermination/SinglePatternMatchesAll/WhenImportAndAliasShareName.cs
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,33 @@ | ||
namespace OrderUsings.Tests.OrderAndSpacingDetermination.SinglePatternMatchesAll | ||
{ | ||
using NUnit.Framework; | ||
|
||
public class WhenImportAndAliasShareName : SinglePatternMatchesAllTestBase | ||
{ | ||
[Test] | ||
public void GroupItemsShouldPutNonAliasFirst() | ||
{ | ||
// Bizarre though it seems, this: | ||
// using System; | ||
// using System = System.Text; | ||
// is legal. If a group orders using alias directives by Alias (which is the default) | ||
// we need to pick one to go first. We put the non-alias one first (i.e., the order | ||
// shown above), since this seems most consistent with the behaviour of ordering | ||
// usings lexographically within a group. | ||
Verify( | ||
new[] | ||
{ | ||
AliasSystemTextAsSystem, | ||
ImportSystem | ||
}, | ||
new[] | ||
{ | ||
new[] | ||
{ | ||
ImportSystem, | ||
AliasSystemTextAsSystem | ||
} | ||
}); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...derUsings.Core.Tests/OrderAndSpacingDetermination/SinglePatternMatchesAll/WhenNoUsings.cs
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,13 @@ | ||
namespace OrderUsings.Tests.OrderAndSpacingDetermination.SinglePatternMatchesAll | ||
{ | ||
using NUnit.Framework; | ||
|
||
public class WhenNoUsings : SinglePatternMatchesAllTestBase | ||
{ | ||
[Test] | ||
public void ProducesNoGroups() | ||
{ | ||
VerifyEmptyHandling(); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...erUsings.Core.Tests/OrderAndSpacingDetermination/SinglePatternMatchesAll/WhenOneImport.cs
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,13 @@ | ||
namespace OrderUsings.Tests.OrderAndSpacingDetermination.SinglePatternMatchesAll | ||
{ | ||
using NUnit.Framework; | ||
|
||
public class WhenOneImport : SinglePatternMatchesAllTestBase | ||
{ | ||
[Test] | ||
public void ProducesOneGroup() | ||
{ | ||
Verify(new[] { ImportSystem }, new[] { new[] { ImportSystem } }); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...sings.Core.Tests/OrderAndSpacingDetermination/SinglePatternMatchesAll/WhenThreeImports.cs
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,28 @@ | ||
namespace OrderUsings.Tests.OrderAndSpacingDetermination.SinglePatternMatchesAll | ||
{ | ||
using NUnit.Framework; | ||
|
||
public class WhenThreeImports : SinglePatternMatchesAllTestBase | ||
{ | ||
[Test] | ||
public void ProducesOneGroupInAlphabeticalOrder() | ||
{ | ||
Verify( | ||
new[] | ||
{ | ||
ImportSystem, | ||
ImportSystemCollectionsGeneric, | ||
ImportSystemLinq | ||
}, | ||
new[] | ||
{ | ||
new[] | ||
{ | ||
ImportSystem, | ||
ImportSystemCollectionsGeneric, | ||
ImportSystemLinq | ||
} | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.