コード例 #1
0
 [Test] public void ExecuteMakeUsesSymbolInClassName() {
     processor.Get<Symbols>().Save("symbol", "NUnit");
     var executeMake = new ExecuteMake { Processor = processor };
     var input = new SlimTree().AddBranchValue("step").AddBranchValue("make").AddBranchValue("variable").AddBranchValue("fitSharp.Test.$symbol.Slim.SampleClass");
     ExecuteOperation(executeMake, input, 2);
     Assert.IsTrue(processor.Get<SavedInstances>().GetValue("variable") is SampleClass);
 }
コード例 #2
0
 public void ExecuteMakeBadClassReturnsException()
 {
     var executeMake = new ExecuteMake { Processor = processor };
     var input = new SlimTree().AddBranchValue("step").AddBranchValue("make").AddBranchValue("variable").AddBranchValue("garbage");
     ExecuteOperation(executeMake, input, 2);
     CheckForException("message:<<NO_CLASS garbage>>");
 }
コード例 #3
0
 [Test] public void ExecuteCallBadMethodReturnsException() {
     processor.Get<SavedInstances>().Save("variable", new SampleClass());
     var executeCall = new ExecuteCall { Processor = processor };
     var input = new SlimTree().AddBranchValue("step").AddBranchValue("call").AddBranchValue("variable").AddBranchValue("garbage");
     ExecuteOperation(executeCall, input, 2);
     CheckForException("message:<<NO_METHOD_IN_CLASS garbage fitSharp.Test.NUnit.Slim.SampleClass>>");
 }
コード例 #4
0
 public void ExecuteImportAddsNamespace()
 {
     var executeImport = new ExecuteImport { Processor = processor };
     var input = new SlimTree().AddBranchValue("step").AddBranchValue("import").AddBranchValue("fitSharp.Test.NUnit.Slim");
     ExecuteOperation(executeImport, input, 2);
     Assert.IsTrue(processor.Create("SampleClass", new SlimTree()).Value is SampleClass);
 }
コード例 #5
0
 public void ExecuteDefaultReturnsException()
 {
     var executeDefault = new ExecuteDefault { Processor = processor };
     var input = new SlimTree().AddBranchValue("step").AddBranchValue("garbage");
     ExecuteOperation(executeDefault, input, 2);
     CheckForException("message:<<MALFORMED_INSTRUCTION step,garbage>>");
 }
コード例 #6
0
 public void ExecuteCallUsesDomainAdapter()
 {
     processor.Store(new SavedInstance("variable", new SampleClass()));
     var executeCall = new ExecuteCall { Processor = processor };
     var input = new SlimTree().AddBranchValue("step").AddBranchValue("call").AddBranchValue("variable").AddBranchValue("DomainMethod");
     ExecuteOperation(executeCall, input, 2);
     Assert.AreEqual("domainstuff", result.Branches[1].Value);
 }
コード例 #7
0
 [Test] public void ExecuteMakeUsesSymbolAsObject() {
     var newClass = new SampleClass();
     processor.Get<Symbols>().Save("symbol", newClass);
     var executeMake = new ExecuteMake { Processor = processor };
     var input = new SlimTree().AddBranchValue("step").AddBranchValue("make").AddBranchValue("variable").AddBranchValue("$symbol");
     ExecuteOperation(executeMake, input, 2);
     Assert.AreEqual(newClass, processor.Get<SavedInstances>().GetValue("variable"));
 }
コード例 #8
0
        private void MakeSampleClass(string sampleData)
        {
            var executeMake = new ExecuteMake {
                Processor = processor
            };
            var input = new SlimTree().AddBranchValue("step").AddBranchValue("make").AddBranchValue("scriptTableActor").AddBranchValue("fitSharp.Test.NUnit.Slim.SampleClass").AddBranchValue(sampleData);

            ExecuteOperation(executeMake, input, 2);
        }
コード例 #9
0
        private void CallActorMethod(string methodName)
        {
            var executeCall = new ExecuteCall {
                Processor = processor
            };
            var input = new SlimTree().AddBranchValue("step").AddBranchValue("call").AddBranchValue("scriptTableActor").AddBranchValue(methodName);

            ExecuteOperation(executeCall, input, 2);
        }
