Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When including an expression-based property using ShouldBeEquivalentT…
…o it should start evaluation at the root. Fixed #462
- Loading branch information
1 parent
3abfc14
commit 9029a05
Showing
3 changed files
with
66 additions
and
6 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
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 |
---|---|---|
@@ -1,24 +1,41 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace FluentAssertions.Equivalency.Selection | ||
{ | ||
/// <summary> | ||
/// Encapsulates a dotted path to a (nested) member of a type. | ||
/// Encapsulates a dotted candidate to a (nested) member of a type. | ||
/// </summary> | ||
internal class MemberPath | ||
{ | ||
private readonly List<string> segments = new List<string>(); | ||
|
||
public MemberPath(string dottedPath) | ||
{ | ||
segments.AddRange(dottedPath.Split('.')); | ||
segments.AddRange(Segmentize(dottedPath)); | ||
} | ||
|
||
public bool StartsWith(string subPath) | ||
public bool IsParentOrChildOf(string candidate) | ||
{ | ||
string[] subPathSegments = subPath.Split('.'); | ||
return segments.Take(subPathSegments.Length).SequenceEqual(subPathSegments); | ||
return IsParent(candidate) || IsChild(candidate); | ||
} | ||
|
||
private bool IsChild(string candidate) | ||
{ | ||
return Segmentize(candidate).Take(segments.Count).SequenceEqual(segments); | ||
} | ||
|
||
private bool IsParent(string candidate) | ||
{ | ||
string[] candidateSegments = Segmentize(candidate); | ||
|
||
return candidateSegments.SequenceEqual(segments.Take(candidateSegments.Length)); | ||
} | ||
|
||
private static string[] Segmentize(string dottedPath) | ||
{ | ||
return dottedPath.Split(new[] { '.', '[', ']' }, StringSplitOptions.RemoveEmptyEntries); | ||
} | ||
} | ||
} |
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