Skip to content

Commit

Permalink
moving filterByTags tests from gauge_test.go to specFilter_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
kashishm committed Apr 1, 2015
1 parent 30ebbc1 commit a1e5612
Show file tree
Hide file tree
Showing 2 changed files with 258 additions and 258 deletions.
258 changes: 0 additions & 258 deletions gauge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,174 +83,6 @@ func (s *MySuite) TestToSplitTagNames(c *C) {
c.Assert(allTags[2], Equals, "tag3")
}

func (s *MySuite) TestToFilterScenariosByTag(c *C) {
myTags := []string{"tag1", "tag2"}
tokens := []*token{
&token{kind: specKind, value: "Spec Heading", lineNo: 1},
&token{kind: scenarioKind, value: "Scenario Heading 1", lineNo: 2},
&token{kind: scenarioKind, value: "Scenario Heading 2", lineNo: 4},
&token{kind: tagKind, args: myTags, lineNo: 3},
&token{kind: scenarioKind, value: "Scenario Heading 3", lineNo: 5},
}
spec, result := new(specParser).createSpecification(tokens, new(conceptDictionary))
c.Assert(result.ok, Equals, true)

c.Assert(len(spec.scenarios), Equals, 3)
c.Assert(len(spec.scenarios[1].tags.values), Equals, 2)

var specs []*specification
specs = append(specs, spec)
specs = filterSpecsByTags(specs, "tag1 & tag2")
c.Assert(len(specs[0].scenarios), Equals, 1)
c.Assert(specs[0].scenarios[0].heading.value, Equals, "Scenario Heading 2")
}

func (s *MySuite) TestToFilterScenariosByUnavailableTags(c *C) {
myTags := []string{"tag1", "tag2"}
tokens := []*token{
&token{kind: specKind, value: "Spec Heading", lineNo: 1},
&token{kind: scenarioKind, value: "Scenario Heading 1", lineNo: 2},
&token{kind: scenarioKind, value: "Scenario Heading 2", lineNo: 4},
&token{kind: tagKind, args: myTags, lineNo: 3},
&token{kind: scenarioKind, value: "Scenario Heading 3", lineNo: 5},
}
spec, result := new(specParser).createSpecification(tokens, new(conceptDictionary))
c.Assert(result.ok, Equals, true)

c.Assert(len(spec.scenarios), Equals, 3)
c.Assert(len(spec.scenarios[1].tags.values), Equals, 2)

var specs []*specification
specs = append(specs, spec)
specs = filterSpecsByTags(specs, "tag3")
c.Assert(len(specs), Equals, 0)
}

func (s *MySuite) TestToFilterMultipleScenariosByTags(c *C) {
myTags := []string{"tag1", "tag2"}
tokens := []*token{
&token{kind: specKind, value: "Spec Heading", lineNo: 1},
&token{kind: scenarioKind, value: "Scenario Heading 1", lineNo: 2},
&token{kind: tagKind, args: []string{"tag1"}, lineNo: 3},
&token{kind: scenarioKind, value: "Scenario Heading 2", lineNo: 4},
&token{kind: tagKind, args: myTags, lineNo: 5},
&token{kind: scenarioKind, value: "Scenario Heading 3", lineNo: 6},
&token{kind: tagKind, args: myTags, lineNo: 7},
}
spec, result := new(specParser).createSpecification(tokens, new(conceptDictionary))
c.Assert(result.ok, Equals, true)

var specs []*specification
specs = append(specs, spec)
c.Assert(len(specs[0].scenarios), Equals, 3)
c.Assert(len(specs[0].scenarios[0].tags.values), Equals, 1)
c.Assert(len(specs[0].scenarios[1].tags.values), Equals, 2)
specs = filterSpecsByTags(specs, "tag1 & tag2")
c.Assert(len(specs[0].scenarios), Equals, 2)
c.Assert(specs[0].scenarios[0].heading.value, Equals, "Scenario Heading 2")
c.Assert(specs[0].scenarios[1].heading.value, Equals, "Scenario Heading 3")
}

