Skip to content

Commit

Permalink
Merge pull request #49 from vapor/build-errors
Browse files Browse the repository at this point in the history
Build errors
  • Loading branch information
loganwright authored Mar 20, 2017
2 parents 9fffbb4 + 6928480 commit 79a2d4d
Show file tree
Hide file tree
Showing 28 changed files with 95 additions and 93 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/.build
/Packages
/*.xcodeproj
Package.pins
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ sudo: required
dist: trusty
osx_image: xcode8
script:
- eval "$(curl -sL swift.vapor.sh/ci)"
- eval "$(curl -sL swift.vapor.sh/ci-3.1)"
- eval "$(curl -sL swift.vapor.sh/codecov)"
10 changes: 5 additions & 5 deletions Sources/Leaf/Buffer/Buffer+Leaf.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ extension BufferProtocol where Element == Byte {
guard current == .leftParenthesis else {
throw ParseError.expectedOpenParenthesis
}
return name.string
return name.makeString()
}

mutating func extractInstructionParameters() throws -> [Parameter] {
Expand All @@ -106,13 +106,13 @@ extension BufferProtocol where Element == Byte {
mutating func extractBody() throws -> String {
return try extractSection(opensWith: .leftCurlyBracket, closesWith: .rightCurlyBracket)
.trimmed(.whitespace)
.string
.makeString()
}

mutating func extractSection(opensWith opener: Byte, closesWith closer: Byte) throws -> Bytes {
guard current == opener else {
let have = current.flatMap { [$0] }?.string
throw ParseError.missingBodyOpener(expected: [opener].string, have: have)
let have = current.flatMap { [$0] }?.makeString()
throw ParseError.missingBodyOpener(expected: [opener].makeString(), have: have)
}

var subBodies = 0
Expand All @@ -129,7 +129,7 @@ extension BufferProtocol where Element == Byte {
}

guard current == closer else {
throw ParseError.missingBodyCloser(expected: [closer].string)
throw ParseError.missingBodyCloser(expected: [closer].makeString())
}

return body
Expand Down
2 changes: 1 addition & 1 deletion Sources/Leaf/Context.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public final class Context {

// TODO: Subscripts

func get<T: PathIndex>(path: [T]) -> Node? {
func get<T: PathIndexer>(path: [T]) -> Node? {
var next = queue.tip
repeat {
if let value = next?.value[path] { return value }
Expand Down
2 changes: 1 addition & 1 deletion Sources/Leaf/HTMLEscape.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ extension String {
.joined(separator: "&lt;".makeBytes())
.split(separator: .greaterThan, omittingEmptySubsequences: false)
.joined(separator: "&gt;".makeBytes())
.string
.makeString()
}
}
2 changes: 1 addition & 1 deletion Sources/Leaf/LeafComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extension Leaf.Component: CustomStringConvertible {
public var description: String {
switch self {
case let .raw(r):
return ".raw(\(r.string))"
return ".raw(\(r.makeString()))"
case let .tagTemplate(i):
return ".tagTemplate(\(i))"
case let .chain(chain):
Expand Down
2 changes: 1 addition & 1 deletion Sources/Leaf/Node+Rendered.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extension Node {
func rendered() throws -> Bytes {
switch self {
switch self.wrapped {
case .array(_), .object(_), .null:
return []
case let .bool(bool):
Expand Down
4 changes: 2 additions & 2 deletions Sources/Leaf/Parameter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ extension Parameter {
let bytes = bytes.array.trimmed(.whitespace)
guard !bytes.isEmpty else { throw Error.nonEmptyArgumentRequired }
if bytes.count > 1, bytes.first == .quote, bytes.last == .quote {
self = .constant(value: bytes.dropFirst().dropLast().string)
self = .constant(value: bytes.dropFirst().dropLast().makeString())
} else {
let path = bytes.split(
separator: .period,
omittingEmptySubsequences: true
)
.map { $0.string }
.map { $0.makeString() }
self = .variable(path: path)
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Leaf/Stem+Spawn.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extension Stem {
let raw = raw.trimmed(.whitespace)
var buffer = Buffer(raw)
let components = try buffer.components(stem: self).map(postCompile)
var leaf = Leaf(raw: raw.string, components: components)
var leaf = Leaf(raw: raw.makeString(), components: components)
try tags.values.forEach {
leaf = try $0.postCompile(stem: self, leaf: leaf)
}
Expand All @@ -26,7 +26,7 @@ extension Stem {
let path = workingDirectory + name
let bytes = try Bytes.load(path: path)
let component = Leaf.Component.raw(bytes)
let leaf = Leaf(raw: bytes.string, components: [component])
let leaf = Leaf(raw: bytes.makeString(), components: [component])
cache(leaf, named: name)
return leaf
}
Expand Down
14 changes: 7 additions & 7 deletions Sources/Leaf/Tag/Models/Equal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ fileprivate func fuzzyEquals(_ lhs: Node?, _ rhs: Node?) -> Bool {
let lhs = lhs ?? .null
let rhs = rhs ?? .null

switch lhs {
switch lhs.wrapped {
case let .array(lhs):
guard let rhs = rhs.nodeArray else { return false }
guard let rhs = rhs.array else { return false }
guard lhs.count == rhs.count else { return false }
for (l, r) in zip(lhs, rhs) where !fuzzyEquals(l, r) { return false }
for (l, r) in zip(lhs, rhs) where !fuzzyEquals(Node(l), r) { return false }
return true
case let .bool(bool):
return bool == rhs.bool
case let .bytes(bytes):
guard case let .bytes(rhs) = rhs else { return false }
guard case let .bytes(rhs) = rhs.wrapped else { return false }
return bytes == rhs
case .null:
return rhs.isNull
Expand All @@ -48,15 +48,15 @@ fileprivate func fuzzyEquals(_ lhs: Node?, _ rhs: Node?) -> Bool {
return uint == rhs.uint
}
case let .object(lhs):
guard let rhs = rhs.nodeObject else { return false }
guard let rhs = rhs.object else { return false }
guard lhs.count == rhs.count else { return false }
for (k, v) in lhs where !fuzzyEquals(v, rhs[k]) { return false }
for (k, v) in lhs where !fuzzyEquals(Node(v), rhs[k]) { return false }
return true
case let .string(string):
return string == rhs.string
case let .date(date):
// FIXME: Add fuzzy date access and equality?
guard case let .date(right) = rhs else { return false }
guard case let .date(right) = rhs.wrapped else { return false }
return date == right
}
}
2 changes: 1 addition & 1 deletion Sources/Leaf/Tag/Models/Index.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class Index: BasicTag {
public func run(arguments: [Argument]) throws -> Node? {
guard
arguments.count == 2,
let array = arguments[0].value?.nodeArray,
let array = arguments[0].value?.array,
let index = arguments[1].value?.int,
index < array.count
else { return nil }
Expand Down
4 changes: 2 additions & 2 deletions Sources/Leaf/Tag/Models/Loop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public final class Loop: Tag {
}

guard let unwrapped = value else { return nil }
let array = unwrapped.nodeArray ?? [unwrapped]
let array = unwrapped.array ?? [unwrapped]
return .array(array.map { [innername: $0] })
}

Expand All @@ -34,7 +34,7 @@ public final class Loop: Tag {
value: Node?,
leaf: Leaf
) throws -> Bytes {
guard let array = value?.nodeArray else { fatalError("run function MUST return an array") }
guard let array = value?.array else { fatalError("run function MUST return an array") }
func renderItem(_ item: Node) throws -> Bytes {
context.push(item)
let rendered = try stem.render(leaf, with: context)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Leaf/Tag/Models/Variable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public final class Variable: Tag {
arguments: [Argument]) throws -> Node? {
// temporary escaping mechanism.
// ALL tags are interpreted, use `*()` to have an empty `*` rendered
if arguments.isEmpty { return .string([TOKEN].string) }
if arguments.isEmpty { return .string([TOKEN].makeString()) }
guard arguments.count == 1 else { throw Error.expectedOneArgument }
return arguments[0].value
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/Leaf/Tag/TagTemplate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public final class TagTemplate {
// that means we've found a chain element, ie: @@else {
if name.makeBytes().first == TOKEN {
self.isChain = true
self.name = name.makeBytes().dropFirst().string
self.name = name.makeBytes().dropFirst().makeString()
} else {
self.isChain = false
self.name = name
Expand All @@ -38,6 +38,7 @@ extension TagTemplate {

extension TagTemplate: CustomStringConvertible {
public var description: String {
let body = self.body?.description ?? ""
return "(name: \(name), parameters: \(parameters), body: \(body)"
}
}
Expand Down
16 changes: 8 additions & 8 deletions Tests/LeafTests/ContextTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ContextTests: XCTestCase {
let template = try stem.spawnLeaf(raw: "Hello, #(name)!")
let context = try Node(node: ["name": "World"])
let loadable = Context(context)
let rendered = try stem.render(template, with: loadable).string
let rendered = try stem.render(template, with: loadable).makeString()
let expectation = "Hello, World!"
XCTAssert(rendered == expectation, "have: \(rendered) want: \(expectation)")
}
Expand All @@ -27,15 +27,15 @@ class ContextTests: XCTestCase {
let raw = "#(best-friend) { Hello, #(self.name)! }"
let template = try stem.spawnLeaf(raw: raw)
let context = Context(["best-friend": ["name": "World"]])
let rendered = try stem.render(template, with: context).string
let rendered = try stem.render(template, with: context).makeString()
XCTAssert(rendered == "Hello, World!")
}

func testLoop() throws {
let raw = "#loop(friends, \"friend\") { Hello, #(friend)! }"
let template = try stem.spawnLeaf(raw: raw)
let context = Context(["friends": ["a", "b", "c", "#loop"]])
let rendered = try stem.render(template, with: context).string
let rendered = try stem.render(template, with: context).makeString()
let expectation = "Hello, a!\nHello, b!\nHello, c!\nHello, #loop!"
XCTAssert(rendered == expectation)
}
Expand All @@ -44,7 +44,7 @@ class ContextTests: XCTestCase {
let raw = "#(name) { #(name) }" // redundant, but should render as an inner stem
let template = try stem.spawnLeaf(raw: raw)
let context = Context(["name": "foo"])
let rendered = try stem.render(template, with: context).string
let rendered = try stem.render(template, with: context).makeString()
let expectation = "foo"
XCTAssert(rendered == expectation)
}
Expand All @@ -53,7 +53,7 @@ class ContextTests: XCTestCase {
let raw = "Let's render #(friend) { #(name) is friends with #(friend.name) } "
let template = try stem.spawnLeaf(raw: raw)
let context = Context(["name": "Foo", "friend": ["name": "Bar"]])
let rendered = try stem.render(template, with: context).string
let rendered = try stem.render(template, with: context).makeString()
let expectation = "Let's render Foo is friends with Bar"
XCTAssertEqual(rendered, expectation)
}
Expand All @@ -62,7 +62,7 @@ class ContextTests: XCTestCase {
let raw = "#(a) { #(self.b) { #(self.c) { #(self.path.1) } } }"
let template = try stem.spawnLeaf(raw: raw)
let context = Context(["a": ["b": ["c": ["path": ["array-variant", "HEllo"]]]]])
let rendered = try stem.render(template, with: context).string
let rendered = try stem.render(template, with: context).makeString()
let expectation = "HEllo"
XCTAssert(rendered == expectation, "have: \(rendered) want: \(expectation)")
}
Expand All @@ -82,7 +82,7 @@ class ContextTests: XCTestCase {

try cases.forEach { key, bool, expectation in
let context = Context([key: .bool(bool)])
let rendered = try stem.render(template, with: context).string
let rendered = try stem.render(template, with: context).makeString()
XCTAssert(rendered == expectation, "have: \(rendered) want: \(expectation)")
}
}
Expand All @@ -101,7 +101,7 @@ class ContextTests: XCTestCase {

let template = try stem.spawnLeaf(raw: raw)
let loadable = Context(context)
let rendered = try stem.render(template, with: loadable).string
let rendered = try stem.render(template, with: loadable).makeString()
let expectation = "Hello, World!"
XCTAssert(rendered == expectation)
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/LeafTests/EmbedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class EmbedTests: XCTestCase {
func testBasicEmbed() throws {
let template = try stem.spawnLeaf(named: "/embed-base")
let context = Context(["name": "World"])
let rendered = try stem.render(template, with: context).string
let rendered = try stem.render(template, with: context).makeString()
let expectation = "Leaf embedded: Hello, World!"
XCTAssert(rendered == expectation, "have: \(rendered) want: \(expectation)")
}
Expand Down
Loading

0 comments on commit 79a2d4d

Please sign in to comment.