Skip to content

Commit c478d49

Browse files
committed
Check all [Flags] enums for overlaps
Closes libgit2#311
1 parent 4afa289 commit c478d49

2 files changed

Lines changed: 19 additions & 15 deletions

File tree

LibGit2Sharp.Tests/MetaFixture.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,25 @@ public void TypesInLibGit2SharpMustBeExtensibleInATestingContext()
9393
}
9494
}
9595

96+
[Fact]
97+
public void EnumsWithFlagsHaveMutuallyExclusiveValues()
98+
{
99+
var flagsEnums = Assembly.GetAssembly(typeof(Repository)).GetExportedTypes()
100+
.Where(t => t.IsEnum && t.GetCustomAttributes(typeof(FlagsAttribute), false).Any());
101+
102+
var overlaps = from t in flagsEnums
103+
from int x in Enum.GetValues(t)
104+
where x != 0
105+
from int y in Enum.GetValues(t)
106+
where y != 0
107+
where x != y && (x & y) == y
108+
select string.Format("{0}.{1} overlaps with {0}.{2}", t.Name, Enum.ToObject(t, x), Enum.ToObject(t, y));
109+
110+
var message = string.Join(Environment.NewLine, overlaps.ToArray());
111+
112+
Assert.Equal("", message);
113+
}
114+
96115
private string BuildMissingDebuggerDisplayPropertyMessage(IEnumerable<Type> typesWithDebuggerDisplayAndInvalidImplPattern)
97116
{
98117
var sb = new StringBuilder();

LibGit2Sharp.Tests/StatusFixture.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,6 @@ namespace LibGit2Sharp.Tests
99
{
1010
public class StatusFixture : BaseFixture
1111
{
12-
[Fact]
13-
public void FileStatusFlagsAreMutuallyExclusive()
14-
{
15-
var overlaps = from FileStatus x in Enum.GetValues(typeof(FileStatus))
16-
where x != default(FileStatus)
17-
from FileStatus y in Enum.GetValues(typeof(FileStatus))
18-
where y != default(FileStatus)
19-
where x != y && (x & y) == y
20-
select string.Format("{0} overlaps with {1}", x, y);
21-
22-
var message = string.Join(Environment.NewLine, overlaps.ToArray());
23-
24-
Assert.Equal("", message);
25-
}
26-
2712
[Fact]
2813
public void CanRetrieveTheStatusOfAFile()
2914
{

0 commit comments

Comments
 (0)