github.com/mattdotmatt/gauge@v0.3.2-0.20160421115137-425a4cdccb62/gauge/scenario.go (about)

     1  // Copyright 2015 ThoughtWorks, Inc.
     2  
     3  // This file is part of Gauge.
     4  
     5  // Gauge is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  
    10  // Gauge is distributed in the hope that it will be useful,
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  // GNU General Public License for more details.
    14  
    15  // You should have received a copy of the GNU General Public License
    16  // along with Gauge.  If not, see <http://www.gnu.org/licenses/>.
    17  
    18  package gauge
    19  
    20  type Scenario struct {
    21  	Heading  *Heading
    22  	Steps    []*Step
    23  	Comments []*Comment
    24  	Tags     *Tags
    25  	Items    []Item
    26  }
    27  
    28  func (scenario *Scenario) AddHeading(heading *Heading) {
    29  	heading.HeadingType = ScenarioHeading
    30  	scenario.Heading = heading
    31  }
    32  
    33  func (scenario *Scenario) AddStep(step *Step) {
    34  	scenario.Steps = append(scenario.Steps, step)
    35  	scenario.AddItem(step)
    36  }
    37  
    38  func (scenario *Scenario) AddTags(tags *Tags) {
    39  	scenario.Tags = tags
    40  	scenario.AddItem(tags)
    41  }
    42  
    43  func (scenario *Scenario) AddComment(comment *Comment) {
    44  	scenario.Comments = append(scenario.Comments, comment)
    45  	scenario.AddItem(comment)
    46  }
    47  
    48  func (scenario *Scenario) renameSteps(oldStep Step, newStep Step, orderMap map[int]int) bool {
    49  	isRefactored := false
    50  	for _, step := range scenario.Steps {
    51  		isConcept := false
    52  		isRefactored = step.Rename(oldStep, newStep, isRefactored, orderMap, &isConcept)
    53  	}
    54  	return isRefactored
    55  }
    56  
    57  func (scenario *Scenario) AddItem(itemToAdd Item) {
    58  	if scenario.Items == nil {
    59  		scenario.Items = make([]Item, 0)
    60  	}
    61  	scenario.Items = append(scenario.Items, itemToAdd)
    62  }
    63  
    64  func (scenario *Scenario) LatestStep() *Step {
    65  	return scenario.Steps[len(scenario.Steps)-1]
    66  }
    67  
    68  func (scenario *Scenario) Traverse(traverser ScenarioTraverser) {
    69  	traverser.ScenarioHeading(scenario.Heading)
    70  	for _, item := range scenario.Items {
    71  		switch item.Kind() {
    72  		case StepKind:
    73  			traverser.Step(item.(*Step))
    74  		case CommentKind:
    75  			traverser.Comment(item.(*Comment))
    76  		case TagKind:
    77  			traverser.ScenarioTags(item.(*Tags))
    78  		}
    79  	}
    80  }
    81  
    82  func (scenario Scenario) Kind() TokenKind {
    83  	return ScenarioKind
    84  }