func (s *MySuite) TestToFilterMultipleScenariosByMultipleTags(c *C) {
myTags := []string{"tag1", "tag2"}
tokens := []*token{
&token{kind: specKind, value: "Spec Heading", lineNo: 1},
&token{kind: scenarioKind, value: "Scenario Heading 1", lineNo: 2},
&token{kind: tagKind, args: []string{"tag1"}, lineNo: 3},
&token{kind: scenarioKind, value: "Scenario Heading 2", lineNo: 4},
&token{kind: tagKind, args: myTags, lineNo: 5},
&token{kind: scenarioKind, value: "Scenario Heading 3", lineNo: 6},
&token{kind: tagKind, args: myTags, lineNo: 7},
&token{kind: scenarioKind, value: "Scenario Heading 4", lineNo: 8},
&token{kind: tagKind, args: []string{"prod", "tag7", "tag1", "tag2"}, lineNo: 9},
}
spec, result := new(specParser).createSpecification(tokens, new(conceptDictionary))
c.Assert(result.ok, Equals, true)

var specs []*specification
specs = append(specs, spec)

c.Assert(len(specs[0].scenarios), Equals, 4)
c.Assert(len(specs[0].scenarios[0].tags.values), Equals, 1)
c.Assert(len(specs[0].scenarios[1].tags.values), Equals, 2)
c.Assert(len(specs[0].scenarios[2].tags.values), Equals, 2)
c.Assert(len(specs[0].scenarios[3].tags.values), Equals, 4)

specs = filterSpecsByTags(specs, "tag1 & tag2")
c.Assert(len(specs[0].scenarios), Equals, 3)
c.Assert(specs[0].scenarios[0].heading.value, Equals, "Scenario Heading 2")
c.Assert(specs[0].scenarios[1].heading.value, Equals, "Scenario Heading 3")
c.Assert(specs[0].scenarios[2].heading.value, Equals, "Scenario Heading 4")
}

func (s *MySuite) TestToFilterScenariosByTagsAtSpecLevel(c *C) {
myTags := []string{"tag1", "tag2"}
tokens := []*token{
&token{kind: specKind, value: "Spec Heading", lineNo: 1},
&token{kind: tagKind, args: myTags, lineNo: 2},
&token{kind: scenarioKind, value: "Scenario Heading 1", lineNo: 3},
&token{kind: scenarioKind, value: "Scenario Heading 2", lineNo: 4},
&token{kind: scenarioKind, value: "Scenario Heading 3", lineNo: 5},
}
spec, result := new(specParser).createSpecification(tokens, new(conceptDictionary))
c.Assert(result.ok, Equals, true)

var specs []*specification
specs = append(specs, spec)

c.Assert(len(specs[0].scenarios), Equals, 3)
c.Assert(len(specs[0].tags.values), Equals, 2)
specs = filterSpecsByTags(specs, "tag1 & tag2")
c.Assert(len(specs[0].scenarios), Equals, 3)
c.Assert(specs[0].scenarios[0].heading.value, Equals, "Scenario Heading 1")
c.Assert(specs[0].scenarios[1].heading.value, Equals, "Scenario Heading 2")
c.Assert(specs[0].scenarios[2].heading.value, Equals, "Scenario Heading 3")
}

func (s *MySuite) TestToFilterSpecsByTags(c *C) {
myTags := []string{"tag1", "tag2"}
tokens := []*token{
&token{kind: specKind, value: "Spec Heading1", lineNo: 1},
&token{kind: scenarioKind, value: "Scenario Heading 1", lineNo: 1},
&token{kind: tagKind, args: myTags, lineNo: 2},
&token{kind: scenarioKind, value: "Scenario Heading 2", lineNo: 3},
}
spec1, result := new(specParser).createSpecification(tokens, new(conceptDictionary))
c.Assert(result.ok, Equals, true)

tokens1 := []*token{
&token{kind: specKind, value: "Spec Heading2", lineNo: 1},
&token{kind: scenarioKind, value: "Scenario Heading 1", lineNo: 1},
&token{kind: scenarioKind, value: "Scenario Heading 2", lineNo: 2},
}
spec2, result := new(specParser).createSpecification(tokens1, new(conceptDictionary))
c.Assert(result.ok, Equals, true)

tokens2 := []*token{
&token{kind: specKind, value: "Spec Heading3", lineNo: 1},
&token{kind: scenarioKind, value: "Scenario Heading 1", lineNo: 1},
&token{kind: tagKind, args: myTags, lineNo: 2},
&token{kind: scenarioKind, value: "Scenario Heading 2", lineNo: 3},
}
spec3, result := new(specParser).createSpecification(tokens2, new(conceptDictionary))
c.Assert(result.ok, Equals, true)

c.Assert(len(spec1.scenarios), Equals, 2)
c.Assert(len(spec1.scenarios[0].tags.values), Equals, 2)
c.Assert(len(spec2.scenarios), Equals, 2)

var specs []*specification
specs = append(specs, spec1)
specs = append(specs, spec2)
specs = append(specs, spec3)
specs = filterSpecsByTags(specs, "tag1 & tag2")
c.Assert(len(specs), Equals, 2)
c.Assert(len(specs[0].scenarios), Equals, 1)
c.Assert(len(specs[1].scenarios), Equals, 1)
c.Assert(specs[0].heading.value, Equals, "Spec Heading1")
c.Assert(specs[1].heading.value, Equals, "Spec Heading3")
}

