<commit_before>﻿using System;

namespace TestFirst.Net {

    /// <summary>
    /// Conveneince class to use when usign matchers outside of a scenario
    /// </summary>
    public static class Expect {
        
        /// <summary>
        /// Build an expect with a label which is useful in loops when you want to know what the loop value was.
        /// 
        /// Usage:
        ///     
        /// foreach(var x in bar){
        ///     Expect.For(x)  -- this is simply printed on failure, not used for matching
        ///         .That(Something(x))
        ///         .Is(AFoo.With()...);
        /// }
        /// </summary>
        /// <param name="label"></param>
        /// <returns></returns>
        public ExpectWithLabel For(Object label)
        {
            return new ExpectWithLabel(label);
        }

        /// <summary>
        /// Helper method to make using matchers outside of scenarios easier and cleaner
        /// 
        /// Usage:
        /// var x = Foo();
        /// Expect.That(x)
        ///     .Is(AFoo.With()...)
        ///     
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="actual"></param>
        /// <returns></returns>
        public static Expect<T> That<T>(T actual) {
            return new Expect<T>(actual);
        }
    }
    
    public class ExpectWithLabel
    {
        private readonly Object m_label;

        internal ExpectWithLabel(Object label)
        {
            m_label = label;
        }

        public Expect<T> That<T>(T actual)
        {
            return new Expect<T>(actual);
        }

    }
    public class Expect<T> {
        private readonly T m_actual;

        public Expect(T actual) {
            m_actual = actual;
        }

        public void Is(IMatcher<T> matcher) {
            AssertMatches(matcher);
        }

        public void Is<TNull>(IMatcher<TNull?> matcher) 
        where TNull : struct, T
        {
            AssertMatches(matcher);
        }

        public void And(IMatcher<T> matcher) {
            AssertMatches(matcher);
        }

        public void And<TNull>(IMatcher<TNull?> matcher)
        where TNull : struct, T
        {
            AssertMatches(matcher);
        }

        private void AssertMatches(IMatcher<T> matcher) {
            var diag = new MatchDiagnostics();
            if (!matcher.Matches(m_actual, diag))
            {
                GenerateAndThrowFailMsg(matcher, diag);
            }
        }

        private void AssertMatches<TNull>(IMatcher<TNull?> matcher)
        where TNull : struct, T
        {
            var diag = new MatchDiagnostics();
            if (!matcher.Matches(m_actual, diag)) 
            {
                GenerateAndThrowFailMsg(matcher, diag);
            }
        }

        private void GenerateAndThrowFailMsg(IMatcher matcher, MatchDiagnostics diag)
        {
            var desc = new Description();

            desc.Child("expected", matcher);
            desc.Child("but was", m_actual);
            desc.Text("==== Diagnostics ====");
            desc.Child(diag);
            TestFirstAssert.Fail(Environment.NewLine + desc.ToString());
        }
    }
}<commit_msg>make Expect.For static<commit_after>﻿using System;

namespace TestFirst.Net {

    /// <summary>
    /// Conveneince class to use when usign matchers outside of a scenario
    /// </summary>
    public static class Expect {
        
        /// <summary>
        /// Build an expect with a label which is useful in loops when you want to know what the loop value was.
        /// 
        /// Usage:
        ///     
        /// foreach(var x in bar){
        ///     Expect.For(x)  -- this is simply printed on failure, not used for matching
        ///         .That(Something(x))
        ///         .Is(AFoo.With()...);
        /// }
        /// </summary>
        /// <param name="label"></param>
        /// <returns></returns>
        public static ExpectWithLabel For(Object label)
        {
            return new ExpectWithLabel(label);
        }

        /// <summary>
        /// Helper method to make using matchers outside of scenarios easier and cleaner
        /// 
        /// Usage:
        /// var x = Foo();
        /// Expect.That(x)
        ///     .Is(AFoo.With()...)
        ///     
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="actual"></param>
        /// <returns></returns>
        public static Expect<T> That<T>(T actual) {
            return new Expect<T>(actual);
        }
    }
    
    public class ExpectWithLabel
    {
        private readonly Object m_label;

        internal ExpectWithLabel(Object label)
        {
            m_label = label;
        }

        public Expect<T> That<T>(T actual)
        {
            return new Expect<T>(actual);
        }

    }
    public class Expect<T> {
        private readonly T m_actual;

        public Expect(T actual) {
            m_actual = actual;
        }

        public void Is(IMatcher<T> matcher) {
            AssertMatches(matcher);
        }

        public void Is<TNull>(IMatcher<TNull?> matcher) 
        where TNull : struct, T
        {
            AssertMatches(matcher);
        }

        public void And(IMatcher<T> matcher) {
            AssertMatches(matcher);
        }

        public void And<TNull>(IMatcher<TNull?> matcher)
        where TNull : struct, T
        {
            AssertMatches(matcher);
        }

        private void AssertMatches(IMatcher<T> matcher) {
            var diag = new MatchDiagnostics();
            if (!matcher.Matches(m_actual, diag))
            {
                GenerateAndThrowFailMsg(matcher, diag);
            }
        }

        private void AssertMatches<TNull>(IMatcher<TNull?> matcher)
        where TNull : struct, T
        {
            var diag = new MatchDiagnostics();
            if (!matcher.Matches(m_actual, diag)) 
            {
                GenerateAndThrowFailMsg(matcher, diag);
            }
        }

        private void GenerateAndThrowFailMsg(IMatcher matcher, MatchDiagnostics diag)
        {
            var desc = new Description();

            desc.Child("expected", matcher);
            desc.Child("but was", m_actual);
            desc.Text("==== Diagnostics ====");
            desc.Child(diag);
            TestFirstAssert.Fail(Environment.NewLine + desc.ToString());
        }
    }
}
{'fraction_non_alphanumeric': 0.12037899968934451, 'fraction_numerical': 0.0, 'mean_word_length': 1.4492202358311146, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 67, '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': '4190767', 'n_tokens_mistral': 1778, 'n_tokens_neox': 1722, 'n_words': 431}