Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public override void PushDirectory(DirectoryInfoBase directory)
{
// copy the current frame
FrameData frame = Frame;
frame.AddedStemItem = false;

if (IsStackEmpty() || Frame.IsNotApplicable)
{
Expand All @@ -55,6 +56,7 @@ public override void PushDirectory(DirectoryInfoBase directory)
{
frame.InStem = true;
frame.StemItems.Add(directory.Name);
frame.AddedStemItem = true;
}

// directory matches segment, advance position in pattern
Expand All @@ -64,15 +66,28 @@ public override void PushDirectory(DirectoryInfoBase directory)
PushDataFrame(frame);
}

public override void PopDirectory()
{
bool addedStem = Frame.AddedStemItem;
base.PopDirectory();
if (addedStem && Frame.HasStemItems)
{
Frame.StemItems.RemoveAt(Frame.StemItems.Count - 1);
}
}

public struct FrameData
{
public bool IsNotApplicable;
public int SegmentIndex;
public bool InStem;
private IList<string>? _stemItems;
private List<string>? _stemItems;
internal bool AddedStemItem;

public IList<string> StemItems => _stemItems ??= new List<string>();

internal readonly bool HasStemItems => _stemItems is not null && _stemItems.Count > 0;

public string? Stem => _stemItems == null ? null : string.Join("/", _stemItems);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public sealed override void PushDirectory(DirectoryInfoBase directory)
{
// copy the current frame
FrameData frame = Frame;
frame.AddedStemItem = false;

if (IsStackEmpty())
{
Expand Down Expand Up @@ -77,6 +78,7 @@ public sealed override void PushDirectory(DirectoryInfoBase directory)
if (frame.InStem)
{
frame.StemItems.Add(directory.Name);
frame.AddedStemItem = true;
}

while (
Expand All @@ -103,8 +105,9 @@ public sealed override void PushDirectory(DirectoryInfoBase directory)

public override void PopDirectory()
{
bool addedStem = Frame.AddedStemItem;
base.PopDirectory();
if (Frame.StemItems.Count > 0)
if (addedStem && Frame.HasStemItems)
{
Frame.StemItems.RemoveAt(Frame.StemItems.Count - 1);
}
Expand All @@ -124,10 +127,14 @@ public struct FrameData

public bool InStem;

private IList<string>? _stemItems;
private List<string>? _stemItems;

internal bool AddedStemItem;

public IList<string> StemItems => _stemItems ??= new List<string>();

internal readonly bool HasStemItems => _stemItems is not null && _stemItems.Count > 0;

public string? Stem => _stemItems == null ? null : string.Join("/", _stemItems);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -946,5 +946,37 @@ public void VerifyFiles_InMemory_HasCaseSensitiveRootMisses(string matchRoot, st
Assert.False(patternMatchingResult.HasMatches);
Assert.Equal(0, patternMatchingResult.Files.Count());
}

[Fact]
public void StemIsCorrectForMultipleWildcardSiblingDirectories()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT, this tests PatternContextLinear. Shouldn't there be also a test for PatternContextRagged ?

{
var matcher = new Matcher();
matcher.AddInclude("sys*/1*/*.dll");

var files = new[]
{
"system32/1028/VsGraphicsResources.dll",
"system32/1028/vsjitdebuggerui.dll",
"system32/1029/VsGraphicsResources.dll",
"system32/1029/vsjitdebuggerui.dll",
"system32/1031/VsGraphicsResources.dll",
"system32/1031/vsjitdebuggerui.dll",
};

var results = matcher.Match("./", files);

var actual = results.Files.Select(f => f.Stem);
var expected = new[]
{
"system32/1028/VsGraphicsResources.dll",
"system32/1028/vsjitdebuggerui.dll",
"system32/1029/VsGraphicsResources.dll",
"system32/1029/vsjitdebuggerui.dll",
"system32/1031/VsGraphicsResources.dll",
"system32/1031/vsjitdebuggerui.dll",
};

AssertExtensions.CollectionEqual(expected, actual, StringComparer.OrdinalIgnoreCase);
}
}
}
Loading