Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix language with spaces giving wrong results [#1607] #2038

Merged
merged 4 commits into from
Nov 13, 2019
Merged
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
20 changes: 10 additions & 10 deletions Octokit.Tests/Clients/SearchClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,13 @@ public void TestingTheLanguageQualifier()
{
var connection = Substitute.For<IApiConnection>();
var client = new SearchClient(connection);
//get users who have mostly repos where language is Ruby
//get users who have mostly repos where language is Literate Haskell
var request = new SearchUsersRequest("github");
request.Language = Language.Ruby;
request.Language = Language.LiterateHaskell;
client.SearchUsers(request);
connection.Received().Get<SearchUsersResult>(
Arg.Is<Uri>(u => u.ToString() == "search/users"),
Arg.Is<Dictionary<string, string>>(d => d["q"] == "github+language:Ruby"));
Arg.Is<Dictionary<string, string>>(d => d["q"] == "github+language:\"Literate Haskell\""));
}

[Fact]
Expand Down Expand Up @@ -462,12 +462,12 @@ public void TestingTheLangaugeQualifier()
{
var connection = Substitute.For<IApiConnection>();
var client = new SearchClient(connection);
//get repos who's language is Ruby
//get repos who's language is Literate Haskell
var request = new SearchRepositoriesRequest("github");
request.Language = Language.Ruby;
request.Language = Language.LiterateHaskell;
client.SearchRepo(request);
connection.Received().Get<SearchRepositoryResult>(Arg.Is<Uri>(u => u.ToString() == "search/repositories"),
Arg.Is<Dictionary<string, string>>(d => d["q"] == "github+language:ruby"));
Arg.Is<Dictionary<string, string>>(d => d["q"] == "github+language:\"Literate Haskell\""));
}

[Fact]
Expand Down Expand Up @@ -986,13 +986,13 @@ public void TestingTheLanguageQualifier()
var connection = Substitute.For<IApiConnection>();
var client = new SearchClient(connection);
var request = new SearchIssuesRequest("something");
request.Language = Language.CSharp;
request.Language = Language.LiterateHaskell;

client.SearchIssues(request);

connection.Received().Get<SearchIssuesResult>(
Arg.Is<Uri>(u => u.ToString() == "search/issues"),
Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+language:CSharp"));
Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+language:\"Literate Haskell\""));
}

[Fact]
Expand Down Expand Up @@ -1682,13 +1682,13 @@ public void TestingTheLanguageQualifier()
var connection = Substitute.For<IApiConnection>();
var client = new SearchClient(connection);
var request = new SearchCodeRequest("something");
request.Language = Language.CSharp;
request.Language = Language.LiterateHaskell;

client.SearchCode(request);

connection.Received().Get<SearchCodeResult>(
Arg.Is<Uri>(u => u.ToString() == "search/code"),
Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+language:CSharp"));
Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+language:\"Literate Haskell\""));
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion Octokit.Tests/Models/SearchIssuesRequestExclusionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void HandlesLanguageAttributeCorrectly()

request.Language = Language.CSharp;

Assert.Contains("-language:CSharp", request.MergedQualifiers());
Assert.Contains("-language:\"CSharp\"", request.MergedQualifiers());
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion Octokit.Tests/Models/SearchIssuesRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void HandlesLanguageAttributeCorrectly()
Assert.DoesNotContain(request.MergedQualifiers(), x => x.Contains("language:"));

request.Language = Language.CSharp;
Assert.Contains("language:CSharp", request.MergedQualifiers());
Assert.Contains("language:\"CSharp\"", request.MergedQualifiers());
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion Octokit.Tests/Models/SearchRepositoryRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void LanguageUsesParameterTranslation()
{
var request = new SearchRepositoriesRequest() { Language = Language.CPlusPlus };
var result = request.MergedQualifiers();
Assert.Contains(result, x => string.Equals(x, "language:cpp"));
Assert.Contains(result, x => string.Equals(x, "language:\"cpp\""));
}
}
}
2 changes: 1 addition & 1 deletion Octokit/Models/Request/SearchCodeRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public override IReadOnlyList<string> MergedQualifiers()

if (Language != null)
{
parameters.Add(string.Format(CultureInfo.InvariantCulture, "language:{0}", Language.ToParameter()));
parameters.Add(string.Format(CultureInfo.InvariantCulture, "language:\"{0}\"", Language.ToParameter()));
}

if (Forks != null)
Expand Down
2 changes: 1 addition & 1 deletion Octokit/Models/Request/SearchIssuesRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public override IReadOnlyList<string> MergedQualifiers()

if (Language != null)
{
parameters.Add(string.Format(CultureInfo.InvariantCulture, "language:{0}", Language.ToParameter()));
parameters.Add(string.Format(CultureInfo.InvariantCulture, "language:\"{0}\"", Language.ToParameter()));
}

if (Is != null)
Expand Down
2 changes: 1 addition & 1 deletion Octokit/Models/Request/SearchIssuesRequestExclusions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public IReadOnlyList<string> MergedQualifiers()

if (Language != null)
{
parameters.Add(string.Format(CultureInfo.InvariantCulture, "-language:{0}", Language.ToParameter()));
parameters.Add(string.Format(CultureInfo.InvariantCulture, "-language:\"{0}\"", Language.ToParameter()));
}

if (Status.HasValue)
Expand Down
2 changes: 1 addition & 1 deletion Octokit/Models/Request/SearchRepositoriesRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public override IReadOnlyList<string> MergedQualifiers()

if (Language != null)
{
parameters.Add(string.Format(CultureInfo.InvariantCulture, "language:{0}", Language.ToParameter()));
parameters.Add(string.Format(CultureInfo.InvariantCulture, "language:\"{0}\"", Language.ToParameter()));
}

if (User.IsNotBlank())
Expand Down
2 changes: 1 addition & 1 deletion Octokit/Models/Request/SearchUsersRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public override IReadOnlyList<string> MergedQualifiers()

if (Language != null)
{
parameters.Add(string.Format(CultureInfo.InvariantCulture, "language:{0}", Language));
parameters.Add(string.Format(CultureInfo.InvariantCulture, "language:\"{0}\"", Language.ToParameter()));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually found that this part didn't use to Parameter so named languages such as CPlusPlus was parsed as "CPlusPlus" instead of "cpp"

}

if (Created != null)
Expand Down