public TypedValue[] ActualValues(CellProcessor processor, object theActualRow)
 {
     var actuals = (object[]) theActualRow;
     var result = new TypedValue[actuals.Length];
     for (int i = 0; i < actuals.Length; i++) result[i] = new TypedValue(actuals[i]);
     return result;
 }
Пример #2
0
 public TypedValue[] ActualValues(CellProcessor processor, object theActualRow)
 {
     if (myColumnsUsed == null) myColumnsUsed = new bool[myHeaderRow.Parts.Size];
     var result = new TypedValue[myHeaderRow.Parts.Size];
     int column = 0;
     foreach (Parse headerCell in new CellRange(myHeaderRow.Parts).Cells) {
         TypedValue memberResult = new CellOperationImpl(processor).TryInvoke(theActualRow, headerCell);
         if (memberResult.IsValid) {
             result[column] = memberResult;
             myColumnsUsed[column] = true;
         }
         else {
             TypedValue itemResult = new CellOperationImpl(processor).TryInvoke(theActualRow,
                                                          new StringCellLeaf("getitem"),
                                                          new CellRange(headerCell, 1));
             if (itemResult.IsValid) {
                 result[column] = itemResult;
                 myColumnsUsed[column] = true;
             }
             else {
                 result[column] = TypedValue.Void;
             }
         }
         column++;
     }
     return result;
 }
Пример #3
0
        public object Evaluate(DomainAdapter theFixture, CellProcessor processor) {
            cells.ValueAt(0).SetAttribute(CellAttribute.Syntax, CellAttributeValue.SyntaxKeyword);

            var cellCount = cells.Branches.Count;
            if (cellCount < 2) throw MakeException("missing cells");
            var identifier = cells.ValueAt(1).Text;
            if (newIdentifier.Equals(identifier)) {
                cells.ValueAt(1).SetAttribute(CellAttribute.Syntax, CellAttributeValue.SyntaxKeyword);
                return new MethodPhrase(cells.Skip(1)).EvaluateNew(processor);
            }
            if (typeIdentifier.Equals(identifier)) {
                cells.ValueAt(1).SetAttribute(CellAttribute.Syntax, CellAttributeValue.SyntaxKeyword);
                if (cellCount < 3) throw MakeException("missing cells");
                cells.ValueAt(2).SetAttribute(CellAttribute.Syntax, CellAttributeValue.SyntaxSUT);
                return processor.ParseTree(typeof (Type), cells.Branches[2]).Value;
            }
            if (currentIdentifier.Equals(identifier)) {
                cells.ValueAt(1).SetAttribute(CellAttribute.Syntax, CellAttributeValue.SyntaxKeyword);
                return theFixture.SystemUnderTest;
            }
            var fixture = theFixture as FlowInterpreter;
            if (fixture == null) throw MakeException("flow fixture required");

            return processor.Get<Symbols>().HasValue(identifier)
                ? processor.Get<Symbols>().GetValue(identifier)
                : fixture.ExecuteFlowRowMethod(processor, cells);
        }
Пример #4
0
 public void Interpret(CellProcessor processor, Tree<Cell> table)
 {
     new Traverse<Cell>()
         .Rows.First(row => selectValue = new ValuePhrase(row).Evaluate(processor))
         .Rows.All(row => SelectRow(processor, row))
         .VisitTable(table);
 }
Пример #5
0
 public static void Evaluate(this Tree<Cell> row, CellProcessor processor)
 {
     var interpreter = processor.CallStack.DomainAdapter.GetValueAs<FlowInterpreter>();
     if (!row.InvokeSpecialAction(processor, interpreter).IsValid) {
         row.ExecuteMethod(processor, interpreter);
     }
 }
Пример #6
0
 public SocketServer(FitSocket socket, CellProcessor service, ProgressReporter reporter, bool suiteSetUpIsAnonymous)
 {
     this.service = service;
     this.reporter = reporter;
     this.socket = socket;
     IMaybeProcessingSuiteSetup = suiteSetUpIsAnonymous;
 }
