├── Screen Shots ├── Unit Test.png └── Trait-Based View.png ├── Unit Test.xctemplate ├── TemplateIcon.png ├── TemplateIcon@2x.png ├── ___FILEBASENAME___.playground │ ├── contents.xcplayground │ ├── Contents.swift │ └── Sources │ │ └── Assertions.swift └── TemplateInfo.plist ├── Trait-Based View.xctemplate ├── TemplateIcon.png ├── TemplateIcon@2x.png ├── ___FILEBASENAME___.playground │ ├── contents.xcplayground │ ├── Contents.swift │ └── Sources │ │ └── PlaygroundController.swift └── TemplateInfo.plist ├── Makefile ├── README.md ├── LICENSE └── .gitignore /Screen Shots/Unit Test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pointfreeco/swift-playground-templates/HEAD/Screen Shots/Unit Test.png -------------------------------------------------------------------------------- /Screen Shots/Trait-Based View.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pointfreeco/swift-playground-templates/HEAD/Screen Shots/Trait-Based View.png -------------------------------------------------------------------------------- /Unit Test.xctemplate/TemplateIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pointfreeco/swift-playground-templates/HEAD/Unit Test.xctemplate/TemplateIcon.png -------------------------------------------------------------------------------- /Unit Test.xctemplate/TemplateIcon@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pointfreeco/swift-playground-templates/HEAD/Unit Test.xctemplate/TemplateIcon@2x.png -------------------------------------------------------------------------------- /Trait-Based View.xctemplate/TemplateIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pointfreeco/swift-playground-templates/HEAD/Trait-Based View.xctemplate/TemplateIcon.png -------------------------------------------------------------------------------- /Trait-Based View.xctemplate/TemplateIcon@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pointfreeco/swift-playground-templates/HEAD/Trait-Based View.xctemplate/TemplateIcon@2x.png -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | dir = $(HOME)/Library/Developer/Xcode/Templates/File\ Templates/Playground 2 | 3 | install: $(dir) 4 | cp -R *.xctemplate $(dir) 5 | 6 | $(dir): 7 | mkdir -p $(dir) 8 | 9 | .PHONY = install 10 | -------------------------------------------------------------------------------- /Unit Test.xctemplate/___FILEBASENAME___.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Trait-Based View.xctemplate/___FILEBASENAME___.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Unit Test.xctemplate/___FILEBASENAME___.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | final class UnitTests: XCTestCase { 4 | override func setUp() { 5 | super.setUp() 6 | // Put set-up code here. 7 | } 8 | 9 | override func tearDown() { 10 | // Put tear-down code here. 11 | super.tearDown() 12 | } 13 | 14 | func testExample() { 15 | XCTAssert(true) 16 | } 17 | } 18 | 19 | UnitTests.defaultTestSuite.run() 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # swift-playground-templates 2 | 3 | A collection of helpful Xcode playground templates. 4 | 5 | - [Trait-Based View](#trait-based-view) 6 | - [Unit Test](#unit-test) 7 | 8 | 9 | ## Install 10 | 11 | Run `make` from the repository root. 12 | 13 | 14 | ## Trait-Based View 15 | 16 | Generates a trait-configurable, view-based playground. 17 | 18 | ![Trait-Based View](/Screen%20Shots/Trait-Based%20View.png) 19 | 20 | 21 | ## Unit Test 22 | 23 | Generates a playground with a unit test. 24 | 25 | ![Unit Test](/Screen%20Shots/Unit%20Test.png) 26 | -------------------------------------------------------------------------------- /Trait-Based View.xctemplate/___FILEBASENAME___.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | import PlaygroundSupport 2 | import UIKit 3 | 4 | final class MyViewController: UIViewController { 5 | override func viewDidLoad() { 6 | super.viewDidLoad() 7 | 8 | let stackView = UIStackView(frame: self.view.bounds) 9 | stackView.autoresizingMask = [.flexibleWidth, .flexibleHeight] 10 | self.view.addSubview(stackView) 11 | 12 | let label = UILabel() 13 | label.text = "Hello, world!" 14 | label.textAlignment = .center 15 | label.sizeToFit() 16 | 17 | stackView.addArrangedSubview(label) 18 | } 19 | } 20 | 21 | PlaygroundPage.current.liveView = playgroundController( 22 | for: MyViewController(), 23 | device: .phone4_7inch, 24 | orientation: .portrait, 25 | traits: .init(preferredContentSizeCategory: .medium) 26 | ) 27 | -------------------------------------------------------------------------------- /Trait-Based View.xctemplate/TemplateInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Kind 6 | Xcode.IDEFoundation.TextSubstitutionPlaygroundTemplateKind 7 | Summary 8 | An iOS Playground 9 | Description 10 | Playgrounds provide an interactive environment to play with code. 11 | SortOrder 12 | 20 13 | MainTemplateFile 14 | ___FILEBASENAME___.playground 15 | AllowedTypes 16 | 17 | com.apple.dt.playground 18 | 19 | DefaultCompletionName 20 | MyPlayground 21 | Platforms 22 | 23 | com.apple.platform.iphoneos 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Unit Test.xctemplate/TemplateInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Kind 6 | Xcode.IDEFoundation.TextSubstitutionPlaygroundTemplateKind 7 | Summary 8 | A Playground 9 | Description 10 | Playgrounds provide an interactive environment to play with code. 11 | SortOrder 12 | 20 13 | MainTemplateFile 14 | ___FILEBASENAME___.playground 15 | AllowedTypes 16 | 17 | com.apple.dt.playground 18 | 19 | DefaultCompletionName 20 | MyPlayground 21 | Platforms 22 | 23 | com.apple.platform.iphoneos 24 | com.apple.platform.macosx 25 | com.apple.platform.appletvos 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Point-Free, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | ## Playgrounds 32 | timeline.xctimeline 33 | playground.xcworkspace 34 | 35 | # Swift Package Manager 36 | # 37 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 38 | # Packages/ 39 | # Package.pins 40 | .build/ 41 | 42 | # CocoaPods 43 | # 44 | # We recommend against adding the Pods directory to your .gitignore. However 45 | # you should judge for yourself, the pros and cons are mentioned at: 46 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 47 | # 48 | # Pods/ 49 | 50 | # Carthage 51 | # 52 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 53 | # Carthage/Checkouts 54 | 55 | Carthage/Build 56 | 57 | # fastlane 58 | # 59 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 60 | # screenshots whenever they are needed. 61 | # For more information about the recommended setup visit: 62 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 63 | 64 | fastlane/report.xml 65 | fastlane/Preview.html 66 | fastlane/screenshots 67 | fastlane/test_output 68 | 69 | .DS_Store 70 | *.xcodeproj/* 71 | -------------------------------------------------------------------------------- /Trait-Based View.xctemplate/___FILEBASENAME___.playground/Sources/PlaygroundController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | public func playgroundController( 4 | for viewController: UIViewController, 5 | device: Device = .phone4_7inch, 6 | orientation: Orientation = .portrait, 7 | traits: UITraitCollection = .init()) 8 | -> UIViewController 9 | { 10 | return playgroundController( 11 | for: viewController, 12 | size: device.size(for: orientation), 13 | traits: .init( 14 | traitsFrom: [ 15 | device.traits(for: orientation), 16 | traits 17 | ] 18 | ) 19 | ) 20 | } 21 | 22 | public func playgroundController( 23 | for viewController: UIViewController, 24 | size: CGSize, 25 | traits: UITraitCollection = .init()) 26 | -> UIViewController 27 | { 28 | let parent = UIViewController() 29 | parent.view.frame.size = size 30 | parent.preferredContentSize = parent.view.frame.size 31 | parent.view.addSubview(viewController.view) 32 | parent.addChild(viewController) 33 | 34 | viewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] 35 | viewController.view.frame = parent.view.frame 36 | 37 | parent.view.backgroundColor = .white 38 | 39 | parent.setOverrideTraitCollection(traits, forChild: viewController) 40 | 41 | return parent 42 | } 43 | 44 | public enum Orientation { 45 | case portrait 46 | case landscape 47 | } 48 | 49 | public enum Device { 50 | case phone3_5inch 51 | case phone4inch 52 | case phone4_7inch 53 | case phone5_5inch 54 | case pad 55 | case pad12_9inch 56 | 57 | var portraitSize: CGSize { 58 | switch self { 59 | case .phone3_5inch: 60 | return .init(width: 320, height: 480) 61 | case .phone4inch: 62 | return .init(width: 320, height: 568) 63 | case .phone4_7inch: 64 | return .init(width: 375, height: 667) 65 | case .phone5_5inch: 66 | return .init(width: 414, height: 736) 67 | case .pad: 68 | return .init(width: 768, height: 1024) 69 | case .pad12_9inch: 70 | return .init(width: 1024, height: 1366) 71 | } 72 | } 73 | 74 | var landscapeSize: CGSize { 75 | let portraitSize = self.portraitSize 76 | return .init(width: portraitSize.height, height: portraitSize.width) 77 | } 78 | 79 | func size(for orientation: Orientation) -> CGSize { 80 | switch orientation { 81 | case .portrait: 82 | return self.portraitSize 83 | case .landscape: 84 | return self.landscapeSize 85 | } 86 | } 87 | 88 | func traits(for orientation: Orientation) -> UITraitCollection { 89 | switch (self, orientation) { 90 | case (.phone3_5inch, .portrait), (.phone4inch, .portrait), (.phone4_7inch, .portrait), (.phone5_5inch, .portrait): 91 | return .init( 92 | traitsFrom: [ 93 | .init(horizontalSizeClass: .compact), 94 | .init(verticalSizeClass: .regular), 95 | .init(userInterfaceIdiom: .phone) 96 | ] 97 | ) 98 | case (.phone3_5inch, .landscape), (.phone4inch, .landscape), (.phone4_7inch, .landscape): 99 | return .init( 100 | traitsFrom: [ 101 | .init(horizontalSizeClass: .compact), 102 | .init(verticalSizeClass: .compact), 103 | .init(userInterfaceIdiom: .phone) 104 | ] 105 | ) 106 | case (.phone5_5inch, .landscape): 107 | return .init( 108 | traitsFrom: [ 109 | .init(horizontalSizeClass: .regular), 110 | .init(verticalSizeClass: .compact), 111 | .init(userInterfaceIdiom: .phone) 112 | ] 113 | ) 114 | case (.pad, _), (.pad12_9inch, _): 115 | return .init( 116 | traitsFrom: [ 117 | .init(horizontalSizeClass: .regular), 118 | .init(verticalSizeClass: .regular), 119 | .init(userInterfaceIdiom: .pad) 120 | ] 121 | ) 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /Unit Test.xctemplate/___FILEBASENAME___.playground/Sources/Assertions.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | private func emoji(for bool: Bool) -> Character { 4 | return bool ? "✅" : "❌" 5 | } 6 | 7 | extension XCTestCase { 8 | public func XCTAssert(_ expression: @autoclosure () throws -> Bool, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) rethrows -> Character { 9 | let result = try expression() 10 | Shim.Assert(result, message, file: file, line: line) 11 | return emoji(for: result) 12 | } 13 | 14 | public func XCTAssertEqual(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) rethrows -> Character where T: Equatable { 15 | let (result1, result2) = try (expression1(), expression2()) 16 | Shim.AssertEqual(result1, result2, message, file: file, line: line) 17 | return emoji(for: result1 == result2) 18 | } 19 | 20 | public func XCTAssertEqual(_ expression1: @autoclosure () throws -> T?, _ expression2: @autoclosure () throws -> T?, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) rethrows -> Character where T: Equatable { 21 | let (result1, result2) = try (expression1(), expression2()) 22 | Shim.AssertEqual(result1, result2, message, file: file, line: line) 23 | return emoji(for: result1 == result2) 24 | } 25 | 26 | public func XCTAssertEqual(_ expression1: @autoclosure () throws -> ArraySlice, _ expression2: @autoclosure () throws -> ArraySlice, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) rethrows -> Character where T: Equatable { 27 | let (result1, result2) = try (expression1(), expression2()) 28 | Shim.AssertEqual(result1, result2, message, file: file, line: line) 29 | return emoji(for: result1 == result2) 30 | } 31 | 32 | public func XCTAssertEqual(_ expression1: @autoclosure () throws -> ContiguousArray, _ expression2: @autoclosure () throws -> ContiguousArray, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) rethrows -> Character where T: Equatable { 33 | let (result1, result2) = try (expression1(), expression2()) 34 | Shim.AssertEqual(result1, result2, message, file: file, line: line) 35 | return emoji(for: result1 == result2) 36 | } 37 | 38 | public func XCTAssertEqual(_ expression1: @autoclosure () throws -> [T], _ expression2: @autoclosure () throws -> [T], _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) rethrows -> Character where T: Equatable { 39 | let (result1, result2) = try (expression1(), expression2()) 40 | Shim.AssertEqual(result1, result2, message, file: file, line: line) 41 | return emoji(for: result1 == result2) 42 | } 43 | 44 | public func XCTAssertEqual(_ expression1: @autoclosure () throws -> [T: U], _ expression2: @autoclosure () throws -> [T: U], _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) rethrows -> Character where U: Equatable { 45 | let (result1, result2) = try (expression1(), expression2()) 46 | Shim.AssertEqual(result1, result2, message, file: file, line: line) 47 | return emoji(for: result1 == result2) 48 | } 49 | 50 | public func XCTAssertEqual(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, accuracy: T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) rethrows -> Character where T: FloatingPoint { 51 | let (result1, result2) = try (expression1(), expression2()) 52 | Shim.AssertEqual(result1, result2, message, file: file, line: line) 53 | return emoji(for: result1 == result2) 54 | } 55 | 56 | public func XCTAssertFalse(_ expression: @autoclosure () throws -> Bool, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) rethrows -> Character { 57 | let result = try expression() 58 | Shim.AssertFalse(result, message, file: file, line: line) 59 | return emoji(for: result == false) 60 | } 61 | 62 | public func XCTAssertGreaterThan(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) rethrows -> Character where T: Comparable { 63 | let (result1, result2) = try (expression1(), expression2()) 64 | Shim.AssertGreaterThan(result1, result2, message, file: file, line: line) 65 | return emoji(for: result1 > result2) 66 | } 67 | 68 | public func XCTAssertGreaterThanOrEqual(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) rethrows -> Character where T: Comparable { 69 | let (result1, result2) = try (expression1(), expression2()) 70 | Shim.AssertGreaterThanOrEqual(result1, result2, message, file: file, line: line) 71 | return emoji(for: result1 >= result2) 72 | } 73 | 74 | public func XCTAssertLessThan(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) rethrows -> Character where T: Comparable { 75 | let (result1, result2) = try (expression1(), expression2()) 76 | Shim.AssertLessThan(result1, result2, message, file: file, line: line) 77 | return emoji(for: result1 < result2) 78 | } 79 | 80 | public func XCTAssertLessThanOrEqual(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) rethrows -> Character where T: Comparable { 81 | let (result1, result2) = try (expression1(), expression2()) 82 | Shim.AssertLessThanOrEqual(result1, result2, message, file: file, line: line) 83 | return emoji(for: result1 <= result2) 84 | } 85 | 86 | public func XCTAssertNil(_ expression: @autoclosure () throws -> Any?, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) rethrows -> Character { 87 | let result = try expression() 88 | Shim.AssertNil(result, message, file: file, line: line) 89 | return emoji(for: result == nil) 90 | } 91 | 92 | public func XCTAssertNoThrow(_ expression: @autoclosure () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) rethrows -> Character { 93 | do { 94 | _ = try expression() 95 | return emoji(for: true) 96 | } catch { 97 | let throwing = { throw error } 98 | try Shim.AssertNoThrow(throwing(), message, file: file, line: line) 99 | return emoji(for: false) 100 | } 101 | } 102 | 103 | public func XCTAssertNotEqual(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) rethrows -> Character where T: Equatable { 104 | let (result1, result2) = try (expression1(), expression2()) 105 | Shim.AssertNotEqual(result1, result2, message, file: file, line: line) 106 | return emoji(for: result1 != result2) 107 | } 108 | 109 | public func XCTAssertNotEqual(_ expression1: @autoclosure () throws -> T?, _ expression2: @autoclosure () throws -> T?, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) rethrows -> Character where T: Equatable { 110 | let (result1, result2) = try (expression1(), expression2()) 111 | Shim.AssertNotEqual(result1, result2, message, file: file, line: line) 112 | return emoji(for: result1 != result2) 113 | } 114 | 115 | public func XCTAssertNotEqual(_ expression1: @autoclosure () throws -> ContiguousArray, _ expression2: @autoclosure () throws -> ContiguousArray, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) rethrows -> Character where T: Equatable { 116 | let (result1, result2) = try (expression1(), expression2()) 117 | Shim.AssertNotEqual(result1, result2, message, file: file, line: line) 118 | return emoji(for: result1 != result2) 119 | } 120 | 121 | public func XCTAssertNotEqual(_ expression1: @autoclosure () throws -> ArraySlice, _ expression2: @autoclosure () throws -> ArraySlice, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) rethrows -> Character where T: Equatable { 122 | let (result1, result2) = try (expression1(), expression2()) 123 | Shim.AssertNotEqual(result1, result2, message, file: file, line: line) 124 | return emoji(for: result1 != result2) 125 | } 126 | 127 | public func XCTAssertNotEqual(_ expression1: @autoclosure () throws -> [T], _ expression2: @autoclosure () throws -> [T], _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) rethrows -> Character where T: Equatable { 128 | let (result1, result2) = try (expression1(), expression2()) 129 | Shim.AssertNotEqual(result1, result2, message, file: file, line: line) 130 | return emoji(for: result1 != result2) 131 | } 132 | 133 | public func XCTAssertNotEqual(_ expression1: @autoclosure () throws -> [T: U], _ expression2: @autoclosure () throws -> [T: U], _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) rethrows -> Character where U: Equatable { 134 | let (result1, result2) = try (expression1(), expression2()) 135 | Shim.AssertNotEqual(result1, result2, message, file: file, line: line) 136 | return emoji(for: result1 != result2) 137 | } 138 | 139 | public func XCTAssertNotEqual(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, accuracy: T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) rethrows -> Character where T: FloatingPoint { 140 | let (result1, result2) = try (expression1(), expression2()) 141 | Shim.AssertNotEqual(result1, result2, message, file: file, line: line) 142 | return emoji(for: result1 != result2) 143 | } 144 | 145 | public func XCTAssertNotNil(_ expression: @autoclosure () throws -> Any?, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) rethrows -> Character { 146 | let result = try expression() 147 | Shim.AssertNotNil(result, message, file: file, line: line) 148 | return emoji(for: result != nil) 149 | } 150 | 151 | public func XCTAssertThrowsError(_ expression: @autoclosure () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line, _ errorHandler: (Error) -> Swift.Void = { _ in }) rethrows -> Character { 152 | do { 153 | _ = try expression() 154 | return emoji(for: false) 155 | } catch { 156 | let throwing = { throw error } 157 | try Shim.AssertThrowsError(throwing(), message, file: file, line: line, errorHandler) 158 | return emoji(for: true) 159 | } 160 | } 161 | 162 | public func XCTAssertTrue(_ expression: @autoclosure () throws -> Bool, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) rethrows -> Character { 163 | let result = try expression() 164 | Shim.AssertTrue(result, message, file: file, line: line) 165 | return emoji(for: result) 166 | } 167 | 168 | public func XCTFail(_ message: String = "", file: StaticString = #file, line: UInt = #line) -> Character { 169 | Shim.Fail(message, file: file, line: line) 170 | return emoji(for: false) 171 | } 172 | } 173 | 174 | private enum Shim { 175 | static func Assert(_ expression: @autoclosure () throws -> Bool, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) rethrows { 176 | XCTAssert(expression, message, file: file, line: line) 177 | } 178 | 179 | static func AssertEqual(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) where T: Equatable { 180 | XCTAssertEqual(expression1, expression2, message, file: file, line: line) 181 | } 182 | 183 | static func AssertEqual(_ expression1: @autoclosure () throws -> T?, _ expression2: @autoclosure () throws -> T?, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) where T: Equatable { 184 | XCTAssertEqual(expression1, expression2, message, file: file, line: line) 185 | } 186 | 187 | static func AssertEqual(_ expression1: @autoclosure () throws -> ArraySlice, _ expression2: @autoclosure () throws -> ArraySlice, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) where T: Equatable { 188 | XCTAssertEqual(expression1, expression2, message, file: file, line: line) 189 | } 190 | 191 | static func AssertEqual(_ expression1: @autoclosure () throws -> ContiguousArray, _ expression2: @autoclosure () throws -> ContiguousArray, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) where T: Equatable { 192 | XCTAssertEqual(expression1, expression2, message, file: file, line: line) 193 | } 194 | 195 | static func AssertEqual(_ expression1: @autoclosure () throws -> [T], _ expression2: @autoclosure () throws -> [T], _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) where T: Equatable { 196 | XCTAssertEqual(expression1, expression2, message, file: file, line: line) 197 | } 198 | 199 | static func AssertEqual(_ expression1: @autoclosure () throws -> [T: U], _ expression2: @autoclosure () throws -> [T: U], _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) where U: Equatable { 200 | XCTAssertEqual(expression1, expression2, message, file: file, line: line) 201 | } 202 | 203 | static func AssertEqual(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, accuracy: T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) where T: FloatingPoint { 204 | XCTAssertEqual(expression1, expression2, message, file: file, line: line) 205 | } 206 | 207 | static func AssertFalse(_ expression: @autoclosure () throws -> Bool, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) { 208 | XCTAssertFalse(expression, message, file: file, line: line) 209 | } 210 | 211 | static func AssertGreaterThan(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) where T: Comparable { 212 | XCTAssertGreaterThan(expression1, expression2, message, file: file, line: line) 213 | } 214 | 215 | static func AssertGreaterThanOrEqual(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) where T: Comparable { 216 | XCTAssertGreaterThanOrEqual(expression1, expression2, message, file: file, line: line) 217 | } 218 | 219 | static func AssertLessThan(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) where T: Comparable { 220 | XCTAssertLessThan(expression1, expression2, message, file: file, line: line) 221 | } 222 | 223 | static func AssertLessThanOrEqual(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) where T: Comparable { 224 | XCTAssertLessThanOrEqual(expression1, expression2, message, file: file, line: line) 225 | } 226 | 227 | static func AssertNil(_ expression: @autoclosure () throws -> Any?, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) { 228 | XCTAssertNil(expression, message, file: file, line: line) 229 | } 230 | 231 | static func AssertNoThrow(_ expression: @autoclosure () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) { 232 | XCTAssertNoThrow(expression, message, file: file, line: line) 233 | } 234 | 235 | static func AssertNotEqual(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) where T: Equatable { 236 | XCTAssertNotEqual(expression1, expression2, message, file: file, line: line) 237 | } 238 | 239 | static func AssertNotEqual(_ expression1: @autoclosure () throws -> T?, _ expression2: @autoclosure () throws -> T?, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) where T: Equatable { 240 | XCTAssertNotEqual(expression1, expression2, message, file: file, line: line) 241 | } 242 | 243 | static func AssertNotEqual(_ expression1: @autoclosure () throws -> ContiguousArray, _ expression2: @autoclosure () throws -> ContiguousArray, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) where T: Equatable { 244 | XCTAssertNotEqual(expression1, expression2, message, file: file, line: line) 245 | } 246 | 247 | static func AssertNotEqual(_ expression1: @autoclosure () throws -> ArraySlice, _ expression2: @autoclosure () throws -> ArraySlice, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) where T: Equatable { 248 | XCTAssertNotEqual(expression1, expression2, message, file: file, line: line) 249 | } 250 | 251 | static func AssertNotEqual(_ expression1: @autoclosure () throws -> [T], _ expression2: @autoclosure () throws -> [T], _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) where T: Equatable { 252 | XCTAssertNotEqual(expression1, expression2, message, file: file, line: line) 253 | } 254 | 255 | static func AssertNotEqual(_ expression1: @autoclosure () throws -> [T: U], _ expression2: @autoclosure () throws -> [T: U], _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) where U: Equatable { 256 | XCTAssertNotEqual(expression1, expression2, message, file: file, line: line) 257 | } 258 | 259 | static func AssertNotEqual(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, accuracy: T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) where T: FloatingPoint { 260 | XCTAssertNotEqual(expression1, expression2, message, file: file, line: line) 261 | } 262 | 263 | static func AssertNotNil(_ expression: @autoclosure () throws -> Any?, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) { 264 | XCTAssertNotNil(expression, message, file: file, line: line) 265 | } 266 | 267 | static func AssertThrowsError(_ expression: @autoclosure () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line, _ errorHandler: (Error) -> Swift.Void = { _ in }) { 268 | XCTAssertThrowsError(expression, message, file: file, line: line, errorHandler) 269 | } 270 | 271 | static func AssertTrue(_ expression: @autoclosure () throws -> Bool, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) { 272 | XCTAssertTrue(expression, message, file: file, line: line) 273 | } 274 | 275 | static func Fail(_ message: String = "", file: StaticString = #file, line: UInt = #line) { 276 | XCTFail(message, file: file, line: line) 277 | } 278 | } 279 | --------------------------------------------------------------------------------