stryker-net icon indicating copy to clipboard operation
stryker-net copied to clipboard

List pattern syntax mutation

Open richardwerkman opened this issue 8 months ago • 0 comments

Is your feature request related to a problem? Please describe. The following code (in the switch expression) should be mutated but is not:

    public void ListPatterns()
    {
        decimal balance = 0m;
        string[][] transactions = new[]
        {
            new[] { "1", "DEPOSIT", "100.00" },
        };
        foreach (string[] transaction in transactions)
        {
            balance += transaction switch
            {
            // "DEPOSIT" should be mutated here
            [_, "DEPOSIT", _, var amount] => decimal.Parse(amount),
            [_, "WITHDRAWAL", .., var amount] => -decimal.Parse(amount),
            [_, "INTEREST", var amount] => decimal.Parse(amount),
            [_, "FEE", var fee] => -decimal.Parse(fee),
                _ => throw new InvalidOperationException($"Record {string.Join(", ", transaction)} is not in the expected format!"),
            };
            Console.WriteLine($"Record: {string.Join(", ", transaction)}, New balance: {balance:C}");
        }
    }

Describe the solution you'd like We should introduce a new orchestrator for the syntax type ListPatternSyntax.

richardwerkman avatar Jun 07 '24 12:06 richardwerkman