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;
 }
 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;
 }
Example #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);
        }
Example #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);
 }
Example #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);
     }
 }
Example #6
0
 public SocketServer(FitSocket socket, CellProcessor service, ProgressReporter reporter, bool suiteSetUpIsAnonymous)
 {
     this.service = service;
     this.reporter = reporter;
     this.socket = socket;
     IMaybeProcessingSuiteSetup = suiteSetUpIsAnonymous;
 }
Example #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);
 }
Example #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);
 }
Example #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>();
        }
Example #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;
 }
Example #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;
 }
Example #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));
 }
Example #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);
 }
Example #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);
 }
Example #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);
 }
Example #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);
 }
Example #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);
        }
Example #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);
     }
 }
Example #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;
 }
Example #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();
     }
 }
Example #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);
 }
Example #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());
        }
Example #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());
        }
Example #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);
            }
        }
Example #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;
     }
 }
Example #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();
     }
 }
Example #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));
            }
        }
Example #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);
 }
Example #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);
        }
Example #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();
 }
Example #32
0
 public void Prepare(CellProcessor processor, Tree <Cell> row)
 {
     Processor = processor;
     GetArgsForRow(row);
 }
Example #33
0
 static Type FindType(CellProcessor processor, string facilityName, string action)
 {
     return(processor.ApplicationUnderTest.FindType(new GracefulNameMatcher(ConfigurationNames.TypeName(facilityName, action))).Type);
 }
Example #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);
 }
Example #35
0
 public void Execute(CellProcessor cellProcessor)
 {
     cellProcessor.Operate <RunTestOperator>(ParsedInput, writer);
 }
Example #36
0
 public SetMatchStrategy(CellProcessor processor, Parse theHeaderRow) : base(processor, theHeaderRow)
 {
 }
Example #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)));
 }
Example #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();
        }
Example #39
0
 public FlowKeywords(FlowInterpreter fixture, CellProcessor processor)
 {
     this.fixture   = fixture;
     this.processor = processor;
 }
Example #40
0
 public InterpretFlow(CellProcessor processor, FlowInterpreter interpreter)
 {
     this.interpreter = interpreter;
     this.processor   = processor;
 }
Example #41
0
 public CellMatcher(CellProcessor processor)
 {
     Processor = processor;
 }
Example #42
0
 public CellOperationImpl(CellProcessor processor)
 {
     this.processor = processor;
 }
Example #43
0
 public static void Check(this CellProcessor processor, TypedValue actualValue, Tree <Cell> expectedCell)
 {
     processor.Operate <CheckOperator>(
         CellOperationValue.Make(actualValue),
         expectedCell);
 }
Example #44
0
 public static T GetSystemUnderTest <T>(this CellProcessor processor) where T : class
 {
     return(processor.CallStack.GetSystemUnderTest <T>());
 }
Example #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)));
 }
Example #46
0
 public static void Check(this CellProcessor processor, object systemUnderTest, Tree <Cell> memberName, Tree <Cell> expectedCell)
 {
     processor.Check(systemUnderTest, memberName, new CellTree(), expectedCell);
 }
Example #47
0
 public StoryTest(CellProcessor processor, StoryTestWriter writer)
 {
     this.processor = processor;
     this.writer    = writer;
 }
Example #48
0
 public static V Get <V>(this CellProcessor processor) where V : new()
 {
     return(processor.Memory.GetItem <V>());
 }
Example #49
0
 public DeepCopy(CellProcessor processor)
 {
     this.processor = processor;
 }
Example #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());
 }
Example #52
0
 public void DoSetUp(CellProcessor processor, Tree <Cell> table)
 {
     Prepare(processor, table.Branches[0]);
     ExecuteOptionalMethod(InvokeSetUpTearDown.SetUpMethod, (Parse)table.Branches[0].Branches[0]);
 }
 public void Interpret(CellProcessor processor, Tree <Cell> table)
 {
 }
Example #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;
 }
Example #57
0
 public QueryMatchStrategy(CellProcessor processor, Parse theHeaderRow, bool isOrdered)
     : base(processor, theHeaderRow)
 {
     this.isOrdered = isOrdered;
 }
Example #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));
 }
Example #59
0
 public InputBinding(CellProcessor processor, TargetObjectProvider targetProvider, Tree<Cell> memberCell)
 {
     this.processor = processor;
     this.memberCell = memberCell;
     this.targetProvider = targetProvider;
 }
Example #60
0
 public IncludeAction(CellProcessor processor)
 {
     this.processor = processor;
 }