I have a method I am trying to test
public static string BySpace(string s, int position)
{
return s.Split()[position];
}
I have a test function around it
[Theory]
[InlineData("a b c d")]
[InlineData(" a b c d")]
[InlineData("a b c d ")]
[InlineData("a b c d")]
[InlineData(" a b c d ")]
public void TestParseToList(string s)
{
Assert.Equal("a", Util.BySpace(s, 0));
Assert.Equal("b", Util.BySpace(s, 1));
Assert.Equal("c", Util.BySpace(s, 2));
Assert.Equal("d", Util.BySpace(s, 3));
}
A bunch of inline data tests fail. As can be seen i am playing with Space & Tab.
Desired effect: Take a string and split it by any white space
What am i missing please? How can I take a string and split it by space
I tried all of the below to no avail
// return s.Split()[position];
// return s.Split(' ')[position];
// return s.Split("\\s+")[position]; <----- i had high hopes for this one
// return s.Split(null)[position];
// return s.Split(new char[0])[position];
creturn s.Split(new char[0], StringSplitOptions.RemoveEmptyEntries)[position]);