Skip to content

Commit

Permalink
Add tests for #55 and #56.
Browse files Browse the repository at this point in the history
  • Loading branch information
rpaquay committed Feb 10, 2020
1 parent 9972c25 commit b966d1b
Showing 1 changed file with 104 additions and 12 deletions.
116 changes: 104 additions & 12 deletions src/Tests/ServerProcess/TestSearchFilePaths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,38 @@ public void WildcardWorks() {
VerifySearchFilePathsResponse(_server, searchPattern, _testFile.Directory, fileName, 3);
}

[TestMethod]
public void DoubleQuotesWorks() {
const string fileName = "";
const string searchPattern = "\"present_three_times.txt\"";

VerifySearchFilePathsResponse(_server, searchPattern, _testFile.Directory, fileName, 0);
}

[TestMethod]
public void ImplicitWildcardWorks() {
const string fileName = "";
const string searchPattern = "readme";

VerifySearchFilePathsResponse(_server, searchPattern, _testFile.Directory, fileName, 2);
}

[TestMethod]
public void ImplicitWildcardAndExlusionWorks() {
const string fileName = "";
const string searchPattern = "-readme";

VerifySearchFilePathsResponse(_server, searchPattern, _testFile.Directory, fileName, 9);
}

[TestMethod]
public void DoubleQuotesAndExlusionWorks() {
const string fileName = "";
const string searchPattern = "-\"readme\"";

VerifySearchFilePathsResponse(_server, searchPattern, _testFile.Directory, fileName, 11);
}

[TestMethod]
public void SemiColonSeparatorWithWildcardWorks() {
const string searchPattern = "*.txt;*.py";
Expand All @@ -63,19 +95,75 @@ public void SemiColonSeparatorWithWildcardWorks() {
}

[TestMethod]
public void SemiColonSeparatorWithPartialNamesWorks() {
public void SemiColonSeparatorWithImplicitWildcardWorks() {
const string searchPattern = ".txt;.py";
const string fileName = "";

VerifySearchFilePathsResponse(_server, searchPattern, _testFile.Directory, fileName, 9);
}

[TestMethod]
public void SemiColonSeparatorSingleDoubleQuotesWorks() {
const string searchPattern = ".txt;\".py\"";
const string fileName = "";

VerifySearchFilePathsResponse(_server, searchPattern, _testFile.Directory, fileName, 8);
}

[TestMethod]
public void SemiColonSeparatorSingleDoubleQuotes2Works() {
const string searchPattern = "\".txt\";.py";
const string fileName = "";

VerifySearchFilePathsResponse(_server, searchPattern, _testFile.Directory, fileName, 1);
}

[TestMethod]
public void SemiColonSeparatorDoubleQuotesWorks() {
const string searchPattern = "\".txt\";\".py\"";
const string fileName = "";

VerifySearchFilePathsResponse(_server, searchPattern, _testFile.Directory, fileName, 0);
}

[TestMethod]
public void SemiColonSeparatorWithExclusionWorks() {
const string searchPattern = ".txt;.py;-presubmit";
const string fileName = "";

VerifySearchFilePathsResponse(_server, searchPattern, _testFile.Directory, fileName, 8);
}

[TestMethod]
public void SemiColonSeparatorWithExclusionsOnlyWorks() {
const string searchPattern = "-presubmit;-readme";
const string fileName = "";

VerifySearchFilePathsResponse(_server, searchPattern, _testFile.Directory, fileName, 8);
}

[TestMethod]
public void SemiColonSeparatorWithExclusionAndIncludingDoubleQuotesWorks() {
const string searchPattern = ".txt;.py;-\"presubmit.py\"";
const string fileName = "";

VerifySearchFilePathsResponse(_server, searchPattern, _testFile.Directory, fileName, 8);
}

[TestMethod]
public void SemiColonSeparatorWithExclusionAndExcludingDoubleQuotesWorks() {
const string searchPattern = ".txt;.py;-\"presubmit\"";
const string fileName = "";

VerifySearchFilePathsResponse(_server, searchPattern, _testFile.Directory, fileName, 9);
}

private static void VerifySearchFilePathsResponse(
ITypedRequestProcessProxy server,
string searchPattern,
DirectoryInfo chromiumDirectory,
string fileName,
int occurrenceCount) {
string expectedFileName,
int expectedOccurrenceCount) {
var response = SendRequest<SearchFilePathsResponse>(server, new SearchFilePathsRequest {
SearchParams = new SearchParams {
SearchString = searchPattern,
Expand All @@ -86,15 +174,19 @@ private static void VerifySearchFilePathsResponse(
Assert.IsNotNull(response.SearchResult);
Assert.IsNotNull(response.SearchResult.Entries);

Assert.AreEqual(1, response.SearchResult.Entries.Count);
var chromiumEntry = response.SearchResult.Entries[0] as DirectoryEntry;
Assert.IsNotNull(chromiumEntry);
Assert.AreEqual(chromiumDirectory.FullName, chromiumEntry.Name);

chromiumEntry.Entries.ForAll(x => Debug.WriteLine(string.Format("File name: \"{0}\"", x.Name)));
Assert.AreEqual(occurrenceCount, chromiumEntry.Entries.Count);
if (fileName != "") {
Assert.AreEqual(occurrenceCount, chromiumEntry.Entries.Count(x => Path.GetFileName(x.Name) == fileName));
if (expectedOccurrenceCount == 0) {
Assert.AreEqual(0, response.SearchResult.Entries.Count);
} else {
Assert.AreEqual(1, response.SearchResult.Entries.Count);
var chromiumEntry = response.SearchResult.Entries[0] as DirectoryEntry;
Assert.IsNotNull(chromiumEntry);
Assert.AreEqual(chromiumDirectory.FullName, chromiumEntry.Name);

chromiumEntry.Entries.ForAll(x => Debug.WriteLine(string.Format("File name: \"{0}\"", x.Name)));
Assert.AreEqual(expectedOccurrenceCount, chromiumEntry.Entries.Count);
if (expectedFileName != "") {
Assert.AreEqual(expectedOccurrenceCount, chromiumEntry.Entries.Count(x => Path.GetFileName(x.Name) == expectedFileName));
}
}
}
}
Expand Down

0 comments on commit b966d1b

Please sign in to comment.