コード例 #10
0
ファイル: Interpreter.cs プロジェクト: GibSral/fitsharp
 private Tree<string> ExecuteInstructions(Tree<string> instructions) {
     var results = new SlimTree();
     foreach (Tree<string> statement in instructions.Branches) {
         var result = processor.Invoke(new SlimInstruction(), new MemberName(string.Empty), statement).GetValue<Tree<string>>();
         results.AddBranchValue(result);
         if (ComposeException.WasAborted(result.ValueAt(1))) break;
     }
     return results;
 }
コード例 #11
0
 [Test] public void ExecuteCallAndAssignSavesSymbol() {
     processor.Get<SavedInstances>().Save("variable", new SampleClass());
     var executeCallAndAssign = new ExecuteCallAndAssign { Processor = processor };
     var input =
         new SlimTree().AddBranchValue("step").AddBranchValue("callAndAssign").AddBranchValue("symbol").AddBranchValue(
             "variable").AddBranchValue("sampleMethod");
     ExecuteOperation(executeCallAndAssign, input, 2);
     Assert.AreEqual("testresult", result.ValueAt(1));
     Assert.AreEqual("testresult", processor.Get<Symbols>().GetValue("symbol"));
 }
コード例 #12
0
 [Test] public void ExecuteMakeLibraryIsStacked() {
     var executeMake = new ExecuteMake { Processor = processor };
     var input = new SlimTree().AddBranchValue("step").AddBranchValue("make").AddBranchValue("librarystuff").AddBranchValue("fitSharp.Test.NUnit.Slim.SampleClass");
     ExecuteOperation(executeMake, input, 2);
     foreach (TypedValue libraryInstance in processor.LibraryInstances) {
         Assert.IsTrue(libraryInstance.Value is SampleClass);
         return;
     }
     Assert.Fail();
 }
コード例 #13
0
        protected static Tree <string> ParameterTree(Tree <string> input, int startingIndex)
        {
            var result = new SlimTree();

            for (int i = startingIndex; i < input.Branches.Count; i++)
            {
                result.AddBranch(input.Branches[i]);
            }
            return(result);
        }
コード例 #14
0
        [Test] public void ExecuteDefaultReturnsException()
        {
            var executeDefault = new ExecuteDefault {
                Processor = processor
            };
            var input = new SlimTree().AddBranchValue("step").AddBranchValue("garbage");

            ExecuteOperation(executeDefault, input, 2);
            CheckForException("message:<<MALFORMED_INSTRUCTION step,garbage>>");
        }
コード例 #15
0
ファイル: ServiceTest.cs プロジェクト: x97mdr/fitsharp
        [Test] public void OperatorIsAddedFromConfiguration()
        {
            var configuration = new Configuration();

            configuration.LoadXml("<config><fitSharp.Slim.Service.Service><addOperator>fitSharp.Test.NUnit.Slim.SampleOperator</addOperator></fitSharp.Slim.Service.Service></config>");
            var statement = new SlimTree().AddBranchValue("step").AddBranchValue("sampleCommand");
            var result    = new Service(configuration).Execute(TypedValue.Void, statement).GetValue <Tree <string> >();

            Assert.AreEqual("sampleResult", result.Branches[1].Value);
        }
コード例 #16
0
        [Test] public void ExecuteMakeBadClassReturnsException()
        {
            var executeMake = new ExecuteMake {
                Processor = processor
            };
            var input = new SlimTree().AddBranchValue("step").AddBranchValue("make").AddBranchValue("variable").AddBranchValue("garbage");

            ExecuteOperation(executeMake, input, 2);
            CheckForException("message:<<NO_CLASS garbage>>");
        }
コード例 #17
0
        [Test] public void ExecuteMakeUsesSymbolAsFullClassName()
        {
            processor.Get <Symbols>().Save("symbol", "fitSharp.Test.NUnit.Slim.SampleClass");
            var executeMake = new ExecuteMake {
                Processor = processor
            };
            var input = new SlimTree().AddBranchValue("step").AddBranchValue("make").AddBranchValue("variable").AddBranchValue("$symbol");

            ExecuteOperation(executeMake, input, 2);
            Assert.IsTrue(processor.Get <SavedInstances>().GetValue("variable") is SampleClass);
        }
コード例 #18
0
        [Test] public void ExecuteCallUsesDomainAdapter()
        {
            processor.Store(new SavedInstance("variable", new SampleClass()));
            var executeCall = new ExecuteCall {
                Processor = processor
            };
            var input = new SlimTree().AddBranchValue("step").AddBranchValue("call").AddBranchValue("variable").AddBranchValue("DomainMethod");

            ExecuteOperation(executeCall, input, 2);
            Assert.AreEqual("domainstuff", result.Branches[1].Value);
        }
