swift format
This commit is contained in:
@@ -404,6 +404,7 @@ extension HBParser {
|
|||||||
func getPosition() -> Int {
|
func getPosition() -> Int {
|
||||||
return index
|
return index
|
||||||
}
|
}
|
||||||
|
|
||||||
mutating func setPosition(_ index: Int) throws {
|
mutating func setPosition(_ index: Int) throws {
|
||||||
guard range.contains(index) else { throw Error.invalidPosition }
|
guard range.contains(index) else { throw Error.invalidPosition }
|
||||||
guard validateUTF8Character(at: index).0 != nil else { throw Error.invalidPosition }
|
guard validateUTF8Character(at: index).0 != nil else { throw Error.invalidPosition }
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ extension HBMustacheTemplate {
|
|||||||
// section
|
// section
|
||||||
parser.unsafeAdvance()
|
parser.unsafeAdvance()
|
||||||
let (name, method) = try parseName(&parser)
|
let (name, method) = try parseName(&parser)
|
||||||
if newLine && hasLineFinished(&parser) {
|
if newLine, hasLineFinished(&parser) {
|
||||||
setNewLine = true
|
setNewLine = true
|
||||||
if parser.current() == "\n" {
|
if parser.current() == "\n" {
|
||||||
parser.unsafeAdvance()
|
parser.unsafeAdvance()
|
||||||
@@ -77,7 +77,7 @@ extension HBMustacheTemplate {
|
|||||||
// inverted section
|
// inverted section
|
||||||
parser.unsafeAdvance()
|
parser.unsafeAdvance()
|
||||||
let (name, method) = try parseName(&parser)
|
let (name, method) = try parseName(&parser)
|
||||||
if newLine && hasLineFinished(&parser) {
|
if newLine, hasLineFinished(&parser) {
|
||||||
setNewLine = true
|
setNewLine = true
|
||||||
if parser.current() == "\n" {
|
if parser.current() == "\n" {
|
||||||
parser.unsafeAdvance()
|
parser.unsafeAdvance()
|
||||||
@@ -96,7 +96,7 @@ extension HBMustacheTemplate {
|
|||||||
guard name == sectionName else {
|
guard name == sectionName else {
|
||||||
throw Error.sectionCloseNameIncorrect
|
throw Error.sectionCloseNameIncorrect
|
||||||
}
|
}
|
||||||
if newLine && hasLineFinished(&parser) {
|
if newLine, hasLineFinished(&parser) {
|
||||||
setNewLine = true
|
setNewLine = true
|
||||||
if parser.current() == "\n" {
|
if parser.current() == "\n" {
|
||||||
parser.unsafeAdvance()
|
parser.unsafeAdvance()
|
||||||
@@ -111,7 +111,7 @@ extension HBMustacheTemplate {
|
|||||||
// comment
|
// comment
|
||||||
parser.unsafeAdvance()
|
parser.unsafeAdvance()
|
||||||
_ = try parseComment(&parser)
|
_ = try parseComment(&parser)
|
||||||
if newLine && hasLineFinished(&parser) {
|
if newLine, hasLineFinished(&parser) {
|
||||||
setNewLine = true
|
setNewLine = true
|
||||||
if !parser.reachedEnd() {
|
if !parser.reachedEnd() {
|
||||||
parser.unsafeAdvance()
|
parser.unsafeAdvance()
|
||||||
@@ -152,7 +152,7 @@ extension HBMustacheTemplate {
|
|||||||
if whiteSpaceBefore.count > 0 {
|
if whiteSpaceBefore.count > 0 {
|
||||||
tokens.append(.text(whiteSpaceBefore))
|
tokens.append(.text(whiteSpaceBefore))
|
||||||
}
|
}
|
||||||
if newLine && hasLineFinished(&parser) {
|
if newLine, hasLineFinished(&parser) {
|
||||||
setNewLine = true
|
setNewLine = true
|
||||||
if parser.current() == "\n" {
|
if parser.current() == "\n" {
|
||||||
parser.unsafeAdvance()
|
parser.unsafeAdvance()
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ func test(_ object: Any, _ template: String, _ expected: String) throws {
|
|||||||
// MARK: Comments
|
// MARK: Comments
|
||||||
|
|
||||||
final class SpecCommentsTests: XCTestCase {
|
final class SpecCommentsTests: XCTestCase {
|
||||||
|
|
||||||
func testInline() throws {
|
func testInline() throws {
|
||||||
let object = {}
|
let object = {}
|
||||||
let template = "12345{{! Comment Block! }}67890"
|
let template = "12345{{! Comment Block! }}67890"
|
||||||
@@ -121,7 +120,6 @@ final class SpecInterpolationTests: XCTestCase {
|
|||||||
let template = "Hello from {Mustache}!"
|
let template = "Hello from {Mustache}!"
|
||||||
let expected = "Hello from {Mustache}!"
|
let expected = "Hello from {Mustache}!"
|
||||||
try test(object, template, expected)
|
try test(object, template, expected)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testBasicInterpolation() throws {
|
func testBasicInterpolation() throws {
|
||||||
@@ -129,7 +127,6 @@ final class SpecInterpolationTests: XCTestCase {
|
|||||||
let template = "Hello, {{subject}}!"
|
let template = "Hello, {{subject}}!"
|
||||||
let expected = "Hello, world!"
|
let expected = "Hello, world!"
|
||||||
try test(object, template, expected)
|
try test(object, template, expected)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testHTMLEscaping() throws {
|
func testHTMLEscaping() throws {
|
||||||
@@ -137,7 +134,6 @@ final class SpecInterpolationTests: XCTestCase {
|
|||||||
let template = "These characters should be HTML escaped: {{forbidden}}"
|
let template = "These characters should be HTML escaped: {{forbidden}}"
|
||||||
let expected = #"These characters should be HTML escaped: & " < >"#
|
let expected = #"These characters should be HTML escaped: & " < >"#
|
||||||
try test(object, template, expected)
|
try test(object, template, expected)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testTripleMustache() throws {
|
func testTripleMustache() throws {
|
||||||
@@ -145,7 +141,6 @@ final class SpecInterpolationTests: XCTestCase {
|
|||||||
let template = "These characters should not be HTML escaped: {{{forbidden}}}"
|
let template = "These characters should not be HTML escaped: {{{forbidden}}}"
|
||||||
let expected = #"These characters should not be HTML escaped: & " < >"#
|
let expected = #"These characters should not be HTML escaped: & " < >"#
|
||||||
try test(object, template, expected)
|
try test(object, template, expected)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAmpersand() throws {
|
func testAmpersand() throws {
|
||||||
@@ -153,7 +148,6 @@ final class SpecInterpolationTests: XCTestCase {
|
|||||||
let template = "These characters should not be HTML escaped: {{&forbidden}}"
|
let template = "These characters should not be HTML escaped: {{&forbidden}}"
|
||||||
let expected = #"These characters should not be HTML escaped: & " < >"#
|
let expected = #"These characters should not be HTML escaped: & " < >"#
|
||||||
try test(object, template, expected)
|
try test(object, template, expected)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testBasicInteger() throws {
|
func testBasicInteger() throws {
|
||||||
@@ -250,7 +244,7 @@ final class SpecInterpolationTests: XCTestCase {
|
|||||||
func testInitialResolutionDottedName() throws {
|
func testInitialResolutionDottedName() throws {
|
||||||
let object = [
|
let object = [
|
||||||
"a": ["b": ["c": ["d": ["e": ["name": "Phil"]]]]],
|
"a": ["b": ["c": ["d": ["e": ["name": "Phil"]]]]],
|
||||||
"b": ["c": ["d": ["e": ["name": "Wrong"]]]]
|
"b": ["c": ["d": ["e": ["name": "Wrong"]]]],
|
||||||
]
|
]
|
||||||
let template = #""{{#a}}{{b.c.d.e.name}}{{/a}}" == "Phil""#
|
let template = #""{{#a}}{{b.c.d.e.name}}{{/a}}" == "Phil""#
|
||||||
let expected = #""Phil" == "Phil""#
|
let expected = #""Phil" == "Phil""#
|
||||||
@@ -260,7 +254,7 @@ final class SpecInterpolationTests: XCTestCase {
|
|||||||
func testContextPrecedenceDottedName() throws {
|
func testContextPrecedenceDottedName() throws {
|
||||||
let object = [
|
let object = [
|
||||||
"a": ["b": []],
|
"a": ["b": []],
|
||||||
"b": ["c": "Error"]
|
"b": ["c": "Error"],
|
||||||
]
|
]
|
||||||
let template = #"{{#a}}{{b.c}}{{/a}}"#
|
let template = #"{{#a}}{{b.c}}{{/a}}"#
|
||||||
let expected = ""
|
let expected = ""
|
||||||
@@ -314,7 +308,6 @@ final class SpecInterpolationTests: XCTestCase {
|
|||||||
let template = "|{{ string }}|"
|
let template = "|{{ string }}|"
|
||||||
let expected = "|---|"
|
let expected = "|---|"
|
||||||
try test(object, template, expected)
|
try test(object, template, expected)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testTripleMustacheWithPadding() throws {
|
func testTripleMustacheWithPadding() throws {
|
||||||
@@ -322,7 +315,6 @@ final class SpecInterpolationTests: XCTestCase {
|
|||||||
let template = "|{{{ string }}}|"
|
let template = "|{{{ string }}}|"
|
||||||
let expected = "|---|"
|
let expected = "|---|"
|
||||||
try test(object, template, expected)
|
try test(object, template, expected)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAmpersandWithPadding() throws {
|
func testAmpersandWithPadding() throws {
|
||||||
@@ -341,7 +333,6 @@ final class SpecInvertedTests: XCTestCase {
|
|||||||
let template = #""{{^boolean}}This should be rendered.{{/boolean}}""#
|
let template = #""{{^boolean}}This should be rendered.{{/boolean}}""#
|
||||||
let expected = #""This should be rendered.""#
|
let expected = #""This should be rendered.""#
|
||||||
try test(object, template, expected)
|
try test(object, template, expected)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testTrue() throws {
|
func testTrue() throws {
|
||||||
@@ -349,7 +340,6 @@ final class SpecInvertedTests: XCTestCase {
|
|||||||
let template = #""{{^boolean}}This should not be rendered.{{/boolean}}""#
|
let template = #""{{^boolean}}This should not be rendered.{{/boolean}}""#
|
||||||
let expected = "\"\""
|
let expected = "\"\""
|
||||||
try test(object, template, expected)
|
try test(object, template, expected)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testContext() throws {
|
func testContext() throws {
|
||||||
@@ -357,7 +347,6 @@ final class SpecInvertedTests: XCTestCase {
|
|||||||
let template = #""{{^context}}Hi {{name}}.{{/context}}""#
|
let template = #""{{^context}}Hi {{name}}.{{/context}}""#
|
||||||
let expected = "\"\""
|
let expected = "\"\""
|
||||||
try test(object, template, expected)
|
try test(object, template, expected)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testList() throws {
|
func testList() throws {
|
||||||
@@ -365,7 +354,6 @@ final class SpecInvertedTests: XCTestCase {
|
|||||||
let template = #""{{^list}}{{n}}{{/list}}""#
|
let template = #""{{^list}}{{n}}{{/list}}""#
|
||||||
let expected = "\"\""
|
let expected = "\"\""
|
||||||
try test(object, template, expected)
|
try test(object, template, expected)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testEmptyList() throws {
|
func testEmptyList() throws {
|
||||||
@@ -442,7 +430,6 @@ final class SpecInvertedTests: XCTestCase {
|
|||||||
let template = " | {{^boolean}}\t|\t{{/boolean}} | \n"
|
let template = " | {{^boolean}}\t|\t{{/boolean}} | \n"
|
||||||
let expected = " | \t|\t | \n"
|
let expected = " | \t|\t | \n"
|
||||||
try test(object, template, expected)
|
try test(object, template, expected)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testInternalWhitespace() throws {
|
func testInternalWhitespace() throws {
|
||||||
@@ -450,7 +437,6 @@ final class SpecInvertedTests: XCTestCase {
|
|||||||
let template = " | {{^boolean}} {{! Important Whitespace }}\n {{/boolean}} | \n"
|
let template = " | {{^boolean}} {{! Important Whitespace }}\n {{/boolean}} | \n"
|
||||||
let expected = " | \n | \n"
|
let expected = " | \n | \n"
|
||||||
try test(object, template, expected)
|
try test(object, template, expected)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testIndentedInline() throws {
|
func testIndentedInline() throws {
|
||||||
@@ -458,7 +444,6 @@ final class SpecInvertedTests: XCTestCase {
|
|||||||
let template = " {{^boolean}}NO{{/boolean}}\n {{^boolean}}WAY{{/boolean}}\n"
|
let template = " {{^boolean}}NO{{/boolean}}\n {{^boolean}}WAY{{/boolean}}\n"
|
||||||
let expected = " NO\n WAY\n"
|
let expected = " NO\n WAY\n"
|
||||||
try test(object, template, expected)
|
try test(object, template, expected)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testStandaloneLines() throws {
|
func testStandaloneLines() throws {
|
||||||
@@ -476,7 +461,6 @@ final class SpecInvertedTests: XCTestCase {
|
|||||||
| A Line
|
| A Line
|
||||||
"""
|
"""
|
||||||
try test(object, template, expected)
|
try test(object, template, expected)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testStandaloneIndentedLines() throws {
|
func testStandaloneIndentedLines() throws {
|
||||||
@@ -501,7 +485,6 @@ final class SpecInvertedTests: XCTestCase {
|
|||||||
let template = "|\r\n{{^boolean}}\r\n{{/boolean}}\r\n|"
|
let template = "|\r\n{{^boolean}}\r\n{{/boolean}}\r\n|"
|
||||||
let expected = "|\r\n|"
|
let expected = "|\r\n|"
|
||||||
try test(object, template, expected)
|
try test(object, template, expected)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testStandaloneWithoutPreviousLine() throws {
|
func testStandaloneWithoutPreviousLine() throws {
|
||||||
@@ -653,7 +636,6 @@ final class SpecSectionTests: XCTestCase {
|
|||||||
let template = #""{{#boolean}}This should be rendered.{{/boolean}}""#
|
let template = #""{{#boolean}}This should be rendered.{{/boolean}}""#
|
||||||
let expected = #""This should be rendered.""#
|
let expected = #""This should be rendered.""#
|
||||||
try test(object, template, expected)
|
try test(object, template, expected)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testFalse() throws {
|
func testFalse() throws {
|
||||||
@@ -661,7 +643,6 @@ final class SpecSectionTests: XCTestCase {
|
|||||||
let template = #""{{#boolean}}This should not be rendered.{{/boolean}}""#
|
let template = #""{{#boolean}}This should not be rendered.{{/boolean}}""#
|
||||||
let expected = "\"\""
|
let expected = "\"\""
|
||||||
try test(object, template, expected)
|
try test(object, template, expected)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testContext() throws {
|
func testContext() throws {
|
||||||
@@ -819,7 +800,6 @@ final class SpecSectionTests: XCTestCase {
|
|||||||
try test(object, template, expected)
|
try test(object, template, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func testDottedNameTrue() throws {
|
func testDottedNameTrue() throws {
|
||||||
let object = ["a": ["b": ["c": true]]]
|
let object = ["a": ["b": ["c": true]]]
|
||||||
let template = #""{{#a.b.c}}Here{{/a.b.c}}" == "Here""#
|
let template = #""{{#a.b.c}}Here{{/a.b.c}}" == "Here""#
|
||||||
|
|||||||
Reference in New Issue
Block a user