Separate parser and helpers from Password class for better testability

This commit is contained in:
Danny Moesch 2018-11-11 18:09:52 +01:00 committed by Bob Sun
parent 2abbceb2e9
commit 7c12263458
17 changed files with 913 additions and 537 deletions

View file

@ -0,0 +1,47 @@
//
// AdditionField.swift
// passKit
//
// Created by Danny Moesch on 30.09.18.
// Copyright © 2018 Bob Sun. All rights reserved.
//
public struct AdditionField: Hashable {
public let title: String, content: String
var asString: String {
return title.isEmpty ? content : title + ": " + content
}
var asTuple: (String, String) {
return (title, content)
}
}
extension AdditionField {
static func | (left: String, right: AdditionField) -> String {
return left | right.asString
}
static func | (left: AdditionField, right: String) -> String {
return left.asString | right
}
static func | (left: AdditionField, right: AdditionField) -> String {
return left.asString | right
}
}
extension AdditionField: Equatable {
public static func == (first: AdditionField, second: AdditionField) -> Bool {
return first.asTuple == second.asTuple
}
}
infix operator =>: MultiplicationPrecedence
func => (key: String, value: String) -> AdditionField {
return AdditionField(title: key, content: value)
}