Ejemplo n.º 1
0
 public RawTest[] TranslateScenario(Table table)
 {
     // compact comments before splitting table to prevent comments becoming their own tests
     RemoveIntercommentLines(table);
     List<Table> tables = table.SplitOn(isDivider);
     return tables.ConvertAll(t => TranslateIndividual(t)).ToArray();
 }
Ejemplo n.º 2
0
 // todo: inefficient
 public void RemoveIntercommentLines(Table table)
 {
     List<Row> rowsToRemove = new List<Row>();
     List<Row> rows = table.Rows;
     bool inTest = false;
     foreach (var row in rows)
     {
         if (isComment(row))
         {
             // keep line
         }
         else if (row.IsEmpty())
         {
             if (inTest)
             {
                 // it's a divider - keep it
                 // end of test
                 inTest = false;
             }
             else
             {
                 // empty row, not in test is empty row between comments. ditch it.
                 rowsToRemove.Add(row);
             }
         }
         else
         {
             inTest = true;
         }
     }
     rowsToRemove.ForEach(row => table.Rows.Remove(row));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Split table into subtables based on predicate (blank rows, for example)
        /// </summary>
        public List<Table> SplitOn(Predicate<Row> divideOn)
        {
            var allTables = new List<Table>();
            Table currentTable = null;

            foreach (Row row in Rows)
            {
                // end current table?
                if (divideOn(row))
                {
                    // note: divider row is discarded here (so far no need to keep the divider, but easy enough to do)
                    currentTable = null;
                    continue;
                }

                // start new table?
                if (currentTable == null)
                {
                    currentTable = new Table();
                    allTables.Add(currentTable);
                }

                currentTable.AddRow(row);
            }
            return allTables;
        }
Ejemplo n.º 4
0
 private void CorrectForRowIndex(Table table)
 {
     while (reader.MoveToNextAttribute())
     {
         if (IsIndexAttribute())
         {
             table.AddEmptyRows(GetMissingCount(table.RowCount));
         }
     }
 }
Ejemplo n.º 5
0
 private Table ReadTable(TextReader reader)
 {
     Table table = new Table();
     string line;
     while ((line = reader.ReadLine()) != null)
     {
         Row row = ReadRow(line);
         table.AddRow(row);
     }
     return table;
 }
Ejemplo n.º 6
0
            public Table ReadTable()
            {
                reader.MoveToNextElement("Table");

                var table = new Table();
                while (true)
                {
                    reader.MoveToNextElement();

                    if (reader.IsStartElement("Row"))
                    {
                        ReadRow(table);
                    }

                    if (reader.IsEndElement("Table"))
                    {
                        return table;
                    }
                }
            }
Ejemplo n.º 7
0
 private RawTest[] Interpret(Table table)
 {
     DelimitedTextTableInterpreter tableInterpreter = new DelimitedTextTableInterpreter();
     return tableInterpreter.TranslateScenario(table);
 }
Ejemplo n.º 8
0
        private RawTest TranslateIndividual(Table table)
        {
            int fixtureIndex = 0;
            int headersIndex = 1;

            List<string> comments = new List<string>();
            string title = string.Empty;
            List<string> args = new List<string>();
            List<string> headers = new List<string>();
            List<Row> dataRows = new List<Row>();

            List<Row> rows = table.Rows;
            for (int i = 0; i < rows.Count; i++)
            {
                Row currentRow = rows[i];
                if (isComment(currentRow))
                {
                    // note: comments are really only expected at the front of the test table
                    comments.Add(currentRow.Cells[0].Value.Trim());
                    fixtureIndex++;
                    headersIndex++;
                }
                else
                {
                    List<Cell> cells = currentRow.Cells;

                    AdjustForTestOffset(cells);

                    if (i == fixtureIndex)
                    {
                        // todo: bulletproof the indexing and stuff, provide nice exceptions with nice details
                        title = cells[0].Value;
                        args.AddRange(GetArgs(cells));
                    }
                    else if (i == headersIndex)
                    {
                        headers.AddRange(cells.ConvertAll(input => input.Value));
                    }
                    else
                    {
                        dataRows.Add(new Row(cells));
                    }
                }
            }

            RawTest rawTest = new RawTest(title, comments, args, headers, dataRows);
            rawTest.Validate();
            return rawTest;
        }
Ejemplo n.º 9
0
            void ReadRow(Table table)
            {
                reader.AssertIsStartElement("Row");

                bool isEmptyRow = reader.IsEmptyElement;
                if (isEmptyRow)
                {
                    table.AddEmptyRow();
                }

                CorrectForRowIndex(table);

                if (! isEmptyRow)
                {
                    var row = new Row();
                    table.AddRow(row);
                    ReadRowCells(row);
                }
            }