-
Notifications
You must be signed in to change notification settings - Fork 325
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
Support escaping , in Test filter #1374
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c0a0705
Adding Category to Test Category mapping for ListFullyQualifiedTests
dcc12e8
Merge branch 'master' into users/nigurr/Fix_Nunit_Xunit_filter
437c527
support for Escaping test cases with comma
da0b940
Fix project
14538c8
Merge branch 'master' of https://github.com/microsoft/vstest
990c114
Merge branch 'master' into master
41c4aeb
UTs
88ed8da
Merge branch 'master' of https://github.com/nigurr/vstest
1b7279f
UTs
c341a56
review comments
6e6014c
Merge branch 'master' into master
18e6683
CRC
7b31bd5
Merge branch 'master' of https://github.com/nigurr/vstest
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.VisualStudio.TestPlatform.Utilities | ||
{ | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
public static class StringExtensions | ||
{ | ||
public static IEnumerable<string> Tokenize(this string input, char separator, char escape) | ||
{ | ||
if (string.IsNullOrEmpty(input)) yield break; | ||
|
||
var buffer = new StringBuilder(); | ||
var escaping = false; | ||
foreach (var c in input) | ||
{ | ||
if (escaping) | ||
{ | ||
buffer.Append(c); | ||
escaping = false; | ||
} | ||
else if (c == escape) | ||
{ | ||
escaping = true; | ||
} | ||
else if (c == separator) | ||
{ | ||
yield return buffer.Flush(); | ||
} | ||
else | ||
{ | ||
buffer.Append(c); | ||
} | ||
} | ||
if (buffer.Length > 0 || input[input.Length - 1] == separator) yield return buffer.Flush(); | ||
} | ||
|
||
private static string Flush(this StringBuilder stringBuilder) | ||
{ | ||
var result = stringBuilder.ToString(); | ||
stringBuilder.Clear(); | ||
return result; | ||
} | ||
} | ||
} |
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
98 changes: 98 additions & 0 deletions
98
test/Microsoft.TestPlatform.Utilities.UnitTests/StringUtilitiesTests.cs
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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Linq; | ||
|
||
namespace Microsoft.TestPlatform.Utilities.UnitTests | ||
{ | ||
using Castle.Core.Internal; | ||
using Microsoft.VisualStudio.TestPlatform.Utilities; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
[TestClass] | ||
public class StringUtilitiesTests | ||
{ | ||
[TestMethod] | ||
public void SplitShouldReturnWhenStringisNullOrEmpty() | ||
{ | ||
var argsList = string.Empty.Tokenize(SplitChar, EscapeChar); | ||
|
||
Assert.IsTrue(argsList.IsNullOrEmpty()); | ||
} | ||
|
||
[TestMethod] | ||
public void SplitShouldReturnWhenStringDoesntContainSplitChar() | ||
{ | ||
var data = "foobar"; | ||
var argsList = data.Tokenize(SplitChar, EscapeChar); | ||
var enumerable = argsList as string[] ?? argsList.ToArray(); | ||
|
||
Assert.IsTrue(enumerable.Length == 1); | ||
Assert.IsTrue(enumerable.First().Equals(data)); | ||
} | ||
|
||
[TestMethod] | ||
public void SplitShouldSplitWhenStringContainsSplitChar() | ||
{ | ||
var data = "foo,bar"; | ||
var argsList = data.Tokenize(SplitChar, EscapeChar); | ||
var enumerable = argsList as string[] ?? argsList.ToArray(); | ||
|
||
Assert.IsTrue(enumerable.Length == 2); | ||
} | ||
|
||
[TestMethod] | ||
public void SplitShouldSplitWhenStringWithSplitCharStartEnd() | ||
{ | ||
var data = ",foo,bar,"; | ||
var argsList = data.Tokenize(SplitChar, EscapeChar); | ||
var enumerable = argsList as string[] ?? argsList.ToArray(); | ||
|
||
Assert.IsTrue(enumerable.Length == 4); | ||
} | ||
|
||
[TestMethod] | ||
public void SplitShouldEscapeSplitCharWhenEscapedCharPresent() | ||
{ | ||
var data = "foo\\,bar"; | ||
var argsList = data.Tokenize(SplitChar, EscapeChar); | ||
var enumerable = argsList as string[] ?? argsList.ToArray(); | ||
|
||
Assert.IsTrue(enumerable.Length == 1); | ||
Assert.IsTrue(enumerable.First().Equals("foo,bar")); | ||
} | ||
|
||
[TestMethod] | ||
public void SplitShouldEscapeSplitCharWhenEscapedNonEscapedCharPresent() | ||
{ | ||
var data = "foo\\,,bar"; | ||
var argsList = data.Tokenize(SplitChar, EscapeChar); | ||
var enumerable = argsList as string[] ?? argsList.ToArray(); | ||
Assert.IsTrue(enumerable.Length == 2); | ||
Assert.IsTrue(enumerable.First().Equals("foo,")); | ||
} | ||
|
||
[TestMethod] | ||
public void SplitShouldSplitWhenOnlySplitCharPresent() | ||
{ | ||
var data = ","; | ||
var argsList = data.Tokenize(SplitChar, EscapeChar); | ||
var enumerable = argsList as string[] ?? argsList.ToArray(); | ||
|
||
Assert.IsTrue(enumerable.Length == 2); | ||
} | ||
|
||
[TestMethod] | ||
public void SplitShouldNotSplitWhenNoSplitCharPresent() | ||
{ | ||
var data = "foo\\bar"; | ||
var argsList = data.Tokenize(SplitChar, EscapeChar); | ||
var enumerable = argsList as string[] ?? argsList.ToArray(); | ||
|
||
Assert.IsTrue(enumerable.Length == 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we use SequenceEqual instead or have another assert? just length check isn't good. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in the cases where we required. |
||
} | ||
|
||
private const char SplitChar = ','; | ||
private const char EscapeChar = '\\'; | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is already vstest/src/Microsoft.TestPlatform.CoreUtilities/Utilities/StringExtensions.cs
Can we move this there ?