For some reason, this test utilizing InlineData
fails in xUnit:
[Theory]
[InlineData("\uD800", 1)]
public static void HasLength(string s, int length)
{
Assert.Equal(length, s.Length);
}
while this, which uses MemberData
, passes:
public static IEnumerable<object[]> HasLength_TestData()
{
yield return new object[] { "\uD800", 1 };
}
[Theory]
[MemberData(nameof(HasLength_TestData))]
public static void HasLength(string s, int length)
{
Assert.Equal(length, s.Length);
}
What is the reason for this? Have I discovered a bug in xUnit.net? (I think it may have something to do with the fact that \uD800
is a surrogate character, and it's somehow getting translated to 2 characters when passing thru InlineData
. Not sure why, though.)