question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add mutation for conditional (ternary) operator

See original GitHub issue

Is your feature request related to a problem? Please describe. I have some code that prefixes a string conditionally:

val = val.Contains(prefix)
       ? val
       : $"{prefix}{val}";

I have a test that checks that some strings without that prefix get prefixed, but I do not have any test that checks whether already prefixed strings also get that prefix added. Stryker didn’t find that issue as I expected it to.

Describe the solution you’d like I propose adding two mutations for the conditional (ternary) operator: Original: a ? b : c Mutation 1: b Mutation 2: c

Describe alternatives you’ve considered I can’t think of any.

Additional context None.

Issue Analytics

  • State:open
  • Created 3 months ago
  • Reactions:1
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
psfinakicommented, Jun 30, 2023

Cool stuff!

It took me a while to understand the missing piece here so here is the mutated code that Stryker wouldn’t flag:

  private const string crap = "crap";

  public static string AddImagePrefix(string logo)
  {
      logo = logo.Contains("data:image/jpg;base64,")
          ? crap
          : $"data:image/jpg;base64,{logo}";

      return logo;
  }

Missing tests would be

[Test]
[TestCase("data:image/jpg;base64,")]
[TestCase("blah,data:image/jpg;base64,blah")]
public void AddImageprefix_KeepsInputStringWhenNeeded(string originalString)
{
    // Arrange

    // Act
    var result = AddImagePrefix(originalString);

    // Assert
    result.Should().BeEquivalentTo($"data:image/jpg;base64");
}
1reaction
dupdobcommented, Jun 25, 2023

yes, this will avoid having duplicate/similar mutants

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add mutation for conditional (ternary) operator · Issue #757
I propose adding a mutation for conditional operator: Original Mutated a ? b : c a ? c : b Also, I am...
Read more >
Assigning apollo mutations with a ternary in an onClick?
I am currently having trouble with my login/registration component - a ternary operator is assigned to an onClick handler which dictates whether ...
Read more >
Nested Ternaries are Great
When we force mutation or side-effects with if statements as opposed to ternaries, that often entails adding variables to the mix that don't ......
Read more >
Use the Conditional (Ternary) Operator - Free Code Camp
In this tutorial we use the conditional ternary operator to make our JavaScript cleaner and more efficient. This is one video in a...
Read more >
Use a Ternary Expression for Conditional Rendering - YouTube
In this React tutorial we use a ternary expression for conditional rendering. This video constitutes one part of many where I cover the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found