コード例 #19
0
        public Tree <string> Compose(TypedValue instance)
        {
            var list = instance.Value as IList ?? new List <object>();
            var tree = new SlimTree();

            foreach (object value in list)
            {
                tree.AddBranch(Processor.Compose(value));
            }
            return(tree);
        }
コード例 #20
0
 public void ExecuteCallOnMissingInstanceUsesLibrary()
 {
     var executeMake = new ExecuteMake { Processor = processor };
     var input = new SlimTree().AddBranchValue("step").AddBranchValue("make").AddBranchValue("librarystuff").AddBranchValue("fitSharp.Test.NUnit.Slim.SampleClass");
     ExecuteOperation(executeMake, input, 2);
     var executeCall = new ExecuteCall { Processor = processor };
     input = new SlimTree().AddBranchValue("step").AddBranchValue("call").AddBranchValue("garbage").AddBranchValue("SampleMethod");
     SampleClass.MethodCount = 0;
     ExecuteOperation(executeCall, input, 2);
     Assert.AreEqual(1, SampleClass.MethodCount);
 }
コード例 #21
0
        [Test] public void ExecuteMakeUsesSymbolInClassName()
        {
            processor.Store(new Symbol("symbol", "NUnit"));
            var executeMake = new ExecuteMake {
                Processor = processor
            };
            var input = new SlimTree().AddBranchValue("step").AddBranchValue("make").AddBranchValue("variable").AddBranchValue("fitSharp.Test.$symbol.Slim.SampleClass");

            ExecuteOperation(executeMake, input, 2);
            Assert.IsTrue(processor.Load(new SavedInstance("variable")).Instance is SampleClass);
        }
コード例 #22
0
 public void ExecuteCallAndAssignSavesSymbol()
 {
     processor.Store(new SavedInstance("variable", new SampleClass()));
     var executeCallAndAssign = new ExecuteCallAndAssign { Processor = processor };
     var input =
         new SlimTree().AddBranchValue("step").AddBranchValue("callAndAssign").AddBranchValue("symbol").AddBranchValue(
             "variable").AddBranchValue("sampleMethod");
     ExecuteOperation(executeCallAndAssign, input, 2);
     Assert.AreEqual("testresult", result.Branches[1].Value);
     Assert.AreEqual("testresult", processor.Load(new Symbol("symbol")).Instance);
 }
コード例 #23
0
        static SlimTree ReadList(DelimitedString input)
        {
            var count  = int.Parse(input.ReadTo(":"));
            var result = new SlimTree();

            for (var i = 0; i < count; i++)
            {
                var itemLength = int.Parse(input.ReadTo(":"));
                result.AddBranch(Read(input.Read(itemLength, 1)));
            }
            return(result);
        }
コード例 #24
0
        [Test] public void ExecuteMakeUsesSymbolAsObject()
        {
            var newClass = new SampleClass();

            processor.Store(new Symbol("symbol", newClass));
            var executeMake = new ExecuteMake {
                Processor = processor
            };
            var input = new SlimTree().AddBranchValue("step").AddBranchValue("make").AddBranchValue("variable").AddBranchValue("$symbol");

            ExecuteOperation(executeMake, input, 2);
            Assert.AreEqual(newClass, processor.Load(new SavedInstance("variable")).Instance);
        }
コード例 #25
0
        [Test] public void ExecuteCallAndAssignSavesSymbol()
        {
            processor.Store(new SavedInstance("variable", new SampleClass()));
            var executeCallAndAssign = new ExecuteCallAndAssign {
                Processor = processor
            };
            var input =
                new SlimTree().AddBranchValue("step").AddBranchValue("callAndAssign").AddBranchValue("symbol").AddBranchValue(
                    "variable").AddBranchValue("sampleMethod");

            ExecuteOperation(executeCallAndAssign, input, 2);
            Assert.AreEqual("testresult", result.Branches[1].Value);
            Assert.AreEqual("testresult", processor.Load(new Symbol("symbol")).Instance);
        }