func (s *MySuite) TestToSortSpecs(c *C) {
spec1 := &specification{fileName: "ab"}
spec2 := &specification{fileName: "b"}
Expand All @@ -267,96 +99,6 @@ func (s *MySuite) TestToSortSpecs(c *C) {
c.Assert(specs[2].fileName, Equals, spec3.fileName)
}

func (s *MySuite) TestToFilterSpecsByTagExpOfTwoTags(c *C) {
myTags := []string{"tag1", "tag2"}
tokens := []*token{
&token{kind: specKind, value: "Spec Heading1", lineNo: 1},
&token{kind: tagKind, args: myTags, lineNo: 2},
&token{kind: scenarioKind, value: "Scenario Heading 1", lineNo: 3},
&token{kind: scenarioKind, value: "Scenario Heading 2", lineNo: 4},
}
spec1, result := new(specParser).createSpecification(tokens, new(conceptDictionary))
c.Assert(result.ok, Equals, true)

tokens1 := []*token{
&token{kind: specKind, value: "Spec Heading2", lineNo: 1},
&token{kind: scenarioKind, value: "Scenario Heading 1", lineNo: 2},
&token{kind: scenarioKind, value: "Scenario Heading 2", lineNo: 3},
}
spec2, result := new(specParser).createSpecification(tokens1, new(conceptDictionary))
c.Assert(result.ok, Equals, true)

var specs []*specification
specs = append(specs, spec1)
specs = append(specs, spec2)

c.Assert(specs[0].tags.values[0], Equals, myTags[0])
c.Assert(specs[0].tags.values[1], Equals, myTags[1])
specs = filterSpecsByTags(specs, "tag1 & tag2")
c.Assert(len(specs), Equals, 1)
}

func (s *MySuite) TestToEvaluateTagExpression(c *C) {
myTags := []string{"tag1", "tag2"}
tokens := []*token{
&token{kind: specKind, value: "Spec Heading1", lineNo: 1},
&token{kind: scenarioKind, value: "Scenario Heading 01", lineNo: 2},
&token{kind: tagKind, args: []string{"tag1"}, lineNo: 3},
&token{kind: scenarioKind, value: "Scenario Heading 02", lineNo: 4},
&token{kind: tagKind, args: []string{"tag3"}, lineNo: 5},
}
spec1, result := new(specParser).createSpecification(tokens, new(conceptDictionary))
c.Assert(result.ok, Equals, true)

tokens1 := []*token{
&token{kind: specKind, value: "Spec Heading2", lineNo: 1},
&token{kind: tagKind, args: myTags, lineNo: 2},
&token{kind: scenarioKind, value: "Scenario Heading 1", lineNo: 3},
&token{kind: scenarioKind, value: "Scenario Heading 2", lineNo: 4},
}
spec2, result := new(specParser).createSpecification(tokens1, new(conceptDictionary))
c.Assert(result.ok, Equals, true)

var specs []*specification
specs = append(specs, spec1)
specs = append(specs, spec2)

specs = filterSpecsByTags(specs, "tag1 & !(tag1 & tag4) & (tag2 | tag3)")
c.Assert(len(specs), Equals, 1)
c.Assert(len(specs[0].scenarios), Equals, 2)
c.Assert(specs[0].scenarios[0].heading.value, Equals, "Scenario Heading 1")
c.Assert(specs[0].scenarios[1].heading.value, Equals, "Scenario Heading 2")
}

func (s *MySuite) TestToFilterSpecsByWrongTagExpression(c *C) {
myTags := []string{"tag1", "tag2"}
tokens := []*token{
&token{kind: specKind, value: "Spec Heading1", lineNo: 1},
&token{kind: tagKind, args: myTags, lineNo: 2},
&token{kind: scenarioKind, value: "Scenario Heading 1", lineNo: 3},
&token{kind: scenarioKind, value: "Scenario Heading 2", lineNo: 4},
}
spec1, result := new(specParser).createSpecification(tokens, new(conceptDictionary))
c.Assert(result.ok, Equals, true)

tokens1 := []*token{
&token{kind: specKind, value: "Spec Heading2", lineNo: 1},
&token{kind: scenarioKind, value: "Scenario Heading 1", lineNo: 2},
&token{kind: scenarioKind, value: "Scenario Heading 2", lineNo: 3},
}
spec2, result := new(specParser).createSpecification(tokens1, new(conceptDictionary))
c.Assert(result.ok, Equals, true)

var specs []*specification
specs = append(specs, spec1)
specs = append(specs, spec2)

c.Assert(specs[0].tags.values[0], Equals, myTags[0])
c.Assert(specs[0].tags.values[1], Equals, myTags[1])
specs = filterSpecsByTags(specs, "(tag1 & tag2")
c.Assert(len(specs), Equals, 0)
}

func (s *MySuite) TestToShuffleSpecsToRandomize(c *C) {
var specs []*specification
specs = append(specs, &specification{fileName: "a"}, &specification{fileName: "b"}, &specification{fileName: "c"}, &specification{fileName: "d"},
Expand Down
Loading

0 comments on commit a1e5612

Please sign in to comment.