Пример #7
0
 public static void DoTable(Tree<Cell> table, Interpreter activeFixture, CellProcessor processor, bool inFlow)
 {
     var activeFlowFixture = activeFixture as FlowInterpreter;
     if (activeFlowFixture != null) activeFlowFixture.DoSetUp(processor, table);
     activeFixture.Interpret(processor, table);
     if (activeFlowFixture != null && !inFlow) activeFlowFixture.DoTearDown(table);
 }
Пример #8
0
 public void Interpret(CellProcessor processor, Tree<Cell> table)
 {
     new Traverse<Cell>()
         .Rows.Header(row => headerRow = row)
         .Rows.Rest(row => ComputeRow(processor, row))
         .VisitTable(table);
 }
Пример #9
0
        static Interpreter GetNamedFixture(CellProcessor processor, string theName) {
            if (!processor.Get<Symbols>().HasValue(theName)) return null;

            var result =  processor.Operate<WrapOperator>(new TypedValue(processor.Get<Symbols>().GetValue(theName)));
            result.AsNot<Interpreter>(() => { throw new FitFailureException("Result is not a Fixture."); });
            return result.GetValueAs<Interpreter>();
        }
Пример #10
0
 public object EvaluateNew(CellProcessor processor)
 {
     if (cells.Branches.Count < 2) throw MakeException("missing cells");
     return processor.Create(
             cells.ValueAt(1).Text,
             cells.Skip(2))
         .Value;
 }
Пример #11
0
 public InvokeOperation(CellProcessor processor, TypedValue target, Tree<Cell> member, Tree<Cell> parameters, Tree<Cell> cells)
 {
     this.processor = processor;
     Target = target;
     Member = member;
     Parameters = parameters;
     Cells = cells;
 }
Пример #12
0
 public static TypedValue ExecuteMethod(this Tree<Cell> row, CellProcessor processor, MethodRowSelector selector,
                                        object target)
 {
     return processor.Execute(target,
                 selector.SelectMethodCells(row),
                 selector.SelectParameterCells(row),
                 row.ValueAt(0));
 }
Пример #13
0
 static void Execute(CellProcessor processor, object facility, Tree<Cell> currentRow) {
     var selector = new DoRowSelector();
     var result = processor.ExecuteWithThrow(facility, selector.SelectMethodCells(currentRow),
                                             selector.SelectParameterCells(currentRow),
                                             currentRow.ValueAt(0));
     if (result.IsVoid) return;
     currentRow.ValueAt(0).SetAttribute(CellAttribute.Folded, result.ValueString);
 }
Пример #14
0
 private void RunTest(CellProcessor service, string tables) {
     var socket = new TestSocket();
     socket.PutByteString(Protocol.FormatInteger(tables.Length));
     socket.PutByteString(tables);
     socket.PutByteString(Protocol.FormatInteger(0));
     var server = new SocketServer(new FitSocket(socket, new NullReporter()), service, new NullReporter(), false);
     server.ProcessTestDocuments(new StoryTestStringWriter(service).ForTables(s => resultTables += s));
     Assert.IsFalse(socket.isOpen);
 }
Пример #15
0
 public void Interpret(CellProcessor processor, Tree<Cell> table) {
     var action = new IncludeAction(processor);
     var currentRow = table.Branches[0].Skip(1);
     var selector = new SequenceRowSelector();
     processor.ExecuteWithThrow(action, selector.SelectMethodCells(currentRow),
                                                             selector.SelectParameterCells(currentRow),
                                                             currentRow.ValueAt(0));
     table.ValueAt(0, 0).SetAttribute(CellAttribute.Folded, action.Result);
 }
Пример #16
0
 public TypedValue DoInvoke(CellProcessor processor)
 {
     var targetInstance = new TypedValue(target);
     var targetObjectProvider = target as TargetObjectProvider;
     var name = GetMemberName(processor);
     return processor.Invoke(
             targetObjectProvider != null ? new TypedValue(targetObjectProvider.GetTargetObject()) : targetInstance,
             name, parameters);
 }
