コード例 #1
0
        private bool MakeFormattedTable(DocumentLine line, bool isEnteredNewLine, int?newColumnIndex)
        {
            GherkinTableBuilder builder = new GherkinTableBuilder(Document, line, isEnteredNewLine, newColumnIndex);
            GherkinTable        table   = builder.Build();

            if (table == null)
            {
                return(false);
            }

            string table_text = table.Format();

            if (!table_text.EndsWith(Environment.NewLine, StringComparison.Ordinal))
            {
                table_text += Environment.NewLine;
            }

            // We need to replace newly entered new line when formatting table by entering new line
            // New line length is 2 because it is "\r\n"
            int new_line_length = isEnteredNewLine ? 2 : 0;

            Document.Replace(builder.Offset, builder.Length + new_line_length, table_text);

            return(true);
        }
コード例 #2
0
        public static Tuple <DocumentLine, string> FormatTable(TextDocument document, DocumentLine line, int endLine)
        {
            Tuple <DocumentLine, List <string> > table_rows = ExtractTableText(document, line, endLine);
            GherkinTable table      = GherkinTableBuilder.BuildTable(table_rows.Item2);
            string       table_text = table.Format();

            return(new Tuple <DocumentLine, string>(table_rows.Item1, table_text));
        }
コード例 #3
0
        public static GherkinTable BuildTable(List <string> rows, bool haveTrailingRows = true)
        {
            GherkinTable table       = new GherkinTable(add_last_new_line: haveTrailingRows);
            int          max_columns = 1;

            foreach (string row_text in rows)
            {
                GherkinTableRow row   = new GherkinTableRow();
                string[]        cells = row_text.Split('|');
                max_columns = Math.Max(max_columns, cells.Length - 2);
                for (int i = 1; i < cells.Length - 1; i++)
                {
                    // create cells except first and last empty string
                    row.Add(new GherkinTableCell(cells[i]));
                }
                table.Add(row);
            }

            table.PadCells(max_columns);

            return(table);
        }