Skip to content

Commit

Permalink
[master] - 'Gherkin language error for unexpected EOF - TT'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler-Keith-Thompson committed Dec 9, 2019
1 parent 40c0c06 commit e500646
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
5 changes: 4 additions & 1 deletion CucumberSwift/Gherkin/AST/AST.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AST {
self.ruleLookup = ruleLookup
}

func parse(_ tokens:[Lexer.Token]) -> [FeatureNode] {
func parse(_ tokens:[Lexer.Token], inFile url:String = "") -> [FeatureNode] {
for token in tokens {
if case Lexer.Token.tag(_) = token {
tags.append(token)
Expand All @@ -45,6 +45,9 @@ class AST {
currentNode?.tokens.append(token)
}
}
if (!tags.isEmpty) {
Gherkin.errors.append("File: \(url) unexpected end of file, expected: #TagLine, #ScenarioLine, #Comment, #Empty")
}
return featureNodes
}
var featureNodes:[FeatureNode] = []
Expand Down
27 changes: 9 additions & 18 deletions CucumberSwift/Gherkin/Parser/Scope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,15 @@ enum Scope: Equatable {

static func == (lhs: Scope, rhs: Scope) -> Bool {
switch (lhs, rhs) {
case (.feature, .feature):
return true
case (.background, .background):
return true
case (.scenario, .scenario):
return true
case (.scenarioOutline, .scenarioOutline):
return true
case (.step(let s1), .step(let s2)):
return s1 == s2
case (.examples, .examples):
return true
case (.rule, .rule):
return true
case (.unknown, .unknown):
return true
default:
return false
case (.feature, .feature): return true
case (.background, .background): return true
case (.scenario, .scenario): return true
case (.scenarioOutline, .scenarioOutline): return true
case (.step(let s1), .step(let s2)): return s1 == s2
case (.examples, .examples): return true
case (.rule, .rule): return true
case (.unknown, .unknown): return true
default: return false
}
}

Expand Down
2 changes: 1 addition & 1 deletion CucumberSwift/Runner/Cucumber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ import XCTest

func parseIntoFeatures(_ string:String, uri:String = "") {
let tokens = Lexer(string, uri:uri).lex()
features.append(contentsOf: AST.standard.parse(tokens)
features.append(contentsOf: AST.standard.parse(tokens, inFile: uri)
.map { Feature(with: $0, uri:uri) })
}

Expand Down
13 changes: 13 additions & 0 deletions CucumberSwiftTests/Gherkin/ErrorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ class ErrorsTests : XCTestCase {
""", uri: "failedLanguage.feature")
XCTAssert(Gherkin.errors.contains("File: failedLanguage.feature declares an unsupported language"))
}

func testUnexpectedEndOfFile() {
Cucumber.shared.parseIntoFeatures("""
Feature: Unexpected end of file
Scenario Outline: minimalistic
Given the minimalism
@tag
""", uri: "unexpected_eof.feature")
XCTAssert(Gherkin.errors.contains("File: unexpected_eof.feature unexpected end of file, expected: #TagLine, #ScenarioLine, #Comment, #Empty"))
}

override func tearDown() {
Gherkin.errors.removeAll()
}
Expand Down

0 comments on commit e500646

Please sign in to comment.