Пример #17
0
        public void Interpret(CellProcessor processor, Tree<Cell> table) {
            var firstRow = table.Branches[0];
            if (firstRow.Branches.Count < 2) throw new TableStructureException("Missing cells for use.");

            var fixtureName = firstRow.ValueAt(1).Text;
            var targetFixture = GetNamedFixture(processor, fixtureName)
                ?? MakeNewFixture(processor, firstRow);

            targetFixture.Interpret(processor, table);
        }
Пример #18
0
 void SelectRow(CellProcessor processor, Tree<Cell> row)
 {
     if (processor.Compare(new TypedValue(selectValue), row.Branches[0])) {
         var interpreter = processor.CallStack.DomainAdapter.GetValueAs<FlowInterpreter>();
         new FlowRow(new CellTree(row.Branches.Skip(1))).Evaluate(processor, interpreter);
     }
     else {
         row.Value.SetAttribute(CellAttribute.Status, TestStatus.Ignore);
     }
 }
Пример #19
0
 static Interpreter MakeNewFixture(CellProcessor processor, Tree<Cell> firstRow) {
     var fixture = processor.ParseTree<Cell, Interpreter>(firstRow.Skip(1));
     if (firstRow.Branches.Count > 2) {
         var adapter = fixture as MutableDomainAdapter;
         if (adapter != null) {
             var parent = processor.CallStack.DomainAdapter.GetValueAs<DomainAdapter>();
             adapter.SetSystemUnderTest(new MethodPhrase(firstRow.Skip(2)).Evaluate(parent, processor));
         }
     }
     return fixture;
 }
Пример #20
0
 public static object ExecuteFlowRowMethod(this FlowInterpreter interpreter, CellProcessor processor, Tree<Cell> row)
 {
     try {
         var cells = row.Skip(1);
         return cells.ExecuteMethod(processor, interpreter).ThrowExceptionIfNotValid().Value;
     }
     catch (ParseException<Cell> e) {
         processor.TestStatus.MarkException(e.Subject, e.InnerException);
         throw new IgnoredException();
     }
 }
Пример #21
0
 public void Interpret(CellProcessor processor, Tree<Cell> table)
 {
     processor.TestStatus.TableCount--;
     TypedValue result = processor.Invoke(
         new TypedValue(processor.Configuration.GetItem(table.Branches[0].Branches[1].Value.Text)),
         table.Branches[0].Branches[2].Value.Text,
         new CellTree());
     result.ThrowExceptionIfNotValid();
     if (result.IsVoid) return;
     table.Branches[0].Branches[2].Value.SetAttribute(CellAttribute.Folded, result.ValueString);
 }
Пример #22
0
        void ComputeRow(CellProcessor processor, Tree<Cell> row) {
            var memberName = processor.ParseTree<Cell, MemberName>(headerRow.Branches.Last()).WithNamedParameters();

            var parameterList = new List<Tree<Cell>>();
            for (var i = 0; i < headerRow.Branches.Count - 1; i++) {
                parameterList.Add(new CellTreeLeaf(new GracefulName(headerRow.ValueAt(i).Text).ToString()));
                parameterList.Add(row.Branches[i]);
            }
            var result = processor.Invoke(processor.CallStack.DomainAdapter, memberName, 
                                          new EnumeratedTree<Cell>(parameterList));
            processor.Check(result, row.Branches.Last());
        }
Пример #23
0
        void ComputeRow(CellProcessor processor, Tree<Cell> row)
        {
            var memberName = MemberName.NamedParameterPrefix + processor.ParseTree<Cell, MemberName>(headerRow.Branches.Last());

            var parameterList = new List<Tree<Cell>>();
            for (var i = 0; i < headerRow.Branches.Count - 1; i++) {
                parameterList.Add(new CellTreeLeaf(new GracefulName(headerRow.Branches[i].Value.Text).ToString()));
                parameterList.Add(row.Branches[i]);
            }
            var result = processor.Invoke(new TypedValue(SystemUnderTest), memberName,
                                          new EnumeratedTree<Cell>(parameterList));
            new CellOperationImpl(processor).Check(result, row.Branches.Last());
        }
