<commit_before>using System;
using System.Text;
using NUnit.Framework;

namespace TestFirst.Net.Test
{
    [TestFixture]
    public class MatchDiagnosticsTest
    {
        private static readonly String Indent = Description.Indent;

        [Test]
        public void AppendMatchedFieldTest()
        {
            var diag = new MatchDiagnostics()
                .Matched(Description.With().Value("on field","field1").Value("actual","fieldValue1"))
                .Matched(Description.With().Value("on field","field2").Value("actual","fieldValue2"))
                .ToString();

            var expect = new StringBuilder();
            expect.AppendLine("Match");
            expect.AppendLine(Indent + "on field:field1");
            expect.AppendLine(Indent + "actual:fieldValue1");
            expect.AppendLine("Match");
            expect.AppendLine(Indent + "on field:field2");
            expect.AppendLine(Indent + "actual:fieldValue2");

            AssertEquals(expect.ToString(), diag);
        }

        [Test]
        public void TryMatchPassTest()
        {
            var diag = new MatchDiagnostics();
            var matcher = new MyMatcher("MyValue");
            var matched = diag.TryMatch("MyValue", "MyProperty", matcher);

            Assert.IsTrue(matched, "Expected matcher to match");

            var expect = new StringBuilder();
            expect.AppendLine("Match");
            expect.AppendLine(Indent + "named:MyProperty");
            expect.AppendLine(Indent + "Equals:MyValue");
            AssertEquals(expect.ToString(), diag.ToString());
        }

        [Test]
        public void TryMatchNestedPassTest()
        {
            var diag = new MatchDiagnostics();

            var childMatcher = new MyMatcher("MyValue");
            var rootMatcher = new MyNestedMatcher<string>(childMatcher);
            var matched = diag.TryMatch("MyValue", "MyProperty", rootMatcher);

            Assert.IsTrue(matched, "Expected matcher to match");

            var expect = new StringBuilder();
            expect.AppendLine("Match");
            expect.AppendLine(Indent + "named:MyProperty");
            expect.AppendLine(Indent + "matches:");
            expect.AppendLine(Indent + Indent + "Equals:MyValue");

            AssertEquals(expect.ToString(), diag.ToString());
        }

        [Test]
        public void TryMatchFailTest()
        {
            var diag = new MatchDiagnostics();
            var matcher = new MyMatcher("MyValue");
            var matched = diag.TryMatch("MyWrongValue", "MyProperty", matcher);

            Assert.IsFalse(matched, "Expected matcher to _not_ match");

            var expect = new StringBuilder();
            expect.AppendLine("Mismatch!");
            expect.AppendLine(Indent + "named:MyProperty");
            expect.AppendLine(Indent + "matcherType:" + matcher.GetType());
            expect.AppendLine(Indent + "expect:" );
            expect.AppendLine(Indent + Indent + "Equals:MyValue" );
            expect.AppendLine(Indent + "but was:" );
            expect.AppendLine(Indent + Indent + "MyWrongValue" );
            expect.AppendLine(Indent + "Mismatch!");
            expect.AppendLine(Indent + Indent + "expected:MyValue");
            expect.AppendLine(Indent + Indent + "actual:MyWrongValue");


            AssertEquals(expect.ToString(), diag.ToString());
        }

        private void AssertEquals(String expect, String actual)
        {<commit_msg>Fix failing test<commit_after>using System;
using System.Text;
using NUnit.Framework;

namespace TestFirst.Net.Test
{
    [TestFixture]
    public class MatchDiagnosticsTest
    {
        private static readonly String Indent = Description.Indent;

        [Test]
        public void AppendMatchedFieldTest()
        {
            var diag = new MatchDiagnostics()
                .Matched(Description.With().Value("on field","field1").Value("actual","fieldValue1"))
                .Matched(Description.With().Value("on field","field2").Value("actual","fieldValue2"))
                .ToString();

            var expect = new StringBuilder();
            expect.AppendLine("Match");
            expect.AppendLine(Indent + "on field:field1");
            expect.AppendLine(Indent + "actual:fieldValue1");
            expect.AppendLine("Match");
            expect.AppendLine(Indent + "on field:field2");
            expect.AppendLine(Indent + "actual:fieldValue2");

            AssertEquals(expect.ToString(), diag);
        }

        [Test]
        public void TryMatchPassTest()
        {
            var diag = new MatchDiagnostics();
            var matcher = new MyMatcher("MyValue");
            var matched = diag.TryMatch("MyValue", "MyProperty", matcher);

            Assert.IsTrue(matched, "Expected matcher to match");

            var expect = new StringBuilder();
            expect.AppendLine("Match");
            expect.AppendLine(Indent + "named:MyProperty");
            expect.AppendLine(Indent + "Equals:MyValue");
            AssertEquals(expect.ToString(), diag.ToString());
        }

        [Test]
        public void TryMatchNestedPassTest()
        {
            var diag = new MatchDiagnostics();

            var childMatcher = new MyMatcher("MyValue");
            var rootMatcher = new MyNestedMatcher<string>(childMatcher);
            var matched = diag.TryMatch("MyValue", "MyProperty", rootMatcher);

            Assert.IsTrue(matched, "Expected matcher to match");

            var expect = new StringBuilder();
            expect.AppendLine("Match");
            expect.AppendLine(Indent + "named:MyProperty");
            expect.AppendLine(Indent + "matches:");
            expect.AppendLine(Indent + Indent + "Equals:MyValue");

            AssertEquals(expect.ToString(), diag.ToString());
        }

        [Test]
        public void TryMatchFailTest()
        {
            var diag = new MatchDiagnostics();
            var matcher = new MyMatcher("MyValue");
            var matched = diag.TryMatch("MyWrongValue", "MyProperty", matcher);

            Assert.IsFalse(matched, "Expected matcher to _not_ match");

            var expect = new StringBuilder();
            expect.AppendLine("Mismatch!");
            expect.AppendLine(Indent + "named:MyProperty");
            expect.AppendLine(Indent + "matcherType:" + matcher.GetType());
            expect.AppendLine(Indent + "expected:" );
            expect.AppendLine(Indent + Indent + "Equals:MyValue" );
            expect.AppendLine(Indent + "but was (string,length 12,quoted):" );
            expect.AppendLine(Indent + Indent + "'MyWrongValue'" );
            expect.AppendLine(Indent + "Mismatch!");
            expect.AppendLine(Indent + Indent + "expected:MyValue");
            expect.AppendLine(Indent + Indent + "actual:MyWrongValue");


            AssertEquals(expect.ToString(), diag.ToString());
        }

        private void AssertEquals(String expect, String actual)
        {
{'fraction_non_alphanumeric': 0.12203876525484565, 'fraction_numerical': 0.0025843503230437905, 'mean_word_length': 2.2873997168475695, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6635712', 'n_tokens_mistral': 1810, 'n_tokens_neox': 1757, 'n_words': 368}