github.com/mattdotmatt/gauge@v0.3.2-0.20160421115137-425a4cdccb62/parser/processor_test.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 parser 19 20 import ( 21 . "gopkg.in/check.v1" 22 ) 23 24 func (s *MySuite) TestProcessingTokensGivesErrorWhenSpecHeadingIsEmpty(c *C) { 25 parser := &SpecParser{} 26 parser.lineNo = 2 27 token := &Token{Value: ""} 28 29 err, shouldSkip := processSpec(parser, token) 30 31 c.Assert(shouldSkip, Equals, true) 32 c.Assert(err.LineNo, Equals, 2) 33 c.Assert(err.Message, Equals, "Spec heading should have at least one character") 34 c.Assert(err.LineText, Equals, "") 35 } 36 37 func (s *MySuite) TestProcessingTokensGivesErrorWhenSpecHeadingHasOnlySpaces(c *C) { 38 parser := &SpecParser{} 39 parser.lineNo = 2 40 spaces := " " 41 token := &Token{Value: spaces} 42 43 err, shouldSkip := processSpec(parser, token) 44 45 c.Assert(shouldSkip, Equals, true) 46 c.Assert(err.LineNo, Equals, 2) 47 c.Assert(err.Message, Equals, "Spec heading should have at least one character") 48 c.Assert(err.LineText, Equals, spaces) 49 } 50 51 func (s *MySuite) TestProcessingTokensGivesNoErrorForValidSpecHeading(c *C) { 52 parser := &SpecParser{} 53 parser.lineNo = 2 54 token := &Token{Value: "SPECHEADING"} 55 var nilErr *ParseError 56 57 err, shouldSkip := processSpec(parser, token) 58 59 c.Assert(shouldSkip, Equals, false) 60 c.Assert(err, Equals, nilErr) 61 } 62 63 func (s *MySuite) TestProcessingTokensGivesErrorWhenScenarioHeadingIsEmpty(c *C) { 64 parser := &SpecParser{} 65 parser.lineNo = 2 66 token := &Token{Value: ""} 67 68 err, shouldSkip := processScenario(parser, token) 69 70 c.Assert(shouldSkip, Equals, true) 71 c.Assert(err.LineNo, Equals, 2) 72 c.Assert(err.Message, Equals, "Scenario heading should have at least one character") 73 c.Assert(err.LineText, Equals, "") 74 } 75 76 func (s *MySuite) TestProcessingTokensGivesErrorWhenScenarioHeadingHasOnlySpaces(c *C) { 77 parser := &SpecParser{} 78 parser.lineNo = 2 79 spaces := " " 80 token := &Token{Value: spaces} 81 82 err, shouldSkip := processScenario(parser, token) 83 84 c.Assert(shouldSkip, Equals, true) 85 c.Assert(err.LineNo, Equals, 2) 86 c.Assert(err.Message, Equals, "Scenario heading should have at least one character") 87 c.Assert(err.LineText, Equals, spaces) 88 } 89 90 func (s *MySuite) TestProcessingTokensGivesNoErrorForValidScenarioHeading(c *C) { 91 parser := &SpecParser{} 92 parser.lineNo = 2 93 token := &Token{Value: "SCENARIOHEADING"} 94 var nilErr *ParseError 95 96 err, shouldSkip := processScenario(parser, token) 97 98 c.Assert(shouldSkip, Equals, false) 99 c.Assert(err, Equals, nilErr) 100 }