Пример #24
0
        public void DoTableFlow(CellProcessor processor, FlowInterpreter interpreter, Tree<Cell> table)
        {
            this.interpreter = interpreter;
            this.processor = processor;

            if (processor.TestStatus.IsAbandoned) return;
            hasFinishedTable = false;
            for (var i = 0; i < table.Branches.Count; i++) {
                if (i < rowsToSkip) continue;
                if (hasFinishedTable) break;
                ProcessFlowRow(table, i);
            }
        }
Пример #25
0
 public static TypedValue InvokeSpecialAction(this Tree<Cell> row, CellProcessor processor, FlowInterpreter interpreter)
 {
     var specialActionName = processor.ParseTree<Cell, MemberName>(row.Branches[0]);
     try {
         var result = processor.Operate<InvokeSpecialOperator>(new TypedValue(interpreter), specialActionName, row);
         if (result.IsValid) {
             SetSyntaxKeyword(row);
         }
         return result;
     }
     catch (System.Exception) {
             SetSyntaxKeyword(row);
         throw;
     }
 }
Пример #26
0
 public static object ExecuteFlowRowMethod(this FlowInterpreter interpreter, CellProcessor processor, Tree<Cell> row) {
     try {
         var cells = row.Skip(1);
         return
             processor.ExecuteWithThrow(interpreter,
                     interpreter.MethodRowSelector.SelectMethodCells(cells),
                     interpreter.MethodRowSelector.SelectParameterCells(cells),
                     row.ValueAt(1)).
                 Value;
     }
     catch (ParseException<Cell> e) {
         processor.TestStatus.MarkException(e.Subject, e.InnerException);
         throw new IgnoredException();
     }
 }
Пример #27
0
        public void Evaluate(CellProcessor processor, FlowInterpreter interpreter)
        {
            var specialActionName = processor.ParseTree<Cell, MemberName>(row.Branches[0]);
            var result = processor.Operate<InvokeSpecialOperator>(new TypedValue(interpreter), specialActionName, row.Branches[0]);
            if (result.IsValid) {
                row.ValueAt(0).SetAttribute(CellAttribute.Syntax, CellAttributeValue.SyntaxKeyword);
                return;
            }

            if (!result.IsValid) {
                processor.Execute(interpreter,
                        interpreter.MethodRowSelector.SelectMethodCells(row),
                        interpreter.MethodRowSelector.SelectParameterCells(row),
                        row.ValueAt(0));
            }
        }
Пример #28
0
 public static void SetOption(CellProcessor processor, String name, String value)
 {
     String normalname = NameNormaliser.NormaliseName(name);
     if ("fixedlengthstringparsing".Equals(normalname))
     {
         fixedLengthStringParsing = Boolean.Parse(value);
         if (fixedLengthStringParsing)
             processor.AddOperator(typeof(ParseQuotedString).FullName);
         else
             processor.RemoveOperator(typeof(ParseQuotedString).FullName);
     }
     else if ("bindsymbols".Equals(normalname))
     {
         bindSymbols = Boolean.Parse(value);
     }
     else throw new ApplicationException("Unsupported option" + name);
 }
Пример #29
0
        public void Interpret(CellProcessor processor, Tree<Cell> table)
        {
            processor.TestStatus.TableCount--;

            var facility = processorIdentifier.Matches(table.ValueAt(0, 1).Text)
                ? processor
                : processor.Memory.GetItem(table.ValueAt(0, 1).Text);

            if (table.Branches[0].Branches.Count > 2) {
                var currentRow = table.Branches[0].Skip(2);
                Execute(processor, facility, currentRow);
            }

            new Traverse<Cell>()
                .Rows.All(row => Execute(processor, facility, row))
                .VisitTable(table);
        }
Пример #30
0
 public BindingFactory(CellProcessor processor, MutableDomainAdapter adapter, TargetObjectProvider targetProvider)
 {
     this.processor      = processor;
     this.adapter        = adapter;
     this.targetProvider = targetProvider;
 }
 public void Interpret(CellProcessor processor, Tree <Cell> table)
 {
     processor.TestStatus.TableCount--;
     processor.Get <Symbols>().Clear();
 }
