-
Notifications
You must be signed in to change notification settings - Fork 205
Add support for UTF8 string literals #2940
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
base: master
Are you sure you want to change the base?
Changes from all commits
705bc66
4430981
b09a3a8
efcfa2f
c73643b
bf247d2
9ac57f4
6841729
54653f8
318b569
5ed4a7f
e8e2a3e
6d7678d
3574f4d
d7d764b
a9fe1a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using ExampleProject.String; | ||
using Xunit; | ||
|
||
namespace ExampleProject.XUnit.String | ||
{ | ||
public class Utf8StringMagicTests | ||
{ | ||
[Fact] | ||
public void AddTwoStrings() | ||
{ | ||
var sut = new Utf8StringMagic(); | ||
var actual = sut.HelloWorld(); | ||
Assert.Equal("Hello World!"u8, actual); | ||
} | ||
|
||
[Fact] | ||
public void IsNullOrEmpty() | ||
{ | ||
var sut = new Utf8StringMagic(); | ||
var actual = sut.IsNullOrEmpty("hello"u8); | ||
Assert.False(actual); | ||
} | ||
|
||
[Fact] | ||
public void IsNullOrEmpty_Empty() | ||
{ | ||
var sut = new Utf8StringMagic(); | ||
var actual = sut.IsNullOrEmpty(""u8); | ||
Assert.True(actual); | ||
} | ||
|
||
[Fact] | ||
public void Referenced() | ||
{ | ||
var sut = new Utf8StringMagic(); | ||
var input = "hello"u8; | ||
sut.Referenced(out input); | ||
Assert.Equal("world"u8, input); | ||
} | ||
|
||
[Fact] | ||
public void ReferencedEmpty() | ||
{ | ||
var sut = new Utf8StringMagic(); | ||
var input = "hello"u8; | ||
sut.ReferencedEmpty(out input); | ||
Assert.Equal(""u8, input); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace ExampleProject.String | ||
{ | ||
public class Utf8StringMagic | ||
{ | ||
public ReadOnlySpan<byte> HelloWorld() | ||
{ | ||
return "Hello"u8 + " "u8 + "World!"u8; | ||
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. I've run the integration test locally and saw this line isn't mutated correctly. The mutation causes compile errors. I think this isn't related to the mutator but related to the mutation placing logic. I'd say we create a separate defect for that. 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. This should be fixed in this PR, not as a separate defect. 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. I've investigated why this test is failing. It fails during mutated code compilation. Stryker by default add ternary expression to each operand: So this statement
is transformed into this:
It boxes each UTF-8 value to Hence, mutated code fails to compile with:
Do you think it's worth fixing this bug in current PR? It also touches core
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. Interesting. In that case, we could maybe include some extra code in the compilation that contains an operator overload for
Yes, as this seems like an easy fix we should add to this PR. Otherwise, we risk that this will never be fixed once this PR has been merged. 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. I am not sure adding this operator is needed.
TLDR; |
||
} | ||
|
||
public void Referenced(out ReadOnlySpan<byte> test) | ||
{ | ||
test = "world"u8; | ||
} | ||
|
||
public void ReferencedEmpty(out ReadOnlySpan<byte> test) | ||
{ | ||
test = ""u8; | ||
} | ||
|
||
public bool IsNullOrEmpty(ReadOnlySpan<byte> myString) | ||
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. This has nothing to do with utf8 strings and can be removed |
||
{ | ||
if (myString.IsEmpty) | ||
{ | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.