Add test for crashing
This commit is contained in:
@@ -61,36 +61,42 @@ class LexerTests: XCTestCase {
|
|||||||
|
|
||||||
$0.it("can tokenize an unclosed block") {
|
$0.it("can tokenize an unclosed block") {
|
||||||
let lexer = Lexer(templateString: "{%}")
|
let lexer = Lexer(templateString: "{%}")
|
||||||
let _ = lexer.tokenize()
|
_ = lexer.tokenize()
|
||||||
|
}
|
||||||
|
|
||||||
|
$0.it("can tokenize incorrect syntax without crashing") {
|
||||||
|
let lexer = Lexer(templateString: "func some() {{% if %}")
|
||||||
|
_ = lexer.tokenize()
|
||||||
}
|
}
|
||||||
|
|
||||||
$0.it("can tokenize an empty variable") {
|
$0.it("can tokenize an empty variable") {
|
||||||
let lexer = Lexer(templateString: "{{}}")
|
let lexer = Lexer(templateString: "{{}}")
|
||||||
let _ = lexer.tokenize()
|
_ = lexer.tokenize()
|
||||||
}
|
}
|
||||||
|
|
||||||
$0.it("can tokenize with new lines") {
|
$0.it("can tokenize with new lines") {
|
||||||
let templateString = """
|
let templateString = """
|
||||||
My name is {%
|
My name is {%
|
||||||
if name
|
if name
|
||||||
and
|
and
|
||||||
name
|
name
|
||||||
%}{{
|
%}{{
|
||||||
name
|
name
|
||||||
}}{%
|
}}{%
|
||||||
endif %}.
|
endif %}.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
let lexer = Lexer(templateString: templateString)
|
let lexer = Lexer(templateString: templateString)
|
||||||
|
|
||||||
let tokens = lexer.tokenize()
|
let tokens = lexer.tokenize()
|
||||||
|
|
||||||
try expect(tokens.count) == 5
|
try expect(tokens.count) == 5
|
||||||
try expect(tokens[0]) == Token.text(value: "My name is ", at: SourceMap(location: lexer.rangeLocation(templateString.range(of: "My name is")!)))
|
try expect(tokens[0]) == Token.text(value: "My name is ", at: SourceMap(location: lexer.rangeLocation(templateString.range(of: "My name is")!)))
|
||||||
try expect(tokens[1]) == Token.block(value: "if name and name", at: SourceMap(location: lexer.rangeLocation(templateString.range(of: "{%")!)))
|
try expect(tokens[1]) == Token.block(value: "if name and name", at: SourceMap(location: lexer.rangeLocation(templateString.range(of: "{%")!)))
|
||||||
try expect(tokens[2]) == Token.variable(value: "name", at: SourceMap(location: lexer.rangeLocation(templateString.range(of: "name", options: [.backwards])!)))
|
try expect(tokens[2]) == Token.variable(value: "name", at: SourceMap(location: lexer.rangeLocation(templateString.range(of: "name", options: [.backwards])!)))
|
||||||
try expect(tokens[3]) == Token.block(value: "endif", at: SourceMap(location: lexer.rangeLocation(templateString.range(of: "endif")!)))
|
try expect(tokens[3]) == Token.block(value: "endif", at: SourceMap(location: lexer.rangeLocation(templateString.range(of: "endif")!)))
|
||||||
try expect(tokens[4]) == Token.text(value: ".", at: SourceMap(location: lexer.rangeLocation(templateString.range(of: ".")!)))
|
try expect(tokens[4]) == Token.text(value: ".", at: SourceMap(location: lexer.rangeLocation(templateString.range(of: ".")!)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user