Пример #32
0
 public void Prepare(CellProcessor processor, Tree <Cell> row)
 {
     Processor = processor;
     GetArgsForRow(row);
 }
Пример #33
0
 static Type FindType(CellProcessor processor, string facilityName, string action)
 {
     return(processor.ApplicationUnderTest.FindType(new GracefulNameMatcher(ConfigurationNames.TypeName(facilityName, action))).Type);
 }
Пример #34
0
 public void Interpret(CellProcessor processor, Tree <Cell> table)
 {
     new Traverse <Cell>()
     .All(row => row.Branches.Select(branch => branch.Value).Where(cell => cell.Text == "good").ForEach(cell => processor.TestStatus.MarkRight(cell)))
     .VisitTable(table);
 }
Пример #35
0
 public void Execute(CellProcessor cellProcessor)
 {
     cellProcessor.Operate <RunTestOperator>(ParsedInput, writer);
 }
Пример #36
0
 public SetMatchStrategy(CellProcessor processor, Parse theHeaderRow) : base(processor, theHeaderRow)
 {
 }
Пример #37
0
 public static TypedValue Execute(this CellProcessor processor, object target, Tree <Cell> memberName, Tree <Cell> parameters)
 {
     return(processor.Execute(target, memberName, parameters, new CellBase(string.Empty)));
 }
Пример #38
0
        static async Task Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Blue;

            IExpressionEvaluator _evaluator   = new ExpressionEvaluator();
            IFileService         _fileService = new FileService();
            IValidator           _validator   = new Validator();
            ICellProcessor       _cellService = new CellProcessor();

            Interactions.GreetUser();
            Interactions.AskForFilesCount();
            string filesCount = Console.ReadLine();
            int    filesCountNum;

            while (!_validator.FilesCountIsValid(filesCount, out filesCountNum))
            {
                Interactions.AskForFilesCount();
                filesCount = Console.ReadLine();
            }

            for (int i = 0; i < filesCountNum; i++)
            {
                string filePath, outParameter, formula;

                Interactions.AskForSrcFilePath();
                filePath = Console.ReadLine();
                while (!_validator.FilePathIsValid(filePath))
                {
                    Interactions.AskForSrcFilePath();
                    filePath = Console.ReadLine();
                }

                var fileLines = await File.ReadAllLinesAsync(filePath);

                if (!_validator.FileLinesAreValid(fileLines))
                {
                    return;
                }

                Interactions.AskForOutParameter();
                outParameter = Console.ReadLine();
                while (!_validator.OutParameterIsValid(outParameter))
                {
                    Interactions.AskForOutParameter();
                    outParameter = Console.ReadLine();
                }

                Interactions.AskForFormula();
                formula = Console.ReadLine();
                while (!_validator.FormulaIsValid(formula))
                {
                    Interactions.AskForFormula();
                    formula = Console.ReadLine();
                }

                List <FileLine> lines = _fileService.MapFileLines(fileLines);
                try
                {
                    await Task.Run(() => // cpu-bound operation, better to perform in a separate thread
                    {
                        Parallel.ForEach(lines, l => l.CalculatedValue = _evaluator.EvaluateExpression(formula.ToLower().Replace("x", l.Value.ToString())));
                    });
                }
                catch (FormatException)
                {
                    Console.WriteLine("Wrong formula");
                    return;
                }
                catch (Exception)
                {
                    Console.WriteLine("Something went wrong while evaluating expression");
                }


                if (outParameter.ToLower().Equals("-f"))
                {
                    await _fileService.WriteLinesToFileAsync(filePath, lines); // I/O-bound operation, better to await without Task.Run()

                    Interactions.AnnounceSuccess();
                }
                else
                {
                    foreach (var line in lines)
                    {
                        Console.WriteLine($"{line.LineNumber}: {line.Value}: {line.CalculatedValue}");
                    }
                }
            }

            Console.ReadKey();
        }
Пример #39
0
 public FlowKeywords(FlowInterpreter fixture, CellProcessor processor)
 {
     this.fixture   = fixture;
     this.processor = processor;
 }
