<commit_before>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using fitSharp.Machine.Engine;
using fitSharp.Machine.Model;
using NUnit.Framework;
using fitSharp.Samples.Fit;
using fitSharp.Fit.Operators;

namespace fitSharp.Test.NUnit.Fit {
    public class ParseOperatorTest<ParseOperatorType>
        where ParseOperatorType : CellOperator, ParseOperator<Cell>, new() {
        ParseOperatorType parser;

        public ParseOperatorTest() {
            // Parse operators are stateless, so no need to use SetUp.
            parser = new ParseOperatorType { Processor = Builder.CellProcessor() };
        }

        protected bool CanParse<T>(string cellContent) {
            return parser.CanParse(typeof(T), TypedValue.Void, new CellTreeLeaf(cellContent));
        }

        protected T Parse<T>(string cellContent) where T : class {
            return Parse<T>(cellContent, TypedValue.Void);
        }

        protected T Parse<T>(string cellContent, TypedValue instance) where T : class {
            TypedValue result = parser.Parse(typeof(string), TypedValue.Void, new CellTreeLeaf(cellContent));
            return result.GetValueAs<T>();
        }
    }
}
<commit_msg>Refactor Expose parse operator to deriving tests. Use [SetUp] attribute to recreate parser for every test.<commit_after>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using fitSharp.Machine.Engine;
using fitSharp.Machine.Model;
using NUnit.Framework;
using fitSharp.Samples.Fit;
using fitSharp.Fit.Operators;

namespace fitSharp.Test.NUnit.Fit {
    public class ParseOperatorTest<ParseOperatorType>
        where ParseOperatorType : CellOperator, ParseOperator<Cell>, new() {

        public ParseOperatorType Parser { get; private set; }

        [SetUp]
        public void SetUp() {
            // Parse operators are stateless, but the processor may be mutated
            // by Parse(), so recreate for every test
            Parser = new ParseOperatorType { Processor = Builder.CellProcessor() };
        }

        protected bool CanParse<T>(string cellContent) {
            return Parser.CanParse(typeof(T), TypedValue.Void, new CellTreeLeaf(cellContent));
        }

        protected T Parse<T>(string cellContent) where T : class {
            return Parse<T>(cellContent, TypedValue.Void);
        }

        protected T Parse<T>(string cellContent, TypedValue instance) where T : class {
            TypedValue result = Parser.Parse(typeof(string), TypedValue.Void, new CellTreeLeaf(cellContent));
            return result.GetValueAs<T>();
        }
    }
}

{'fraction_non_alphanumeric': 0.09229016331181163, 'fraction_numerical': 0.0, 'mean_word_length': 3.0773993808049536, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '6433649', 'n_tokens_mistral': 725, 'n_tokens_neox': 700, 'n_words': 194}