コード例 #26
0
        public void ExecuteAssignSavesSymol()
        {
            processor.Get <SavedInstances>().Save("variable", new SampleClass());
            var executeAssign = new ExecuteAssign {
                Processor = processor
            };
            var input =
                new SlimTree().AddBranchValue("step").AddBranchValue("assign").AddBranchValue("symbol").AddBranchValue(
                    "value");

            ExecuteOperation(executeAssign, input, 2);
            Assert.AreEqual("OK", result.ValueAt(1));
            Assert.AreEqual("value", processor.Get <Symbols>().GetValue("symbol"));
        }
コード例 #27
0
ファイル: Interpreter.cs プロジェクト: x97mdr/fitsharp
        private Tree <string> ExecuteInstructions(Tree <string> instructions)
        {
            var results = new SlimTree();

            foreach (Tree <string> statement in instructions.Branches)
            {
                var result = processor.Execute(statement).GetValue <Tree <string> >();
                results.AddBranchValue(result);
                if (ComposeException.WasAborted(result.Branches[1].Value))
                {
                    break;
                }
            }
            return(results);
        }
コード例 #28
0
        [Test] public void ExecuteMakeLibraryIsStacked()
        {
            var executeMake = new ExecuteMake {
                Processor = processor
            };
            var input = new SlimTree().AddBranchValue("step").AddBranchValue("make").AddBranchValue("librarystuff").AddBranchValue("fitSharp.Test.NUnit.Slim.SampleClass");

            ExecuteOperation(executeMake, input, 2);
            foreach (TypedValue libraryInstance in processor.LibraryInstances)
            {
                Assert.IsTrue(libraryInstance.Value is SampleClass);
                return;
            }
            Assert.Fail();
        }
コード例 #29
0
        [Test] public void ExecuteCallOnMissingInstanceUsesLibrary()
        {
            var executeMake = new ExecuteMake {
                Processor = processor
            };
            var input = new SlimTree().AddBranchValue("step").AddBranchValue("make").AddBranchValue("librarystuff").AddBranchValue("fitSharp.Test.NUnit.Slim.SampleClass");

            ExecuteOperation(executeMake, input, 2);
            var executeCall = new ExecuteCall {
                Processor = processor
            };

            input = new SlimTree().AddBranchValue("step").AddBranchValue("call").AddBranchValue("garbage").AddBranchValue("SampleMethod");
            SampleClass.MethodCount = 0;
            ExecuteOperation(executeCall, input, 2);
            Assert.AreEqual(1, SampleClass.MethodCount);
        }
コード例 #30
0
ファイル: ParseList.cs プロジェクト: PinetNicolas/fitsharp
        public TypedValue Parse(Type type, TypedValue instance, Tree <string> parameters)
        {
            var values = parameters.IsLeaf ? SlimTree.Parse(parameters.Value) : parameters;

            if (type.IsArray)
            {
                var array = Array.CreateInstance(type.GetElementType(), values.Branches.Count);
                int i     = 0;
                foreach (var branch in values.Branches)
                {
                    array.SetValue(Processor.ParseTree(type.GetElementType(), branch).Value, i);
                    i++;
                }
                return(new TypedValue(array));
            }
            return(new TypedValue(
                       values.Branches.Aggregate(
                           (IList)Activator.CreateInstance(type),
                           (list, branch) => {
                list.Add(Processor.ParseTree(type.GetGenericArguments()[0], branch).Value);
                return list;
            })));
        }
コード例 #31
0
 private void MakeSampleClass(string sampleData)
 {
     var executeMake = new ExecuteMake { Processor = processor };
     var input = new SlimTree().AddBranchValue("step").AddBranchValue("make").AddBranchValue("scriptTableActor").AddBranchValue("fitSharp.Test.NUnit.Slim.SampleClass").AddBranchValue(sampleData);
     ExecuteOperation(executeMake, input, 2);
 }
コード例 #32
0
 private void CallActorMethod(string methodName)
 {
     var executeCall = new ExecuteCall { Processor = processor };
     var input = new SlimTree().AddBranchValue("step").AddBranchValue("call").AddBranchValue("scriptTableActor").AddBranchValue(methodName);
     ExecuteOperation(executeCall, input, 2);
 }
コード例 #33
0
ファイル: Interpreter.cs プロジェクト: vaibhavsapre/fitsharp
 private Tree<string> ExecuteInstructions(Tree<string> instructions)
 {
     var results = new SlimTree();
     foreach (Tree<string> statement in instructions.Branches) {
         var result = processor.Execute(statement).GetValue<Tree<string>>();
         results.AddBranchValue(result);
         if (ComposeException.WasAborted(result.Branches[1].Value)) break;
     }
     return results;
 }