github.com/getgauge/gauge@v1.6.9/formatter/formatter_test.go (about)

     1  /*----------------------------------------------------------------
     2   *  Copyright (c) ThoughtWorks, Inc.
     3   *  Licensed under the Apache License, Version 2.0
     4   *  See LICENSE in the project root for license information.
     5   *----------------------------------------------------------------*/
     6  
     7  package formatter
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/getgauge/gauge/env"
    13  
    14  	"github.com/getgauge/gauge-proto/go/gauge_messages"
    15  	"github.com/getgauge/gauge/gauge"
    16  	"github.com/getgauge/gauge/parser"
    17  	. "gopkg.in/check.v1"
    18  )
    19  
    20  func Test(t *testing.T) { TestingT(t) }
    21  
    22  type MySuite struct{}
    23  
    24  var _ = Suite(&MySuite{})
    25  
    26  func (s *MySuite) TestFormatSpecification(c *C) {
    27  	tokens := []*parser.Token{
    28  		&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},
    29  		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},
    30  		&parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 3, Lines: []string{"Example step"}},
    31  		&parser.Token{Kind: gauge.StepKind, Value: "Step with inline table", LineNo: 3, Lines: []string{"Step with inline table "}},
    32  		&parser.Token{Kind: gauge.TableHeader, Args: []string{"id", "name"}},
    33  		&parser.Token{Kind: gauge.TableRow, Args: []string{"<1>", "foo"}},
    34  		&parser.Token{Kind: gauge.TableRow, Args: []string{"2", "bar"}},
    35  	}
    36  
    37  	spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")
    38  
    39  	formatted := FormatSpecification(spec)
    40  
    41  	c.Assert(formatted, Equals,
    42  		`# Spec Heading
    43  ## Scenario Heading
    44  * Example step
    45  * Step with inline table
    46  
    47     |id |name|
    48     |---|----|
    49     |<1>|foo |
    50     |2  |bar |
    51  `)
    52  }
    53  
    54  func (s *MySuite) TestFormatTable(c *C) {
    55  	cell1 := gauge.TableCell{Value: "john", CellType: gauge.Static}
    56  	cell2 := gauge.TableCell{Value: "doe", CellType: gauge.Static}
    57  
    58  	headers := []string{"name1", "name2"}
    59  	cols := [][]gauge.TableCell{{cell1}, {cell2}}
    60  
    61  	table := gauge.NewTable(headers, cols, 10)
    62  
    63  	got := FormatTable(table)
    64  	want := `
    65     |name1|name2|
    66     |-----|-----|
    67     |john |doe  |
    68  `
    69  
    70  	c.Assert(got, Equals, want)
    71  }
    72  
    73  func (s *MySuite) TestFormatTableWithUmlautChars(c *C) {
    74  	// umlaut characters are unicode and can take up twice the space of regular chars
    75  	cell1 := gauge.TableCell{Value: "Büsingen", CellType: gauge.Static}
    76  	cell2 := gauge.TableCell{Value: "Hauptstraße", CellType: gauge.Static}
    77  
    78  	headers := []string{"col1", "col2"}
    79  	cols := [][]gauge.TableCell{{cell1}, {cell2}}
    80  
    81  	table := gauge.NewTable(headers, cols, 10)
    82  
    83  	got := FormatTable(table)
    84  	want := `
    85     |col1    |col2       |
    86     |--------|-----------|
    87     |Büsingen|Hauptstraße|
    88  `
    89  
    90  	c.Assert(got, Equals, want)
    91  }
    92  
    93  func (s *MySuite) TestFormatConcepts(c *C) {
    94  	dictionary := gauge.NewConceptDictionary()
    95  	step1 := &gauge.Step{Value: "sdsf", LineText: "sdsf", IsConcept: true, LineNo: 1, PreComments: []*gauge.Comment{&gauge.Comment{Value: "COMMENT", LineNo: 1}}}
    96  	step2 := &gauge.Step{Value: "dsfdsfdsf", LineText: "dsfdsfdsf", IsConcept: true, LineNo: 2, Items: []gauge.Item{&gauge.Step{Value: "sfd", LineText: "sfd", IsConcept: false}, &gauge.Step{Value: "sdfsdf" + "T", LineText: "sdfsdf" + "T", IsConcept: false}}}
    97  
    98  	dictionary.ConceptsMap[step1.Value] = &gauge.Concept{ConceptStep: step1, FileName: "file.cpt"}
    99  	dictionary.ConceptsMap[step2.Value] = &gauge.Concept{ConceptStep: step2, FileName: "file.cpt"}
   100  
   101  	formatted := FormatConcepts(dictionary)
   102  	c.Assert(formatted["file.cpt"], Equals, `COMMENT
   103  # sdsf
   104  # dsfdsfdsf
   105  * sdfsdfT
   106  `)
   107  }
   108  
   109  func (s *MySuite) TestFormatSpecificationWithTags(c *C) {
   110  	tokens := []*parser.Token{
   111  		&parser.Token{Kind: gauge.SpecKind, Value: "My Spec Heading", LineNo: 1},
   112  		&parser.Token{Kind: gauge.TagKind, Args: []string{"tag1", "tag2"}, LineNo: 2},
   113  		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 3},
   114  		&parser.Token{Kind: gauge.TagKind, Args: []string{"tag3", "tag4"}, LineNo: 4},
   115  		&parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 5, Lines: []string{"Example step"}},
   116  		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading1", LineNo: 6},
   117  		&parser.Token{Kind: gauge.TagKind, Args: []string{"tag3", "tag4"}, LineNo: 7},
   118  		&parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 8, Lines: []string{"Example step"}},
   119  	}
   120  
   121  	spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")
   122  	formatted := FormatSpecification(spec)
   123  	c.Assert(formatted, Equals,
   124  		`# My Spec Heading
   125  
   126  tags: tag1, tag2
   127  
   128  ## Scenario Heading
   129  
   130  tags: tag3, tag4
   131  
   132  * Example step
   133  ## Scenario Heading1
   134  
   135  tags: tag3, tag4
   136  
   137  * Example step
   138  `)
   139  
   140  }
   141  
   142  func (s *MySuite) TestFormatSpecificationWithTagsInMutipleLines(c *C) {
   143  	tokens := []*parser.Token{
   144  		&parser.Token{Kind: gauge.SpecKind, Value: "My Spec Heading", LineNo: 1},
   145  		&parser.Token{Kind: gauge.TagKind, Args: []string{"tag1", "tag2"}, LineNo: 2},
   146  		&parser.Token{Kind: gauge.TagKind, Args: []string{"tag3", "tag4"}, LineNo: 3},
   147  		&parser.Token{Kind: gauge.TagKind, Args: []string{"tag5"}, LineNo: 4},
   148  		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 5},
   149  		&parser.Token{Kind: gauge.TagKind, Args: []string{"tag3", "tag4"}, LineNo: 6},
   150  		&parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 7, Lines: []string{"Example step"}},
   151  		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading1", LineNo: 8},
   152  		&parser.Token{Kind: gauge.TagKind, Args: []string{"tag3", "tag4"}, LineNo: 9},
   153  		&parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 10, Lines: []string{"Example step"}},
   154  	}
   155  
   156  	spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")
   157  	formatted := FormatSpecification(spec)
   158  	c.Assert(formatted, Equals,
   159  		`# My Spec Heading
   160  
   161  tags: tag1, tag2,`+string(" \n      ")+`tag3, tag4,`+string(" \n      ")+`tag5
   162  
   163  ## Scenario Heading
   164  
   165  tags: tag3, tag4
   166  
   167  * Example step
   168  ## Scenario Heading1
   169  
   170  tags: tag3, tag4
   171  
   172  * Example step
   173  `)
   174  }
   175  
   176  func (s *MySuite) TestFormatSpecificationWithTeardownSteps(c *C) {
   177  	tokens := []*parser.Token{
   178  		&parser.Token{Kind: gauge.SpecKind, Value: "My Spec Heading", LineNo: 1},
   179  		&parser.Token{Kind: gauge.TagKind, Args: []string{"tag1", "tag2"}, LineNo: 2},
   180  		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 3},
   181  		&parser.Token{Kind: gauge.TagKind, Args: []string{"tag3", "tag4"}, LineNo: 4},
   182  		&parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 5, Lines: []string{"Example step"}},
   183  		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading1", LineNo: 6},
   184  		&parser.Token{Kind: gauge.TagKind, Args: []string{"tag3", "tag4"}, LineNo: 7},
   185  		&parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 8, Lines: []string{"Example step"}},
   186  		&parser.Token{Kind: gauge.TearDownKind, Value: "____", LineNo: 9},
   187  		&parser.Token{Kind: gauge.StepKind, Value: "Example step1", LineNo: 10, Lines: []string{"Example step1"}},
   188  		&parser.Token{Kind: gauge.StepKind, Value: "Example step2", LineNo: 11, Lines: []string{"Example step2"}},
   189  	}
   190  
   191  	spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")
   192  	formatted := FormatSpecification(spec)
   193  	c.Assert(formatted, Equals,
   194  		`# My Spec Heading
   195  
   196  tags: tag1, tag2
   197  
   198  ## Scenario Heading
   199  
   200  tags: tag3, tag4
   201  
   202  * Example step
   203  ## Scenario Heading1
   204  
   205  tags: tag3, tag4
   206  
   207  * Example step
   208  ____
   209  * Example step1
   210  * Example step2
   211  `)
   212  
   213  }
   214  
   215  func (s *MySuite) TestFormatStep(c *C) {
   216  	step := &gauge.Step{Value: "my step with {}, {}, {} and {}", Args: []*gauge.StepArg{&gauge.StepArg{Value: "static \"foo\"", ArgType: gauge.Static},
   217  		&gauge.StepArg{Name: "dynamic", Value: "\"foo\"", ArgType: gauge.Dynamic},
   218  		&gauge.StepArg{Name: "file:user\".txt", ArgType: gauge.SpecialString},
   219  		&gauge.StepArg{Name: "table :hell\".csv", ArgType: gauge.SpecialTable}}}
   220  	formatted := FormatStep(step)
   221  	c.Assert(formatted, Equals, `* my step with "static \"foo\"", <dynamic>, <file:user\".txt> and <table :hell\".csv>
   222  `)
   223  }
   224  
   225  func (s *MySuite) TestFormatStepsWithResolveArgs(c *C) {
   226  	step := &gauge.Step{Value: "my step with {}, {}", Args: []*gauge.StepArg{&gauge.StepArg{Value: "static \"foo\"", ArgType: gauge.Static},
   227  		&gauge.StepArg{Name: "dynamic", Value: "\"foo\"", ArgType: gauge.Dynamic}},
   228  		Fragments: []*gauge_messages.Fragment{
   229  			&gauge_messages.Fragment{Text: "my step with "},
   230  			&gauge_messages.Fragment{FragmentType: gauge_messages.Fragment_Parameter, Parameter: &gauge_messages.Parameter{Value: "static \"foo\"", ParameterType: gauge_messages.Parameter_Static}},
   231  			&gauge_messages.Fragment{Text: ", "},
   232  			&gauge_messages.Fragment{FragmentType: gauge_messages.Fragment_Parameter, Parameter: &gauge_messages.Parameter{Value: "\"foo\"", ParameterType: gauge_messages.Parameter_Dynamic}}}}
   233  	formatted := FormatStepWithResolvedArgs(step)
   234  	c.Assert(formatted, Equals, `* my step with "static "foo"", ""foo""
   235  `)
   236  }
   237  
   238  func (s *MySuite) TestFormatStepsWithResolveArgsWithConcept(c *C) {
   239  	step := &gauge.Step{Value: "my step with {}, {}", Args: []*gauge.StepArg{&gauge.StepArg{Value: "static \"foo\"", ArgType: gauge.Dynamic},
   240  		&gauge.StepArg{Name: "dynamic", Value: "\"foo\"", ArgType: gauge.Static}},
   241  		Fragments: []*gauge_messages.Fragment{
   242  			&gauge_messages.Fragment{Text: "my step with "},
   243  			&gauge_messages.Fragment{FragmentType: gauge_messages.Fragment_Parameter, Parameter: &gauge_messages.Parameter{Value: "static \"foo\"", ParameterType: gauge_messages.Parameter_Dynamic}},
   244  			&gauge_messages.Fragment{Text: ", "},
   245  			&gauge_messages.Fragment{FragmentType: gauge_messages.Fragment_Parameter, Parameter: &gauge_messages.Parameter{Value: "\"foo\"", ParameterType: gauge_messages.Parameter_Static}}}}
   246  	formatted := FormatStepWithResolvedArgs(step)
   247  	c.Assert(formatted, Equals, `* my step with "static "foo"", ""foo""
   248  `)
   249  }
   250  
   251  func (s *MySuite) TestFormatStepsWithResolveArgsWithSpecialArguments(c *C) {
   252  	step := &gauge.Step{Value: "my step with {}, {}", Args: []*gauge.StepArg{&gauge.StepArg{Value: "static \"foo\"", ArgType: gauge.SpecialString},
   253  		&gauge.StepArg{Name: "dynamic", Value: "\"foo\"", ArgType: gauge.SpecialTable}},
   254  		Fragments: []*gauge_messages.Fragment{
   255  			&gauge_messages.Fragment{Text: "my step with "},
   256  			&gauge_messages.Fragment{FragmentType: gauge_messages.Fragment_Parameter, Parameter: &gauge_messages.Parameter{Value: "static \"foo\"", ParameterType: gauge_messages.Parameter_Special_String}},
   257  			&gauge_messages.Fragment{Text: ", "},
   258  			&gauge_messages.Fragment{FragmentType: gauge_messages.Fragment_Parameter, Parameter: &gauge_messages.Parameter{Value: "\"foo\"", ParameterType: gauge_messages.Parameter_Special_Table}}}}
   259  	formatted := FormatStepWithResolvedArgs(step)
   260  	c.Assert(formatted, Equals, `* my step with "static "foo"", ""foo""
   261  `)
   262  }
   263  
   264  func (s *MySuite) TestFormattingWithTableAsAComment(c *C) {
   265  	tokens := []*parser.Token{
   266  		&parser.Token{Kind: gauge.SpecKind, Value: "My Spec Heading", LineNo: 1},
   267  		&parser.Token{Kind: gauge.CommentKind, Value: "\n", LineNo: 2},
   268  		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 3},
   269  		&parser.Token{Kind: gauge.TableHeader, Args: []string{"id", "name"}, Lines: []string{" |id|name|"}},
   270  		&parser.Token{Kind: gauge.TableRow, Args: []string{"1", "foo"}, Lines: []string{" |1|foo|"}},
   271  		&parser.Token{Kind: gauge.TableRow, Args: []string{"2", "bar"}, Lines: []string{"|2|bar|"}},
   272  		&parser.Token{Kind: gauge.CommentKind, Value: "\n", LineNo: 7},
   273  		&parser.Token{Kind: gauge.TableHeader, Args: []string{"id", "name"}, Lines: []string{" |id|name1|"}},
   274  		&parser.Token{Kind: gauge.TableRow, Args: []string{"1", "foo"}, Lines: []string{" |1|foo|"}},
   275  		&parser.Token{Kind: gauge.TableRow, Args: []string{"2", "bar"}, Lines: []string{"|2|bar|"}},
   276  		&parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 11, Lines: []string{"Example step"}},
   277  	}
   278  
   279  	spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")
   280  	formatted := FormatSpecification(spec)
   281  	c.Assert(formatted, Equals,
   282  		`# My Spec Heading
   283  
   284  ## Scenario Heading
   285     |id|name|
   286     |--|----|
   287     |1 |foo |
   288     |2 |bar |
   289  
   290   |id|name1|
   291   |1|foo|
   292  |2|bar|
   293  * Example step
   294  `)
   295  }
   296  
   297  func (s *MySuite) TestFormatSpecificationWithTableContainingDynamicParameters(c *C) {
   298  	tokens := []*parser.Token{
   299  		&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},
   300  		&parser.Token{Kind: gauge.TableHeader, Args: []string{"id", "foo"}},
   301  		&parser.Token{Kind: gauge.TableRow, Args: []string{"1", "f"}},
   302  		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},
   303  		&parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 3, Lines: []string{"Example step"}},
   304  		&parser.Token{Kind: gauge.StepKind, Value: "Step with inline table", LineNo: 3, Lines: []string{"Step with inline table "}},
   305  		&parser.Token{Kind: gauge.TableHeader, Args: []string{"id", "name"}},
   306  		&parser.Token{Kind: gauge.TableRow, Args: []string{"1", "<foo>"}},
   307  		&parser.Token{Kind: gauge.TableRow, Args: []string{"2", "bar"}},
   308  	}
   309  
   310  	spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")
   311  
   312  	formatted := FormatSpecification(spec)
   313  
   314  	c.Assert(formatted, Equals,
   315  		`# Spec Heading
   316     |id|foo|
   317     |--|---|
   318     |1 |f  |
   319  ## Scenario Heading
   320  * Example step
   321  * Step with inline table
   322  
   323     |id|name |
   324     |--|-----|
   325     |1 |<foo>|
   326     |2 |bar  |
   327  `)
   328  }
   329  
   330  func (s *MySuite) TestFormatShouldRetainNewlines(c *C) {
   331  	tokens := []*parser.Token{
   332  		&parser.Token{Kind: gauge.SpecKind, Value: "My Spec Heading", LineNo: 1},
   333  		&parser.Token{Kind: gauge.CommentKind, Value: "\n", LineNo: 2},
   334  		&parser.Token{Kind: gauge.CommentKind, Value: "\n", LineNo: 3},
   335  		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 4},
   336  		&parser.Token{Kind: gauge.TableHeader, Args: []string{"id", "name"}, Lines: []string{" |id|name|"}},
   337  		&parser.Token{Kind: gauge.TableRow, Args: []string{"1", "foo"}, Lines: []string{" |1|foo|"}},
   338  		&parser.Token{Kind: gauge.TableRow, Args: []string{"2", "bar"}, Lines: []string{"|2|bar|"}},
   339  		&parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 8, Lines: []string{"Example step"}},
   340  		&parser.Token{Kind: gauge.TableHeader, Args: []string{"id", "name"}},
   341  		&parser.Token{Kind: gauge.TableRow, Args: []string{"1", "<foo>"}},
   342  		&parser.Token{Kind: gauge.TableRow, Args: []string{"2", "bar"}},
   343  	}
   344  
   345  	env.AllowScenarioDatatable = func() bool { return true }
   346  	spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")
   347  	formatted := FormatSpecification(spec)
   348  	c.Assert(formatted, Equals,
   349  		`# My Spec Heading
   350  
   351  
   352  ## Scenario Heading
   353     |id|name|
   354     |--|----|
   355     |1 |foo |
   356     |2 |bar |
   357  * Example step
   358  
   359     |id|name |
   360     |--|-----|
   361     |1 |<foo>|
   362     |2 |bar  |
   363  `)
   364  }
   365  
   366  func (s *MySuite) TestFormatShouldRetainNewlinesBetweenSteps(c *C) {
   367  	tokens := []*parser.Token{
   368  		&parser.Token{Kind: gauge.SpecKind, Value: "My Spec Heading", LineNo: 1},
   369  		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 4},
   370  		&parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 6, Lines: []string{"Example step"}, Suffix: "\n\n"},
   371  		&parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 9, Lines: []string{"Example step"}, Suffix: "\n\n"},
   372  	}
   373  
   374  	spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")
   375  	formatted := FormatSpecification(spec)
   376  	c.Assert(formatted, Equals,
   377  		`# My Spec Heading
   378  ## Scenario Heading
   379  * Example step
   380  
   381  
   382  * Example step
   383  
   384  
   385  `)
   386  }
   387  
   388  func (s *MySuite) TestFormatShouldStripDuplicateNewlinesBeforeInlineTable(c *C) {
   389  	tokens := []*parser.Token{
   390  		&parser.Token{Kind: gauge.SpecKind, Value: "My Spec Heading", LineNo: 1},
   391  		&parser.Token{Kind: gauge.CommentKind, Value: "\n", LineNo: 2},
   392  		&parser.Token{Kind: gauge.CommentKind, Value: "\n", LineNo: 3},
   393  		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 4},
   394  		&parser.Token{Kind: gauge.TableHeader, Args: []string{"id", "name"}, Lines: []string{" |id|name|"}},
   395  		&parser.Token{Kind: gauge.TableRow, Args: []string{"1", "foo"}, Lines: []string{" |1|foo|"}},
   396  		&parser.Token{Kind: gauge.TableRow, Args: []string{"2", "bar"}, Lines: []string{"|2|bar|"}},
   397  		&parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 8, Lines: []string{"Example step\n\n"}},
   398  		&parser.Token{Kind: gauge.TableHeader, Args: []string{"id", "name"}},
   399  		&parser.Token{Kind: gauge.TableRow, Args: []string{"1", "<foo>"}},
   400  		&parser.Token{Kind: gauge.TableRow, Args: []string{"2", "bar"}},
   401  	}
   402  
   403  	spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")
   404  	formatted := FormatSpecification(spec)
   405  	c.Assert(formatted, Equals,
   406  		`# My Spec Heading
   407  
   408  
   409  ## Scenario Heading
   410     |id|name|
   411     |--|----|
   412     |1 |foo |
   413     |2 |bar |
   414  * Example step
   415  
   416     |id|name |
   417     |--|-----|
   418     |1 |<foo>|
   419     |2 |bar  |
   420  `)
   421  }
   422  
   423  func (s *MySuite) TestFormatShouldStripDuplicateNewlinesBeforeInlineTableInTeardown(c *C) {
   424  	tokens := []*parser.Token{
   425  		&parser.Token{Kind: gauge.SpecKind, Value: "My Spec Heading", LineNo: 1},
   426  		&parser.Token{Kind: gauge.CommentKind, Value: "\n", LineNo: 2},
   427  		&parser.Token{Kind: gauge.CommentKind, Value: "\n", LineNo: 3},
   428  		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 4},
   429  		&parser.Token{Kind: gauge.TableHeader, Args: []string{"id", "name"}, Lines: []string{" |id|name|"}},
   430  		&parser.Token{Kind: gauge.TableRow, Args: []string{"1", "foo"}, Lines: []string{" |1|foo|"}},
   431  		&parser.Token{Kind: gauge.TableRow, Args: []string{"2", "bar"}, Lines: []string{"|2|bar|"}},
   432  		&parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 8, Lines: []string{"Example step\n\n"}},
   433  		&parser.Token{Kind: gauge.TableHeader, Args: []string{"id", "name"}},
   434  		&parser.Token{Kind: gauge.TableRow, Args: []string{"1", "<foo>"}},
   435  		&parser.Token{Kind: gauge.TableRow, Args: []string{"2", "bar"}},
   436  		&parser.Token{Kind: gauge.CommentKind, Value: "\n", LineNo: 10},
   437  		&parser.Token{Kind: gauge.TearDownKind, Value: "____", LineNo: 9},
   438  		&parser.Token{Kind: gauge.CommentKind, Value: "\n", LineNo: 10},
   439  		&parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 8, Lines: []string{"Example step\n\n\n"}},
   440  		&parser.Token{Kind: gauge.TableHeader, Args: []string{"id", "name"}},
   441  		&parser.Token{Kind: gauge.TableRow, Args: []string{"1", "<foo>"}},
   442  		&parser.Token{Kind: gauge.TableRow, Args: []string{"2", "bar"}},
   443  	}
   444  
   445  	spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")
   446  	formatted := FormatSpecification(spec)
   447  	c.Assert(formatted, Equals,
   448  		`# My Spec Heading
   449  
   450  
   451  ## Scenario Heading
   452     |id|name|
   453     |--|----|
   454     |1 |foo |
   455     |2 |bar |
   456  * Example step
   457  
   458     |id|name |
   459     |--|-----|
   460     |1 |<foo>|
   461     |2 |bar  |
   462  
   463  ____
   464  
   465  * Example step
   466  
   467     |id|name |
   468     |--|-----|
   469     |1 |<foo>|
   470     |2 |bar  |
   471  `)
   472  }
   473  
   474  func (s *MySuite) TestFormatShouldNotAddExtraNewLinesBeforeDataTable(c *C) {
   475  	spec, _, _ := new(parser.SpecParser).Parse(`# Specification Heading
   476  
   477       |Word  |Vowel Count|
   478       |------|-----------|
   479       |Gauge |3          |
   480       |Mingle|2          |
   481       |Snap  |1          |
   482       |GoCD  |1          |
   483       |Rhythm|0          |
   484  `, gauge.NewConceptDictionary(), "")
   485  	formatted := FormatSpecification(spec)
   486  	c.Assert(formatted, Equals,
   487  		`# Specification Heading
   488  
   489     |Word  |Vowel Count|
   490     |------|-----------|
   491     |Gauge |3          |
   492     |Mingle|2          |
   493     |Snap  |1          |
   494     |GoCD  |1          |
   495     |Rhythm|0          |
   496  `)
   497  }