Skip to content

Commit 6313677

Browse files
author
Sergei Vorobev
committed
Add unit test for empty query. Replace query with one empty term by empty query on top level
1 parent 3aed54a commit 6313677

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

Jump.Location.Specs/CommandControllerSpec.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,21 @@ public void It_updates_the_database_if_filesystem_is_newer()
291291

292292
fsMock.VerifyAll();
293293
}
294+
295+
[Fact]
296+
public void Empty_query_return_most_popular()
297+
{
298+
dbMock.Setup(x => x.Records).Returns(new[]
299+
{
300+
new Record(@"FS::C:\Users\tkellogg", 10M),
301+
new Record(@"FS::C:\Users\tkellogg2", 13M),
302+
new Record(@"FS::C:\Users\tkellogg3", 15M),
303+
});
304+
305+
var record = controller.GetMatchesForSearchTerm(new string[] {});
306+
record.Select(x => x.Path).ToArray()
307+
.ShouldEqual(new[] { @"C:\Users\tkellogg3", @"C:\Users\tkellogg2", @"C:\Users\tkellogg" });
308+
}
294309

295310
}
296311
}

Jump.Location/CommandController.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ private IEnumerable<IRecord> GetMatchesForNormalizedSearchTerm(List<string> sear
109109
{
110110
ReloadIfNecessary();
111111
var matches = new List<IRecord>();
112+
// Hack to return everything on empty search query.
113+
if (!searchTerms.Any())
114+
{
115+
searchTerms.Add("");
116+
}
112117
for (var i = 0; i < searchTerms.Count(); i++)
113118
{
114119
var isLast = i == searchTerms.Count()-1;

Jump.Location/JumpLocationCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ protected override void ProcessRecord()
7777
return;
7878
}
7979

80-
if (Query == null) { Query = new string[] { "" }; }
80+
if (Query == null) { Query = new string[] {}; }
8181

8282
// If last term is absolute path it's probably because of autocomplition
8383
// so and we can safely process it here.
84-
if (Path.IsPathRooted(Query.Last()))
84+
if (Query.Any() && Path.IsPathRooted(Query.Last()))
8585
{
8686
ChangeDirectory(Query.Last());
8787
return;

0 commit comments

Comments
 (0)