Пример #40
0
 public InterpretFlow(CellProcessor processor, FlowInterpreter interpreter)
 {
     this.interpreter = interpreter;
     this.processor   = processor;
 }
Пример #41
0
 public CellMatcher(CellProcessor processor)
 {
     Processor = processor;
 }
Пример #42
0
 public CellOperationImpl(CellProcessor processor)
 {
     this.processor = processor;
 }
Пример #43
0
 public static void Check(this CellProcessor processor, TypedValue actualValue, Tree <Cell> expectedCell)
 {
     processor.Operate <CheckOperator>(
         CellOperationValue.Make(actualValue),
         expectedCell);
 }
Пример #44
0
 public static T GetSystemUnderTest <T>(this CellProcessor processor) where T : class
 {
     return(processor.CallStack.GetSystemUnderTest <T>());
 }
Пример #45
0
 public static TypedValue ExecuteWithThrow(this CellProcessor processor, object target, Tree <Cell> memberName)
 {
     return(processor.ExecuteWithThrow(target, memberName, new CellTree(), new CellBase(string.Empty)));
 }
Пример #46
0
 public static void Check(this CellProcessor processor, object systemUnderTest, Tree <Cell> memberName, Tree <Cell> expectedCell)
 {
     processor.Check(systemUnderTest, memberName, new CellTree(), expectedCell);
 }
Пример #47
0
 public StoryTest(CellProcessor processor, StoryTestWriter writer)
 {
     this.processor = processor;
     this.writer    = writer;
 }
Пример #48
0
 public static V Get <V>(this CellProcessor processor) where V : new()
 {
     return(processor.Memory.GetItem <V>());
 }
Пример #49
0
 public DeepCopy(CellProcessor processor)
 {
     this.processor = processor;
 }
Пример #50
0
 public static void Check(this CellProcessor processor, object systemUnderTest, Tree <Cell> memberName, Tree <Cell> parameters, Tree <Cell> expectedCell)
 {
     processor.Operate <CheckOperator>(
         CellOperationValue.Make(systemUnderTest, memberName, parameters),
         expectedCell);
 }
 public TypedValue Decorate(CellProcessor processor, Tree <Cell> element, Func <TypedValue> action)
 {
     return(action());
 }
Пример #52
0
 public void DoSetUp(CellProcessor processor, Tree <Cell> table)
 {
     Prepare(processor, table.Branches[0]);
     ExecuteOptionalMethod(InvokeSetUpTearDown.SetUpMethod, (Parse)table.Branches[0].Branches[0]);
 }
Пример #53
0
 public void Interpret(CellProcessor processor, Tree <Cell> table)
 {
 }
Пример #54
0
 public ListMatcher(CellProcessor processor, ListMatchStrategy strategy)
 {
     this.strategy  = strategy;
     this.processor = processor;
 }
 public PatternMemberMatcher(CellProcessor processor, object instance, MemberSpecification specification)
 {
     this.processor     = processor;
     this.specification = specification;
     this.instance      = instance;
 }
 public PatternRuntimeMember(CellProcessor processor, RuntimeMember baseMember, string[] patternParameters)
 {
     this.baseMember        = baseMember;
     this.processor         = processor;
     this.patternParameters = patternParameters;
 }
Пример #57
0
 public QueryMatchStrategy(CellProcessor processor, Parse theHeaderRow, bool isOrdered)
     : base(processor, theHeaderRow)
 {
     this.isOrdered = isOrdered;
 }
Пример #58
0
 public static TypedValue Execute(this CellProcessor processor, object systemUnderTest, Tree <Cell> memberName,
                                  Tree <Cell> parameters, Cell targetCell)
 {
     return(processor.Operate <ExecuteOperator>(systemUnderTest, memberName, parameters, targetCell));
 }
Пример #59
0
 public InputBinding(CellProcessor processor, TargetObjectProvider targetProvider, Tree<Cell> memberCell)
 {
     this.processor = processor;
     this.memberCell = memberCell;
     this.targetProvider = targetProvider;
 }
Пример #60
0
 public IncludeAction(CellProcessor processor)
 {
     this.processor = processor;
 }