예제 #1
0
        [Test] public void CachesParsedValue()
        {
            var cell      = new CellTreeLeaf("<<symbol");
            var processor = new CellProcessorBase();

            processor.Store(new Symbol("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>());
        }
예제 #2
0
        [Test] public void StructWithParseAndConstructorIsParsed()
        {
            TypedValue result = parse.Parse(typeof(StructWithParseAndConstructor), TypedValue.Void, new TreeList <string>("stuff"));

            Assert.IsTrue(result.Value is StructWithParseAndConstructor);
            Assert.AreEqual("stuffparsector", result.GetValue <StructWithParseAndConstructor>().stuff);
        }
예제 #3
0
        private bool Parse(string validString)
        {
            Assert.IsTrue(parseBoolean.CanParse(typeof(bool), TypedValue.Void, TestUtils.CreateCell(validString)));
            TypedValue result = parseBoolean.Parse(typeof(bool), TypedValue.Void, TestUtils.CreateCell(validString));

            return(result.GetValue <bool>());
        }
예제 #4
0
        public bool Compare(TypedValue actual, Tree <Cell> expected)
        {
            var cell    = (Parse)expected.Value;
            var matcher = new ListMatcher(Processor, new ArrayMatchStrategy(Processor, cell.Parts.Parts));

            return(matcher.IsEqual(actual.GetValue <IEnumerable>().Cast <object>(), cell));
        }
예제 #5
0
 public override void DoRow(Parse row)
 {
     if (row.Parts.Size != rowWidth)
     {
         TestStatus.MarkException(row.Parts, new RowWidthException(rowWidth));
     }
     else
     {
         try {
             TypedValue result = CellOperation.Invoke(this, memberNameCells,
                                                      valueCells.GetCells(new CellRange(row.Parts).Cells), row.Parts);
             if (result.Type != typeof(bool))
             {
                 throw new InvalidMethodException(string.Format("Method does not return boolean."));
             }
             if (result.GetValue <bool>() == expectedCondition)
             {
                 TestStatus.MarkRight(row);
             }
             else
             {
                 TestStatus.MarkWrong(row);
             }
         }
         catch (ParseException <Cell> e) {
             TestStatus.MarkException(e.Subject, e.InnerException);
         }
     }
 }
 public override void DoRow(Parse row)
 {
     if (row.Parts.Size != rowWidth)
     {
         TestStatus.MarkException(row.Parts, new RowWidthException(rowWidth));
     }
     else
     {
         try {
             TypedValue result = Processor.ExecuteWithThrow(this, memberNameCells,
                                                            valueCells.GetCells(row.Branches), row.Parts);
             if (result.Type != typeof(bool))
             {
                 throw new InvalidMethodException("Method does not return boolean.");
             }
             if (result.GetValue <bool>() == expectedCondition)
             {
                 TestStatus.MarkRight(row);
             }
             else
             {
                 TestStatus.MarkWrong(row);
             }
         }
         catch (ParseException <Cell> e) {
             TestStatus.MarkException(e.Subject, e.InnerException);
         }
     }
 }
예제 #7
0
        private static bool IsMemberMissing(TypedValue result)
        {
            if (result.IsValid)
            {
                return(false);
            }
            var exception = result.GetValue <System.Exception>();

            return(exception != null && exception is MemberMissingException);
        }
예제 #8
0
        private bool Parse(string validString)
        {
            if (!parseBoolean.CanParse(typeof(bool), TypedValue.Void, TestUtils.CreateCell(validString)))
            {
                return(false);
            }

            TypedValue result = parseBoolean.Parse(typeof(bool), TypedValue.Void, TestUtils.CreateCell(validString));

            return(result.GetValue <bool>());
        }
        public Tree <Cell> Compose(TypedValue instance)
        {
            var showAs = instance.GetValue <ComposeShowAsOperator>();
            var result = Processor.Compose(showAs.source);

            foreach (var cellAttribute in showAs.attributes)
            {
                result.Value.SetAttribute(cellAttribute, string.Empty);
            }
            return(result);
        }
예제 #10
0
            /// <summary>
            /// Build an XML document part for this node.
            /// </summary>
            internal void BuildTree(Stack <XContainer> documentStack)
            {
                var value = RawValue;

                if ((value == null) && (TypedValue != null))
                {
                    value = TypedValue.GetValue(tree);
                }
                var attr = new XAttribute(XName, value ?? string.Empty);

                documentStack.Peek().Add(attr);
            }
예제 #11
0
 private static bool IsStopTestException(TypedValue instance)
 {
     for (var exception = instance.GetValue <System.Exception>();
          exception != null;
          exception = exception.InnerException)
     {
         if (exception.GetType().Name.Contains("StopTest"))
         {
             return(true);
         }
     }
     return(false);
 }
예제 #12
0
        private void ExecuteOperation(InvokeOperator <string> executeOperator, Tree <string> input, int branchCount)
        {
            TypedValue executeResult = TypedValue.Void;

            if (executeOperator.CanInvoke(new TypedValue(new SlimInstruction()), string.Empty, input))
            {
                executeResult = executeOperator.Invoke(new TypedValue(new SlimInstruction()), string.Empty, input);
            }
            result = executeResult.GetValue <Tree <string> >();
            Assert.IsFalse(result.IsLeaf);
            Assert.AreEqual(branchCount, result.Branches.Count);
            Assert.AreEqual("step", result.Branches[0].Value);
        }
예제 #13
0
        private void ExecuteOperation(ExecuteOperator <string> executeOperator, Tree <string> input, int branchCount)
        {
            TypedValue executeResult = TypedValue.Void;

            if (executeOperator.CanExecute(TypedValue.Void, input))
            {
                executeResult = executeOperator.Execute(TypedValue.Void, input);
            }
            result = executeResult.GetValue <Tree <string> >();
            Assert.IsFalse(result.IsLeaf);
            Assert.AreEqual(branchCount, result.Branches.Count);
            Assert.AreEqual("step", result.Branches[0].Value);
        }
        public TypedValue InvokeSpecial(TypedValue instance, MemberName memberName, Tree <Cell> parameters)
        {
            var cell = parameters.Branches[0];

            // lookup Fixture
            foreach (var member in FindMember(instance.Value, memberName, typeof(Parse)).Value)
            {
                cell.Value.SetAttribute(CellAttribute.Syntax, CellAttributeValue.SyntaxKeyword);
                return(member.Invoke(new object[] { cell.Value }));
            }

            // lookup FlowKeywords
            return(keywords[memberName.Name](instance.GetValue <FlowInterpreter>(), (Parse)cell.Value));
        }
 bool TryParse(Type type, string expected)
 {
     try {
         if (parseDate.CanParse(type, TypedValue.Void, new CellTreeLeaf(expected)))
         {
             TypedValue returnValue = parseDate.Parse(type, TypedValue.Void, new CellTreeLeaf(expected));
             result = returnValue.GetValue <DateTime>();
             return(true);
         }
         return(false);
     }
     catch (Exception e) {
         exceptionMessage = e.InnerException.Message;
         return(false);
     }
 }
예제 #16
0
        public TypedValue Wrap(TypedValue result)
        {
            if (!result.HasValue)
            {
                return(result);
            }
            if (result.Type.IsPrimitive)
            {
                return(result);
            }
            if (result.Type == typeof(string))
            {
                return(result);
            }
            var wrapInterpreter = result.GetValueAs <Interpreter>();

            if (wrapInterpreter != null)
            {
                return(result);
            }
            if (typeof(IEnumerable <object>).IsAssignableFrom(result.Type))
            {
                return(MakeInterpreter("fitlibrary.ArrayFixture", typeof(IEnumerable <object>), result.Value));
            }
            if (typeof(IDictionary).IsAssignableFrom(result.Type))
            {
                return(MakeInterpreter("fitlibrary.SetFixture", typeof(IEnumerable), result.GetValue <IDictionary>().Values));
            }
            if (typeof(DataTable).IsAssignableFrom(result.Type))
            {
                return(MakeInterpreter("fitlibrary.ArrayFixture", typeof(DataTable), result.Value));
            }
            if (typeof(XmlDocument).IsAssignableFrom(result.Type))
            {
                return(MakeInterpreter("fitlibrary.XmlFixture", typeof(XmlDocument), result.Value));
            }
            if (typeof(IEnumerable).IsAssignableFrom(result.Type))
            {
                return(MakeInterpreter("fitlibrary.ArrayFixture", typeof(IEnumerable), result.Value));
            }
            if (typeof(IEnumerator).IsAssignableFrom(result.Type))
            {
                return(MakeInterpreter("fitlibrary.ArrayFixture", typeof(IEnumerator), result.Value));
            }
            return(MakeInterpreter(ParseInterpreter.DefaultFlowInterpreter, typeof(object), result.Value));
        }
예제 #17
0
 public TypedValue Wrap(TypedValue result) {
     if (!result.HasValue) return result;
     if (result.Type.IsPrimitive) return result;
     if (result.Type == typeof(string)) return result;
     var wrapInterpreter = result.GetValueAs<Interpreter>();
     if (wrapInterpreter != null) return result;
     if (typeof (IEnumerable<object>).IsAssignableFrom(result.Type))
         return MakeInterpreter("fitlibrary.ArrayFixture", typeof(IEnumerable<object>), result.Value);
     if (typeof (IDictionary).IsAssignableFrom(result.Type))
         return MakeInterpreter("fitlibrary.SetFixture", typeof(IEnumerable), result.GetValue<IDictionary>().Values);
     if (typeof (DataTable).IsAssignableFrom(result.Type))
         return MakeInterpreter("fitlibrary.ArrayFixture", typeof(DataTable), result.Value);
     if (typeof (XmlDocument).IsAssignableFrom(result.Type))
         return MakeInterpreter("fitlibrary.XmlFixture", typeof(XmlDocument), result.Value);
     if (typeof (IEnumerable).IsAssignableFrom(result.Type))
         return MakeInterpreter("fitlibrary.ArrayFixture", typeof(IEnumerable), result.Value);
     if (typeof (IEnumerator).IsAssignableFrom(result.Type))
         return MakeInterpreter("fitlibrary.ArrayFixture", typeof(IEnumerator), result.Value);
     return MakeInterpreter(ParseInterpreter.DefaultFlowInterpreter, typeof (object), result.Value);
 }
        public bool Compare(TypedValue actual, Tree <Cell> expected)
        {
            if (actual.IsValid)
            {
                return(false);
            }

            var actualException  = actual.GetValue <System.Exception>();
            var exceptionContent = expected.Value.Text.Substring("exception[".Length, expected.Value.Text.Length - ("exception[".Length + 1));

            if (IsMessageOnly(exceptionContent))
            {
                return(actualException.Message == exceptionContent.Substring(1, exceptionContent.Length - 2));
            }
            if (IsExceptionTypeNameOnly(exceptionContent))
            {
                var actualContent = actualException.GetType().Name + ": \"" + actualException.Message + "\"";
                return(exceptionContent == actualContent);
            }
            return(actualException.GetType().Name == exceptionContent);
        }
예제 #19
0
        public override TypedValue Execute(ExecuteContext context, ExecuteParameters parameters)
        {
            TypedValue actualValue = GetTypedActual(context, parameters);

            var    cell        = (Parse)parameters.Cell;
            var    expected    = new FixtureTable(cell.Parts);
            var    tables      = actualValue.GetValue <Parse>();
            var    actual      = new FixtureTable(tables);
            string differences = actual.Differences(expected);

            if (differences.Length == 0)
            {
                Processor.TestStatus.MarkRight(parameters.Cell);
            }
            else
            {
                Processor.TestStatus.MarkWrong(parameters.Cell, differences);
                cell.More = new Parse("td", string.Empty, tables, null);
            }
            return(TypedValue.Void);
        }
예제 #20
0
 public TypedValue InvokeSpecial(TypedValue instance, MemberName memberName, Tree<Cell> parameters)
 {
     return keywords[memberName.Name](instance.GetValue<FlowInterpreter>(), parameters);
 }
예제 #21
0
        public bool Compare(TypedValue actual, Tree <Cell> expected)
        {
            var matcher = new ListMatcher(Processor, new ArrayMatchStrategy(Processor, expected.Branches[0].Branches[0]));

            return(matcher.IsEqual(actual.GetValue <IEnumerable>().Cast <object>(), expected));
        }
 public TypedValue InvokeSpecial(TypedValue instance, MemberName memberName, Tree <Cell> parameters)
 {
     return(keywords[memberName.Name](instance.GetValue <FlowInterpreter>(), parameters));
 }
예제 #23
0
 public TypedValue Execute(TypedValue instance, Tree <Cell> parameters)
 {
     return(Execute(instance.GetValue <ExecuteContext>(), new ExecuteParameters(parameters)));
 }
예제 #24
0
 public bool CanExecute(TypedValue instance, Tree <Cell> parameters)
 {
     return(instance.Type == typeof(ExecuteContext) && CanExecute(instance.GetValue <ExecuteContext>(), new ExecuteParameters(parameters)));
 }
 public bool Compare(TypedValue actual, Tree <Cell> expected)
 {
     string[] parts = expected.Value.Text.Split('.');
     return(IsInRange(actual.GetValue <int>(), LowEnd(parts), HighEnd(parts)));
 }
 public Tree <Cell> Compose(TypedValue instance)
 {
     return(new Parse("td", string.Empty, MakeTable(instance.GetValue <Table>()), null));
 }