Skip to content

Commit

Permalink
Merge pull request #43 from vapor/description
Browse files Browse the repository at this point in the history
add descriptions explicit for 3.1
  • Loading branch information
loganwright authored Feb 23, 2017
2 parents 4ad26cb + 5a0292a commit 18ba5ae
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ Carthage/Build
.build/
Packages/
*.xcodeproj
Package.pins
25 changes: 25 additions & 0 deletions Sources/Node/Core/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,28 @@ public enum Node {
case bytes([UInt8])
case date(Date)
}

extension Node: CustomStringConvertible {
public var description: String {
switch self {
case .null:
return "null"
case .bool(let bool):
return bool.description
case .number(let number):
return number.description
case .string(let string):
return string.description
case .array(let array):
let string = array.map { $0.description } .joined(separator: ", ")
return "[\(string)]"
case .object(let ob):
let string = ob.map { key, value in "\(key): \(value)" } .joined(separator: ", ")
return "[\(string)]"
case .bytes(let bytes):
return "\(bytes)"
case .date(let date):
return "\(date)"
}
}
}
2 changes: 1 addition & 1 deletion Sources/Node/Utilities/Errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ extension NodeError {

extension NodeError: CustomStringConvertible {
public var description: String {
return "Expected \(expectation)\nGot: \(node)\nKey: \(key)"
return "Expected \(expectation) Got: \(node ?? .null) forKey: \(key ?? [])"
}
}

0 comments on commit 18ba5ae

Please sign in to comment.