<commit_before>﻿// Copyright © 2010 Syterra Software Inc. All rights reserved.
// The use and distribution terms for this software are covered by the Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
// which can be found in the file license.txt at the root of this distribution. By using this software in any fashion, you are agreeing
// to be bound by the terms of this license. You must not remove this notice, or any other, from this software.

using fitSharp.Fit.Engine;
using fitSharp.Fit.Model;
using fitSharp.Machine.Engine;
using fitSharp.Machine.Model;
using fitSharp.Samples.Fit;
using NUnit.Framework;

namespace fitSharp.Test.NUnit.Fit {
    [TestFixture] public class CellProcessorBaseTest {
        [Test] public void CachesParsedValue() {
            var cell = new CellTreeLeaf("<<symbol");
            var processor = Builder.CellProcessor();
            processor.Get<Symbols>().Save("symbol", "value");
            TypedValue result = processor.Parse(typeof (string), TypedValue.Void, cell);
            Assert.AreEqual("value", result.GetValue<string>());
            Assert.AreEqual(" value", cell.Value.GetAttribute(CellAttribute.InformationSuffix));
            processor.Parse(typeof (string), TypedValue.Void, cell);
            Assert.AreEqual(" value", cell.Value.GetAttribute(CellAttribute.InformationSuffix));
            Assert.AreEqual("value", result.GetValue<string>());
        }

        [Test] public void WrapsValue() {
            var processor = Builder.CellProcessor();
            var result = processor.Operate<WrapOperator>(new TypedValue("hi"));
            Assert.AreEqual("hi", result.ValueString);
        }
    }
}<commit_msg>test a custom create operator<commit_after>﻿// Copyright © 2010 Syterra Software Inc. All rights reserved.
// The use and distribution terms for this software are covered by the Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
// which can be found in the file license.txt at the root of this distribution. By using this software in any fashion, you are agreeing
// to be bound by the terms of this license. You must not remove this notice, or any other, from this software.

using fitSharp.Fit.Engine;
using fitSharp.Fit.Model;
using fitSharp.Fit.Operators;
using fitSharp.Machine.Engine;
using fitSharp.Machine.Model;
using fitSharp.Samples.Fit;
using NUnit.Framework;

namespace fitSharp.Test.NUnit.Fit {
    [TestFixture] public class CellProcessorBaseTest {
        [Test] public void CachesParsedValue() {
            var cell = new CellTreeLeaf("<<symbol");
            var processor = Builder.CellProcessor();
            processor.Get<Symbols>().Save("symbol", "value");
            TypedValue result = processor.Parse(typeof (string), TypedValue.Void, cell);
            Assert.AreEqual("value", result.GetValue<string>());
            Assert.AreEqual(" value", cell.Value.GetAttribute(CellAttribute.InformationSuffix));
            processor.Parse(typeof (string), TypedValue.Void, cell);
            Assert.AreEqual(" value", cell.Value.GetAttribute(CellAttribute.InformationSuffix));
            Assert.AreEqual("value", result.GetValue<string>());
        }

        [Test] public void WrapsValue() {
            var processor = Builder.CellProcessor();
            var result = processor.Operate<WrapOperator>(new TypedValue("hi"));
            Assert.AreEqual("hi", result.ValueString);
        }

        [Test] public void UsesCreateOperator() {
            var processor = Builder.CellProcessor();
            processor.AddOperator(new TestCreateOperator());
            var result = processor.Create("testname");
            Assert.AreEqual("mytestname", result.GetValueAs<string>());
        }

        class TestCreateOperator: CellOperator, CreateOperator<Cell> {
            public bool CanCreate(NameMatcher memberName, Tree<Cell> parameters) {
                return memberName.Matches("testname");
            }

            public TypedValue Create(NameMatcher memberName, Tree<Cell> parameters) {
                return new TypedValue("mytestname");
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.10825242718446602, 'fraction_numerical': 0.002912621359223301, 'mean_word_length': 3.060098522167488, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 15, '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': '4039546', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1055, 'n_words': 313}