-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
creat xcodeproj to pass coverage layout to codecov
- Loading branch information
Showing
7 changed files
with
133 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// UnownedUnsafe.swift | ||
// | ||
// | ||
// Created by 游宗諭 on 2019/12/1. | ||
// | ||
|
||
import Foundation | ||
|
||
/// A wrapper around an `Object` with a `unowned(unsafe)` binding. | ||
public struct UnownedUnsafe<UnowndObject: AnyObject>: UnownedProtocol, CustomStringConvertible { | ||
|
||
/// The object of `self`. | ||
public unowned(unsafe) var object: UnowndObject! | ||
|
||
/// A textual representation of this instance. | ||
public var description: String { | ||
"UnownedUnsafe(" + String(reflecting: object!) + ")" | ||
} | ||
|
||
/// Creates an instance for an object. | ||
public init(_ object: UnowndObject?) { | ||
self.object = object | ||
} | ||
|
||
} | ||
extension UnownedUnsafe: Hashable, Equatable where UnowndObject: Hashable { | ||
|
||
} | ||
|
||
extension Sequence where Iterator.Element: AnyObject { | ||
|
||
/// return An array of unowned references to the elements in `self`. | ||
public func unownedUnsafe() -> [UnownedUnsafe<Iterator.Element>] { | ||
map(UnownedUnsafe.init) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// | ||
// UnownedUnsafeTests.swift | ||
// | ||
// | ||
// Created by 游宗諭 on 2019/12/1. | ||
// | ||
|
||
import XCTest | ||
import Weak | ||
|
||
final class UnownedUnsafeTests:XCTestCase { | ||
class PrintTarget{ var str:String = ""} | ||
class SomeClass:NSObject { | ||
var printTarget:PrintTarget | ||
var text:String | ||
init(printTarget:PrintTarget, text:String) { | ||
self.printTarget = printTarget | ||
self.text = text | ||
} | ||
deinit { | ||
print(text, terminator: "", to: &printTarget.str) | ||
} | ||
} | ||
|
||
func testUnownedunsafe() { | ||
let testString = "deinited" | ||
let UnownedunsafeRef: UnownedUnsafe<SomeClass> | ||
let printTarget = PrintTarget() | ||
do { | ||
let instance = SomeClass(printTarget: printTarget, text: testString) | ||
UnownedunsafeRef = UnownedUnsafe(instance) | ||
XCTAssertNotNil(UnownedunsafeRef.object) | ||
XCTAssertEqual("UnownedUnsafe(" + String(reflecting: instance) + ")", UnownedunsafeRef.description) | ||
} | ||
XCTAssertEqual(printTarget.str, testString) | ||
} | ||
func testUnownedunsafeForSequence() { | ||
let expect = (0...9).map{_ in SomeClass(printTarget: UnownedUnsafeTests.PrintTarget(), text: "")} | ||
let UnownedunsafeArray = expect.unownedUnsafe() | ||
XCTAssertEqual(expect, UnownedunsafeArray.map{$0.object}) | ||
XCTAssertEqual(expect, UnownedunsafeArray.objects) | ||
} | ||
|
||
func testUnownEqual() { | ||
let object = SomeClass(printTarget: UnownedUnsafeTests.PrintTarget(), text: "") | ||
let Unownedunsafe1 = UnownedUnsafe(object) | ||
let Unownedunsafe2 = UnownedUnsafe(object) | ||
let weak = Weak(object) | ||
|
||
XCTAssertTrue(Unownedunsafe1 === Unownedunsafe2) | ||
XCTAssertTrue(Unownedunsafe1 === object) | ||
XCTAssertTrue(object === Unownedunsafe1) | ||
XCTAssertTrue(Unownedunsafe1 === weak) | ||
XCTAssertTrue(Unownedunsafe1 == Unownedunsafe2) | ||
XCTAssertTrue(Unownedunsafe1 == object) | ||
XCTAssertTrue(object == Unownedunsafe1) | ||
XCTAssertFalse(Unownedunsafe1 !== Unownedunsafe2) | ||
XCTAssertFalse(Unownedunsafe1 !== object) | ||
XCTAssertFalse(object !== Unownedunsafe1) | ||
XCTAssertFalse(Unownedunsafe1 !== weak) | ||
|
||
|
||
|
||
} | ||
func testOptionalUnownedunsafeEqual() { | ||
let object:SomeClass? = SomeClass(printTarget: UnownedUnsafeTests.PrintTarget(), text: "") | ||
let Unownedunsafe1:UnownedUnsafe<SomeClass>? = UnownedUnsafe(object) | ||
let Unownedunsafe2:UnownedUnsafe<SomeClass>? = UnownedUnsafe(object) | ||
let weak:Weak<SomeClass>? = Weak(object) | ||
XCTAssertTrue(Unownedunsafe1 === Unownedunsafe2) | ||
XCTAssertTrue(Unownedunsafe1 === object) | ||
XCTAssertTrue(object === Unownedunsafe1) | ||
XCTAssertTrue(Unownedunsafe1 === weak) | ||
XCTAssertTrue(Unownedunsafe1 == Unownedunsafe2) | ||
XCTAssertTrue(Unownedunsafe1 == object) | ||
XCTAssertTrue(object == Unownedunsafe1) | ||
XCTAssertTrue(Unownedunsafe1 == weak) | ||
XCTAssertFalse(Unownedunsafe1 !== Unownedunsafe2) | ||
XCTAssertFalse(Unownedunsafe1 !== object) | ||
XCTAssertFalse(object !== Unownedunsafe1) | ||
XCTAssertFalse(Unownedunsafe1 !== weak) | ||
XCTAssertFalse(Unownedunsafe1 != Unownedunsafe2) | ||
XCTAssertFalse(Unownedunsafe1 != object) | ||
XCTAssertFalse(object != Unownedunsafe1) | ||
XCTAssertFalse(Unownedunsafe1 != weak) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters