Fix a bug where tokens without spaces were parsed incorrectly

This commit is contained in:
David Jennes
2018-09-26 03:06:49 +02:00
parent c7dbba41a5
commit 2e67755118
2 changed files with 13 additions and 5 deletions

View File

@@ -146,7 +146,7 @@ class Scanner {
for (index, char) in content.unicodeScalars.enumerated() {
if foundChar && char == Scanner.tokenEndDelimiter {
let result = String(content.prefix(index))
let result = String(content.prefix(index + 1))
content = String(content.dropFirst(index + 1))
range = range.upperBound..<originalContent.index(range.upperBound, offsetBy: index + 1)
return result

View File

@@ -16,7 +16,7 @@ class LexerTests: XCTestCase {
let tokens = lexer.tokenize()
try expect(tokens.count) == 1
try expect(tokens.first) == .text(value: "Hello World", at: SourceMap(location: ("Hello World", 1, 0)))
try expect(tokens.first) == .text(value: "Hello World", at: makeSourceMap("Hello World", for: lexer))
}
$0.it("can tokenize a comment") {
@@ -24,7 +24,7 @@ class LexerTests: XCTestCase {
let tokens = lexer.tokenize()
try expect(tokens.count) == 1
try expect(tokens.first) == .comment(value: "Comment", at: SourceMap(location: ("{# Comment #}", 1, 3)))
try expect(tokens.first) == .comment(value: "Comment", at: makeSourceMap("Comment", for: lexer))
}
$0.it("can tokenize a variable") {
@@ -32,7 +32,15 @@ class LexerTests: XCTestCase {
let tokens = lexer.tokenize()
try expect(tokens.count) == 1
try expect(tokens.first) == .variable(value: "Variable", at: SourceMap(location: ("{{ Variable }}", 1, 3)))
try expect(tokens.first) == .variable(value: "Variable", at: makeSourceMap("Variable", for: lexer))
}
$0.it("can tokenize a token without spaces") {
let lexer = Lexer(templateString: "{{Variable}}")
let tokens = lexer.tokenize()
try expect(tokens.count) == 1
try expect(tokens.first) == .variable(value: "Variable", at: makeSourceMap("Variable", for: lexer))
}
$0.it("can tokenize unclosed tag by ignoring it") {
@@ -41,7 +49,7 @@ class LexerTests: XCTestCase {
let tokens = lexer.tokenize()
try expect(tokens.count) == 1
try expect(tokens.first) == .text(value: "", at: SourceMap(location: ("{{ thing", 1, 0)))
try expect(tokens.first) == .text(value: "", at: makeSourceMap("{{ thing", for: lexer))
}
$0.it("can tokenize a mixture of content") {