TRAVIS_OS_NAME=osx default= <<<<<< ENV ./codecov.yaml .swift-version LICENSE Package.swift Sources/Weakify/Info.plist Sources/Weakify/Weakify.swift Tests/WeakifyTests/Info.plist Tests/WeakifyTests/WeakifyTest.swift Weakify.podspec Weakify.xcodeproj/project.pbxproj Weakify.xcodeproj/project.xcworkspace/contents.xcworkspacedata Weakify.xcodeproj/xcshareddata/xcschemes/Weakify.xcscheme <<<<<< network # path=./codecov.yaml ignore: - "Tests" # ignore folders and all its contents <<<<<< EOF # path=./Weakify-Tests.xctest.coverage.txt /Users/travis/build/klundberg/Weakify/Tests/WeakifyTests/WeakifyTest.swift: 1| |// Copyright (c) 2015-2017 Kevin Lundberg. See LICENSE file for more info 2| | 3| |import XCTest 4| |import Weakify 5| | 6| |private class Thing {} 7| | 8| |private struct TestError: Error {} 9| | 10| |class WeakifyTest: XCTestCase { 11| | 12| | private var object: Thing! 13| | private var executed = false 14| | 15| 64| override func setUp() { 16| 64| super.setUp() 17| 64| 18| 64| object = Thing() 19| 64| executed = false 20| 64| } 21| | 22| | // MARK: - () -> Void 23| | 24| 1| func testVoidToVoid_PartiallyApplied_WillExecuteIfNotNil() { 25| 1| func f(o object: Thing) -> () -> Void { 26| 1| return { self.executed = true } 27| 1| } 28| 1| 29| 1| weakify(object, f)() 30| 1| 31| 1| XCTAssertTrue(executed) 32| 1| } 33| | 34| 1| func testVoidToVoid_WillExecuteIfNotNil() { 35| 1| func f(o object: Thing) -> Void { 36| 1| self.executed = true 37| 1| } 38| 1| 39| 1| weakify(object, f)() 40| 1| 41| 1| XCTAssertTrue(executed) 42| 1| } 43| | 44| 1| func testVoidThrowsToVoid_PartiallyApplied_WillExecuteIfNotNil() throws { 45| 1| func f(o object: Thing) -> () throws -> Void { 46| 1| return { self.executed = true } 47| 1| } 48| 1| 49| 1| try weakify(object, f)() 50| 1| 51| 1| XCTAssertTrue(executed) 52| 1| } 53| | 54| 1| func testVoidThrowsToVoid_WillExecuteIfNotNil() throws { 55| 1| func f(o object: Thing) throws -> Void { 56| 1| self.executed = true 57| 1| } 58| 1| 59| 1| try weakify(object, f)() 60| 1| 61| 1| XCTAssertTrue(executed) 62| 1| } 63| | 64| 1| func testVoidToVoid_PartiallyApplied_WillNotExecuteIfNil() { 65| 0| func f(o object: Thing) -> () -> Void { 66| 0| return { self.executed = true } 67| 0| } 68| 1| 69| 1| let fn: () -> () = weakify(object, f) 70| 1| object = nil 71| 1| fn() 72| 1| 73| 1| XCTAssertFalse(executed) 74| 1| } 75| | 76| 1| func testVoidToVoid_WillNotExecuteIfNil() { 77| 0| func f(o object: Thing) -> Void { 78| 0| self.executed = true 79| 0| } 80| 1| 81| 1| let fn: () -> () = weakify(object, f) 82| 1| object = nil 83| 1| fn() 84| 1| 85| 1| XCTAssertFalse(executed) 86| 1| } 87| | 88| 1| func testVoidThrowsToVoid_PartiallyApplied_WillNotExecuteIfNil() throws { 89| 0| func f(o object: Thing) -> () throws -> Void { 90| 0| return { self.executed = true } 91| 0| } 92| 1| 93| 1| let fn: () throws -> () = weakify(object, f) 94| 1| object = nil 95| 1| try fn() 96| 1| 97| 1| XCTAssertFalse(executed) 98| 1| } 99| | 100| 1| func testVoidThrowsToVoid_WillNotExecuteIfNil() throws { 101| 0| func f(o object: Thing) throws -> Void { 102| 0| self.executed = true 103| 0| } 104| 1| 105| 1| let fn: () throws -> () = weakify(object, f) 106| 1| object = nil 107| 1| try fn() 108| 1| 109| 1| XCTAssertFalse(executed) 110| 1| } 111| | 112| 1| func testVoidThrowsToVoid_PartiallyApplied_WillThrowIfNotNil() { 113| 1| func f(o object: Thing) -> () throws -> Void { 114| 1| return { throw TestError() } 115| 1| } 116| 1| 117| 1| XCTAssertThrowsError(try weakify(object, f)()) 118| 1| } 119| | 120| 1| func testVoidThrowsToVoid_WillThrowIfNotNil() { 121| 1| func f(o object: Thing) throws -> Void { 122| 1| throw TestError() 123| 1| } 124| 1| 125| 1| XCTAssertThrowsError(try weakify(object, f)()) 126| 1| } 127| | 128| | // MARK: - U -> Void (ignoring U) 129| | 130| 1| func testUToVoidIgnoringU_PartiallyApplied_WillExecuteIfNotNil() { 131| 1| func f(o object: Thing) -> () -> Void { 132| 1| return { self.executed = true } 133| 1| } 134| 1| 135| 1| let fn: (Any) -> Void = weakify(object, f) 136| 1| fn(123) 137| 1| 138| 1| XCTAssertTrue(executed) 139| 1| } 140| | 141| 1| func testUToVoidIgnoringU_WillExecuteIfNotNil() { 142| 1| func f(o object: Thing) -> Void { 143| 1| self.executed = true 144| 1| } 145| 1| 146| 1| let fn: (Any) -> Void = weakify(object, f) 147| 1| fn(123) 148| 1| 149| 1| XCTAssertTrue(executed) 150| 1| } 151| | 152| 1| func testUThrowsToVoidIgnoringU_PartiallyApplied_WillExecuteIfNotNil() throws { 153| 1| func f(o object: Thing) -> () throws -> Void { 154| 1| return { self.executed = true } 155| 1| } 156| 1| 157| 1| let fn: (Any) throws -> Void = weakify(object, f) 158| 1| try fn(123) 159| 1| 160| 1| XCTAssertTrue(executed) 161| 1| } 162| | 163| 1| func testUThrowsToVoidIgnoringU_WillExecuteIfNotNil() throws { 164| 1| func f(o object: Thing) throws -> Void { 165| 1| self.executed = true 166| 1| } 167| 1| 168| 1| let fn: (Any) throws -> Void = weakify(object, f) 169| 1| try fn(123) 170| 1| 171| 1| XCTAssertTrue(executed) 172| 1| } 173| | 174| 1| func testUToVoidIgnoringU_PartiallyApplied_WillNotExecuteIfNil() { 175| 0| func f(o object: Thing) -> () -> Void { 176| 0| return { self.executed = true } 177| 0| } 178| 1| 179| 1| let fn: (Any) -> Void = weakify(object, f) 180| 1| object = nil 181| 1| fn(123) 182| 1| 183| 1| XCTAssertFalse(executed) 184| 1| } 185| | 186| 1| func testUToVoidIgnoringU_WillNotExecuteIfNil() { 187| 0| func f(o object: Thing) -> Void { 188| 0| self.executed = true 189| 0| } 190| 1| 191| 1| let fn: (Any) -> Void = weakify(object, f) 192| 1| object = nil 193| 1| fn(123) 194| 1| 195| 1| XCTAssertFalse(executed) 196| 1| } 197| | 198| 1| func testUThrowsToVoidIgnoringU_PartiallyApplied_WillNotExecuteIfNil() throws { 199| 0| func f(o object: Thing) -> () throws -> Void { 200| 0| return { self.executed = true } 201| 0| } 202| 1| 203| 1| let fn: (Any) throws -> Void = weakify(object, f) 204| 1| object = nil 205| 1| try fn(123) 206| 1| 207| 1| XCTAssertFalse(executed) 208| 1| } 209| | 210| 1| func testUThrowsToVoidIgnoringU_WillNotExecuteIfNil() throws { 211| 0| func f(o object: Thing) throws -> Void { 212| 0| self.executed = true 213| 0| } 214| 1| 215| 1| let fn: (Any) throws -> Void = weakify(object, f) 216| 1| object = nil 217| 1| try fn(123) 218| 1| 219| 1| XCTAssertFalse(executed) 220| 1| } 221| | 222| 1| func testUThrowsToVoidIgnoringU_PartiallyApplied_WillThrowIfNotNil() { 223| 1| func f(o object: Thing) -> () throws -> Void { 224| 1| return { throw TestError() } 225| 1| } 226| 1| 227| 1| let fn: (Any) throws -> Void = weakify(object, f) 228| 1| 229| 1| XCTAssertThrowsError(try fn(123)) 230| 1| } 231| | 232| 1| func testUThrowsToVoidIgnoringU_WillThrowIfNotNil() { 233| 1| func f(o object: Thing) throws -> Void { 234| 1| throw TestError() 235| 1| } 236| 1| 237| 1| let fn: (Any) throws -> Void = weakify(object, f) 238| 1| 239| 1| XCTAssertThrowsError(try fn(123)) 240| 1| } 241| | 242| | // MARK: - U -> Void 243| | 244| 1| func testUToVoid_PartiallyApplied_WillExecuteIfNotNil() { 245| 1| func f(o object: Thing) -> (Int) -> Void { 246| 1| return { int in self.executed = true } 247| 1| } 248| 1| 249| 1| weakify(object, f)(123) 250| 1| 251| 1| XCTAssertTrue(executed) 252| 1| } 253| | 254| 1| func testUToVoid_WillExecuteIfNotNil() { 255| 1| func f(o object: Thing, i: Int) -> Void { 256| 1| self.executed = true 257| 1| } 258| 1| 259| 1| weakify(object, f)(123) 260| 1| 261| 1| XCTAssertTrue(executed) 262| 1| } 263| | 264| 1| func testUThrowsToVoid_PartiallyApplied_WillExecuteIfNotNil() { 265| 1| func f(o object: Thing) -> (Int) throws -> Void { 266| 1| return { int in self.executed = true } 267| 1| } 268| 1| 269| 1| try! weakify(object, f)(123) 270| 1| 271| 1| XCTAssertTrue(executed) 272| 1| } 273| | 274| 1| func testUThrowsToVoid_WillExecuteIfNotNil() throws { 275| 1| func f(o object: Thing, i: Int) throws -> Void { 276| 1| self.executed = true 277| 1| } 278| 1| 279| 1| try weakify(object, f)(123) 280| 1| 281| 1| XCTAssertTrue(executed) 282| 1| } 283| | 284| 1| func testUToVoid_PartiallyApplied_WillNotExecuteIfNil() { 285| 0| func f(o object: Thing) -> (Int) -> Void { 286| 0| return { int in self.executed = true } 287| 0| } 288| 1| 289| 1| let fn: (Int) -> Void = weakify(object, f) 290| 1| object = nil 291| 1| fn(123) 292| 1| 293| 1| XCTAssertFalse(executed) 294| 1| } 295| | 296| 1| func testUToVoid_WillNotExecuteIfNil() { 297| 0| func f(o object: Thing, i: Int) -> Void { 298| 0| self.executed = true 299| 0| } 300| 1| 301| 1| let fn = weakify(object, f) 302| 1| object = nil 303| 1| fn(123) 304| 1| 305| 1| XCTAssertFalse(executed) 306| 1| } 307| | 308| 1| func testUThrowsToVoid_PartiallyApplied_WillNotExecuteIfNil() throws { 309| 0| func f(o object: Thing) -> (Int) throws -> Void { 310| 0| return { int in self.executed = true } 311| 0| } 312| 1| 313| 1| let fn: (Int) throws -> Void = weakify(object, f) 314| 1| object = nil 315| 1| try fn(123) 316| 1| 317| 1| XCTAssertFalse(executed) 318| 1| } 319| | 320| 1| func testUThrowsToVoid_WillNotExecuteIfNil() throws { 321| 0| func f(o object: Thing, i: Int) throws -> Void { 322| 0| self.executed = true 323| 0| } 324| 1| 325| 1| let fn = weakify(object, f) 326| 1| object = nil 327| 1| try fn(123) 328| 1| 329| 1| XCTAssertFalse(executed) 330| 1| } 331| | 332| 1| func testUThrowsToVoid_PartiallyApplied_WillThrowIfNotNil() { 333| 1| func f(o object: Thing) -> (Int) throws -> Void { 334| 1| return { _ in throw TestError() } 335| 1| } 336| 1| 337| 1| XCTAssertThrowsError(try weakify(object, f)(123)) 338| 1| } 339| | 340| 1| func testUThrowsToVoid_WillThrowIfNotNil() { 341| 1| func f(o object: Thing, i: Int) throws -> Void { 342| 1| throw TestError() 343| 1| } 344| 1| 345| 1| XCTAssertThrowsError(try weakify(object, f)(123)) 346| 1| } 347| | 348| | // MARK: - () -> U 349| | 350| 1| func testVoidToU_PartiallyApplied_WillExecuteIfNotNil() { 351| 1| func f(o object: Thing) -> () -> Int { 352| 1| return { return 123 } 353| 1| } 354| 1| 355| 1| let fn: () -> Int? = weakify(object, f) 356| 1| 357| 1| XCTAssertEqual(123, fn()) 358| 1| } 359| | 360| 1| func testVoidToU_WillExecuteIfNotNil() { 361| 1| func f(o object: Thing) -> Int { 362| 1| return 123 363| 1| } 364| 1| let fn: () -> Int? = weakify(object, f) 365| 1| XCTAssertEqual(123, fn()) 366| 1| } 367| | 368| 1| func testVoidThrowsToU_PartiallyApplied_WillExecuteIfNotNil() throws { 369| 1| func f(o object: Thing) -> () throws -> Int { 370| 1| return { return 123 } 371| 1| } 372| 1| 373| 1| let fn: () throws -> Int? = weakify(object, f) 374| 1| 375| 1| XCTAssertEqual(123, try fn()) 376| 1| } 377| | 378| 1| func testVoidThrowsToU_WillExecuteIfNotNil() throws { 379| 1| func f(o object: Thing) throws -> Int { 380| 1| return 123 381| 1| } 382| 1| 383| 1| XCTAssertEqual(123, try weakify(object, f)()) 384| 1| } 385| | 386| 1| func testVoidToU_PartiallyApplied_WillNotExecuteIfNil() { 387| 0| func f(o object: Thing) -> () -> Int { 388| 0| return { return 123 } 389| 0| } 390| 1| 391| 1| let fn = weakify(object, f) 392| 1| object = nil 393| 1| XCTAssertNil(fn()) 394| 1| } 395| | 396| 1| func testVoidToU_WillNotExecuteIfNil() { 397| 0| func f(o object: Thing) -> Int { 398| 0| return 123 399| 0| } 400| 1| 401| 1| let fn = weakify(object, f) 402| 1| object = nil 403| 1| XCTAssertNil(fn()) 404| 1| } 405| | 406| 1| func testVoidThrowsToU_PartiallyApplied_WillNotExecuteIfNil() throws { 407| 0| func f(o object: Thing) -> () throws -> Int { 408| 0| return { return 123 } 409| 0| } 410| 1| 411| 1| let fn: () throws -> Int? = weakify(object, f) 412| 1| object = nil 413| 1| XCTAssertNil(try fn()) 414| 1| } 415| | 416| 1| func testVoidThrowsToU_WillNotExecuteIfNil() throws { 417| 0| func f(o object: Thing) throws -> Int { 418| 0| return 123 419| 0| } 420| 1| 421| 1| let fn: () throws -> Int? = weakify(object, f) 422| 1| object = nil 423| 1| XCTAssertNil(try fn()) 424| 1| } 425| | 426| 1| func testVoidThrowsToU_PartiallyApplied_WillThrowIfNotNil() { 427| 1| func f(o object: Thing) -> () throws -> Int { 428| 1| return { throw TestError() } 429| 1| } 430| 1| 431| 1| let fn: () throws -> Int? = weakify(object, f) 432| 1| 433| 1| XCTAssertThrowsError(try fn()) 434| 1| } 435| | 436| 1| func testVoidThrowsToU_WillThrowIfNotNil() { 437| 1| func f(o object: Thing) throws -> Int { 438| 1| throw TestError() 439| 1| } 440| 1| 441| 1| let fn: () throws -> Int? = weakify(object, f) 442| 1| 443| 1| XCTAssertThrowsError(try fn()) 444| 1| } 445| | 446| | // MARK: - U -> V 447| | 448| 1| func testUToV_PartiallyApplied_WillExecuteIfNotNil() { 449| 1| func f(o object: Thing) -> (Int) -> String { 450| 1| return { int in return String(int) } 451| 1| } 452| 1| 453| 1| XCTAssertEqual("123", weakify(object, f)(123)) 454| 1| } 455| | 456| 1| func testUToV_WillExecuteIfNotNil() { 457| 1| func f(o object: Thing, int: Int) -> String { 458| 1| return String(int) 459| 1| } 460| 1| 461| 1| XCTAssertEqual("123", weakify(object, f)(123)) 462| 1| } 463| | 464| 1| func testUThrowsToV_PartiallyApplied_WillExecuteIfNotNil() throws { 465| 1| func f(o object: Thing) -> (Int) throws -> String { 466| 1| return { int in return String(int) } 467| 1| } 468| 1| 469| 1| XCTAssertEqual("123", try weakify(object, f)(123)) 470| 1| } 471| | 472| 1| func testUThrowsToV_WillExecuteIfNotNil() throws { 473| 1| func f(o object: Thing, int: Int) throws -> String { 474| 1| return String(int) 475| 1| } 476| 1| 477| 1| XCTAssertEqual("123", try weakify(object, f)(123)) 478| 1| } 479| | 480| 1| func testUToV_PartiallyApplied_WillNotExecuteIfNil() { 481| 0| func f(o object: Thing) -> (Int) -> String { 482| 0| return { int in return String(int) } 483| 0| } 484| 1| 485| 1| let fn: (Int) -> String? = weakify(object, f) 486| 1| object = nil 487| 1| XCTAssertNil(fn(123)) 488| 1| } 489| | 490| 1| func testUToV_WillNotExecuteIfNil() { 491| 0| func f(o object: Thing, int: Int) -> String { 492| 0| return String(int) 493| 0| } 494| 1| 495| 1| let fn: (Int) -> String? = weakify(object, f) 496| 1| object = nil 497| 1| XCTAssertNil(fn(123)) 498| 1| } 499| | 500| 1| func testUThrowsToV_PartiallyApplied_WillNotExecuteIfNil() throws { 501| 0| func f(o object: Thing) -> (Int) throws -> String { 502| 0| return { int in return String(int) } 503| 0| } 504| 1| 505| 1| let fn: (Int) throws -> String? = weakify(object, f) 506| 1| object = nil 507| 1| XCTAssertNil(try fn(123)) 508| 1| } 509| | 510| 1| func testUThrowsToV_WillNotExecuteIfNil() throws { 511| 0| func f(o object: Thing, int: Int) throws -> String { 512| 0| return String(int) 513| 0| } 514| 1| 515| 1| let fn: (Int) throws -> String? = weakify(object, f) 516| 1| object = nil 517| 1| XCTAssertNil(try fn(123)) 518| 1| } 519| | 520| 1| func testUThrowsToV_PartiallyApplied_WillThrowIfNotNil() { 521| 1| func f(o object: Thing) -> (Int) throws -> String { 522| 1| return { _ in throw TestError() } 523| 1| } 524| 1| 525| 1| XCTAssertThrowsError(try weakify(object, f)(123)) 526| 1| } 527| | 528| 1| func testUThrowsToV_WillThrowIfNotNil() { 529| 1| func f(o object: Thing, int: Int) throws -> String { 530| 1| throw TestError() 531| 1| } 532| 1| 533| 1| XCTAssertThrowsError(try weakify(object, f)(123)) 534| 1| } 535| | 536| | // MARK: - U as? V -> Void 537| | 538| | var value: Int? 539| | 540| 1| func testUasV_PartiallyApplied_WillExecuteIfNotNil() { 541| 1| func f(o object: Thing) -> (Int?) -> Void { 542| 1| return { int in self.value = int; self.executed = true } 543| 1| } 544| 1| 545| 1| let fn: (Any) -> Void = weakify(object, f) 546| 1| fn(123) 547| 1| 548| 1| XCTAssertTrue(executed) 549| 1| XCTAssertEqual(123, value) 550| 1| } 551| | 552| 1| func testUasV_WillExecuteIfNotNil() { 553| 1| func f(o object: Thing, int: Int?) -> Void { 554| 1| self.value = int; self.executed = true 555| 1| } 556| 1| 557| 1| let fn: (Any) -> Void = weakify(object, f) 558| 1| fn(123) 559| 1| 560| 1| XCTAssertTrue(executed) 561| 1| XCTAssertEqual(123, value) 562| 1| } 563| | 564| 1| func testUasVThrows_PartiallyApplied_WillExecuteIfNotNil() { 565| 1| func f(o object: Thing) -> (Int?) throws -> Void { 566| 1| return { int in self.value = int; self.executed = true } 567| 1| } 568| 1| 569| 1| let fn: (Any) throws -> Void = weakify(object, f) 570| 1| try! fn(123) 571| 1| 572| 1| XCTAssertTrue(executed) 573| 1| XCTAssertEqual(123, value) 574| 1| } 575| | 576| 1| func testUasVThrows_WillExecuteIfNotNil() { 577| 1| func f(o object: Thing, int: Int?) throws -> Void { 578| 1| self.value = int; self.executed = true 579| 1| } 580| 1| 581| 1| let fn: (Any) throws -> Void = weakify(object, f) 582| 1| try! fn(123) 583| 1| 584| 1| XCTAssertTrue(executed) 585| 1| XCTAssertEqual(123, value) 586| 1| } 587| | 588| 1| func testUasV_PartiallyApplied_WillGetNilIfParameterCannotBeCastAsU() { 589| 1| func f(o object: Thing) -> (Int?) -> Void { 590| 1| return { int in self.value = int; self.executed = true } 591| 1| } 592| 1| 593| 1| weakify(object, f)("123") 594| 1| 595| 1| XCTAssertTrue(executed) 596| 1| XCTAssertEqual(nil, value) 597| 1| } 598| | 599| 1| func testUasV_WillGetNilIfParameterCannotBeCastAsU() { 600| 1| func f(o object: Thing, int: Int?) -> Void { 601| 1| self.value = int; self.executed = true 602| 1| } 603| 1| 604| 1| weakify(object, f)("123") 605| 1| 606| 1| XCTAssertTrue(executed) 607| 1| XCTAssertEqual(nil, value) 608| 1| } 609| | 610| 1| func testUasVThrows_PartiallyApplied_WillGetNilIfParameterCannotBeCastAsU() throws { 611| 1| func f(o object: Thing) -> (Int?) throws -> Void { 612| 1| return { int in self.value = int; self.executed = true } 613| 1| } 614| 1| 615| 1| try weakify(object, f)("123") 616| 1| 617| 1| XCTAssertTrue(executed) 618| 1| XCTAssertEqual(nil, value) 619| 1| } 620| | 621| 1| func testUasVThrows_WillGetNilIfParameterCannotBeCastAsU() throws { 622| 1| func f(o object: Thing, int: Int?) throws -> Void { 623| 1| self.value = int; self.executed = true 624| 1| } 625| 1| 626| 1| try weakify(object, f)("123") 627| 1| 628| 1| XCTAssertTrue(executed) 629| 1| XCTAssertEqual(nil, value) 630| 1| } 631| | 632| 1| func testUasV_PartiallyApplied_WillNotExecuteIfNil() { 633| 0| func f(o object: Thing) -> (Int?) -> Void { 634| 0| return { int in self.value = int; self.executed = true } 635| 0| } 636| 1| 637| 1| let fn: (Any) -> Void = weakify(object, f) 638| 1| object = nil 639| 1| fn("123") 640| 1| 641| 1| XCTAssertFalse(executed) 642| 1| XCTAssertEqual(nil, value) 643| 1| } 644| | 645| 1| func testUasV_WillNotExecuteIfNil() { 646| 0| func f(o object: Thing, int: Int?) -> Void { 647| 0| self.value = int; self.executed = true 648| 0| } 649| 1| 650| 1| let fn: (Any) -> Void = weakify(object, f) 651| 1| object = nil 652| 1| fn("123") 653| 1| 654| 1| XCTAssertFalse(executed) 655| 1| XCTAssertEqual(nil, value) 656| 1| } 657| | 658| 1| func testUasVThrows_PartiallyApplied_WillNotExecuteIfNil() { 659| 0| func f(o object: Thing) -> (Int?) throws -> Void { 660| 0| return { int in self.value = int; self.executed = true } 661| 0| } 662| 1| 663| 1| let fn: (Any) throws -> Void = weakify(object, f) 664| 1| object = nil 665| 1| try! fn("123") 666| 1| 667| 1| XCTAssertFalse(executed) 668| 1| XCTAssertEqual(nil, value) 669| 1| } 670| | 671| 1| func testUasVThrows_WillNotExecuteIfNil() { 672| 0| func f(o object: Thing, int: Int?) throws -> Void { 673| 0| self.value = int; self.executed = true 674| 0| } 675| 1| 676| 1| let fn: (Any) throws -> Void = weakify(object, f) 677| 1| object = nil 678| 1| try! fn("123") 679| 1| 680| 1| XCTAssertFalse(executed) 681| 1| XCTAssertEqual(nil, value) 682| 1| } 683| | 684| 1| func testUasVThrows_PartiallyApplied_WillThrowIfNotNil() { 685| 1| func f(o object: Thing) -> (Int?) throws -> Void { 686| 1| return { _ in throw TestError() } 687| 1| } 688| 1| 689| 1| XCTAssertThrowsError(try weakify(object, f)("123")) 690| 1| } 691| | 692| 1| func testUasVThrows_WillThrowIfNotNil() { 693| 1| func f(o object: Thing, int: Int?) throws -> Void { 694| 1| throw TestError() 695| 1| } 696| 1| 697| 1| XCTAssertThrowsError(try weakify(object, f)("123")) 698| 1| } 699| |} <<<<<< EOF # path=./Weakify.framework.coverage.txt /Users/travis/build/klundberg/Weakify/Sources/Weakify/Weakify.swift: 1| |// Copyright (c) 2015-2017 Kevin Lundberg. See LICENSE file for more info 2| | 3| |// MARK: - (T) -> () -> () 4| | 5| 2|public func weakify (_ owner: T, _ f: @escaping (T) -> () -> Void) -> () -> Void { 6| 2| return { [weak owner] in 7| 1| return owner.map { f($0)() } 8| 2| } 9| 2|} 10| | 11| 3|public func weakify (_ owner: T, _ f: @escaping (T) -> () throws -> Void) -> () throws -> Void { 12| 3| return { [weak owner] in 13| 2| return try owner.map { try f($0)() } 14| 3| } 15| 3|} 16| | 17| |// MARK: - (T) -> () 18| | 19| 2|public func weakify (_ owner: T, _ f: @escaping (T) -> Void) -> () -> Void { 20| 2| return { [weak owner] in 21| 1| return owner.map { f($0) } 22| 2| } 23| 2|} 24| | 25| 3|public func weakify (_ owner: T, _ f: @escaping (T) throws -> Void) -> () throws -> Void { 26| 3| return { [weak owner] in 27| 2| return try owner.map { try f($0) } 28| 3| } 29| 3|} 30| | 31| |// MARK: - (T) -> (_) -> () 32| | 33| |/// May be applied to any method that takes no arguments and returns none. The resulting closure can accept an argument which will simply be ignored (useful in cases like `NSNotificationCenter` when you don't care about the `notification` argument), or the type may also represent `Void`, meaning no input arguments are necessary. 34| |/// 35| |/// - Parameters: 36| |/// - owner: The object to weakly apply to the given curried function or method 37| |/// - f: The function/method to weakly apply owner to as the first argument 38| |/// 39| |/// - returns: A function where owner is weakly applied to the given function f. If owner is nil, nothing happens. If owner is not nil, calls `f(owner)()` 40| 2|public func weakify (_ owner: T, _ f: @escaping (T) -> () -> Void) -> (U) -> Void { 41| 2| return { [weak owner] _ in 42| 1| return owner.map { f($0)() } 43| 2| } 44| 2|} 45| | 46| |/// May be applied to any method that takes no arguments and returns none or throws. The resulting closure can accept an argument which will simply be ignored (useful in cases like `NSNotificationCenter` when you don't care about the `notification` argument), or the type may also represent `Void`, meaning no input arguments are necessary. 47| |/// 48| |/// - parameter owner: The object to weakly apply to the given curried function or method 49| |/// - parameter f: The function/method to weakly apply owner to as the first argument 50| |/// 51| |/// - returns: A function where owner is weakly applied to the given function f. If owner is nil, nothing happens. If owner is not nil, calls `try f(owner)()` 52| 3|public func weakify (_ owner: T, _ f: @escaping (T) -> () throws -> Void) -> (U) throws -> Void { 53| 3| return { [weak owner] _ in 54| 2| return try owner.map { try f($0)() } 55| 3| } 56| 3|} 57| | 58| |// MARK: - (_) -> Void 59| | 60| 2|public func weakify (_ owner: T, _ f: @escaping (T) -> Void) -> (U) -> Void { 61| 2| return { [weak owner] _ in 62| 1| return owner.map { f($0) } 63| 2| } 64| 2|} 65| | 66| 3|public func weakify (_ owner: T, _ f: @escaping (T) throws -> Void) -> (U) throws -> Void { 67| 3| return { [weak owner] _ in 68| 2| return try owner.map { try f($0) } 69| 3| } 70| 3|} 71| | 72| |// MARK: - (T) -> (U) -> () 73| | 74| |/// May be applied to a method that accepts an argument and returns none, which the resulting closure mirrors. 75| |/// 76| |/// - parameter owner: The object to weakly apply to the given curried function or method 77| |/// - parameter f: The function/method to weakly apply owner to as the first argument 78| |/// 79| |/// - returns: A function where owner is weakly applied to the given function f. If owner is nil, nothing happens. If owner is not nil, calls `f(owner)($0)` 80| 4|public func weakify (_ owner: T, _ f: @escaping (T) -> (U) -> Void) -> (U) -> Void { 81| 4| return { [weak owner] obj in 82| 2| return owner.map { f($0)(obj) } 83| 4| } 84| 4|} 85| | 86| |/// May be applied to a method that accepts an argument and returns none or throws, which the resulting closure mirrors. 87| |/// 88| |/// - parameter owner: The object to weakly apply to the given curried function or method 89| |/// - parameter f: The function/method to weakly apply owner to as the first argument 90| |/// 91| |/// - returns: A function where owner is weakly applied to the given function f. If owner is nil, nothing happens. If owner is not nil, calls `try f(owner)($0)` 92| 6|public func weakify (_ owner: T, _ f: @escaping (T) -> (U) throws -> Void) -> (U) throws -> Void { 93| 6| return { [weak owner] obj in 94| 4| return try owner.map { try f($0)(obj) } 95| 6| } 96| 6|} 97| | 98| |// MARK: - (T, U) -> () 99| | 100| 2|public func weakify (_ owner: T, _ f: @escaping (T, U) -> Void) -> (U) -> Void { 101| 2| return weakify(owner, curry(f)) 102| 2|} 103| | 104| 3|public func weakify (_ owner: T, _ f: @escaping (T, U) throws -> Void) -> (U) throws -> Void { 105| 3| return weakify(owner, curry(f)) 106| 3|} 107| | 108| |// MARK: - (T) -> () -> U 109| | 110| |/// May be applied to a function that accepts and returns something. The resulting closure must return optional, since if owner is deallocated before it is called there's nothing else it can return. 111| |/// 112| |/// - parameter owner: The object to weakly apply to the given curried function or method 113| |/// - parameter f: The function/method to weakly apply owner to as the first argument 114| |/// 115| |/// - returns: A function where owner is weakly applied to the given function f. If owner is nil, returns nil. If owner is not nil, returns `f(owner)($0)` 116| 1|public func weakify (_ owner: T, _ f: @escaping (T) -> () -> U) -> () -> U? { 117| 1| return { [weak owner] in 118| 1| return owner.map { f($0)() } 119| 1| } 120| 1|} 121| | 122| |/// May be applied to a function that accepts and returns something or throws. The resulting closure must return optional, since if owner is deallocated before it is called there's nothing else it can return. 123| |/// 124| |/// - parameter owner: The object to weakly apply to the given curried function or method 125| |/// - parameter f: The function/method to weakly apply owner to as the first argument 126| |/// 127| |/// - returns: A function where owner is weakly applied to the given function f. If owner is nil, returns nil. If owner is not nil, returns `f(owner)($0)` 128| 3|public func weakify (_ owner: T, _ f: @escaping (T) -> () throws -> U) -> () throws -> U? { 129| 3| return { [weak owner] in 130| 2| return try owner.map { try f($0)() } 131| 3| } 132| 3|} 133| | 134| |// MARK: - (T) -> U 135| | 136| 3|public func weakify (_ owner: T, _ f: @escaping (T) -> U) -> () -> U? { 137| 3| return { [weak owner] in 138| 1| return owner.map { f($0) } 139| 3| } 140| 3|} 141| | 142| 3|public func weakify (_ owner: T, _ f: @escaping (T) throws -> U) -> () throws -> U? { 143| 3| return { [weak owner] in 144| 2| return try owner.map { try f($0) } 145| 3| } 146| 3|} 147| | 148| |// MARK: - (T) -> (U) -> V 149| | 150| |/// May be applied to a function that accepts and returns something. The resulting closure must return optional, since if owner is deallocated before it is called there's nothing else it can return. 151| |/// 152| |/// - parameter owner: The object to weakly apply to the given curried function or method 153| |/// - parameter f: The function/method to weakly apply owner to as the first argument 154| |/// 155| |/// - returns: A function where owner is weakly applied to the given function f. If owner is nil, returns nil. If owner is not nil, returns `f(owner)($0)` 156| 4|public func weakify (_ owner: T, _ f: @escaping (T) -> (U) -> V) -> (U) -> V? { 157| 4| return { [weak owner] obj in 158| 2| return owner.map { f($0)(obj) } 159| 4| } 160| 4|} 161| | 162| |/// May be applied to a function that accepts and returns something or throws. The resulting closure must return optional, since if owner is deallocated before it is called there's nothing else it can return. 163| |/// 164| |/// - parameter owner: The object to weakly apply to the given curried function or method 165| |/// - parameter f: The function/method to weakly apply owner to as the first argument 166| |/// 167| |/// - returns: A function where owner is weakly applied to the given function f. If owner is nil, returns nil. If owner is not nil, returns `f(owner)($0)` 168| 6|public func weakify (_ owner: T, _ f: @escaping (T) -> (U) throws -> V) -> (U) throws -> V? { 169| 6| return { [weak owner] obj in 170| 4| return try owner.map { try f($0)(obj) } 171| 6| } 172| 6|} 173| | 174| |// MARK -> (T, U) -> V 175| | 176| 2|public func weakify (_ owner: T, _ f: @escaping (T, U) -> V) -> (U) -> V? { 177| 2| return weakify(owner, curry(f)) 178| 2|} 179| | 180| 3|public func weakify (_ owner: T, _ f: @escaping (T, U) throws -> V) -> (U) throws -> V? { 181| 3| return weakify(owner, curry(f)) 182| 3|} 183| | 184| |// MARK: - (T) -> (U?) -> () 185| | 186| |/// May be applied to a function that accepts an optional value. The resulting closure can have a completely different type for the input argument. If owner is not nil at call time, the argument to the resulting closure is conditionally cast from V to U with the as? operator, and the result of that is passed to the original function (which is why it must accept an optional, in case the cast fails). 187| |/// 188| |/// - parameter owner: The object to weakly apply to the given curried function or method 189| |/// - parameter f: The function/method to weakly apply owner to as the first argument 190| |/// 191| |/// - returns: A function where owner is weakly applied to the given function f. If owner is nil, nothing happens. If owner is not nil, returns `f(owner)($0 as? U)` 192| 6|public func weakify (_ owner: T, _ f: @escaping (T) -> (U?) -> Void) -> (V) -> Void { 193| 6| return { [weak owner] obj in 194| 4| return owner.map { f($0)(obj as? U) } 195| 6| } 196| 6|} 197| | 198| |/// May be applied to a function that accepts an optional value or throws. The resulting closure can have a completely different type for the input argument. If owner is not nil at call time, the argument to the resulting closure is conditionally cast from V to U with the as? operator, and the result of that is passed to the original function (which is why it must accept an optional, in case the cast fails). 199| |/// 200| |/// - parameter owner: The object to weakly apply to the given curried function or method 201| |/// - parameter f: The function/method to weakly apply owner to as the first argument 202| |/// 203| |/// - returns: A function where owner is weakly applied to the given function f. If owner is nil, nothing happens. If owner is not nil, returns `try f(owner)($0 as? U)` 204| 8|public func weakify (_ owner: T, _ f: @escaping (T) -> (U?) throws -> Void) -> (V) throws -> Void { 205| 8| return { [weak owner] obj in 206| 6| return try owner.map { try f($0)(obj as? U) } 207| 8| } 208| 8|} 209| | 210| |// MARK: - (T, U?) -> () 211| | 212| 3|public func weakify (_ owner: T, _ f: @escaping (T, U?) -> Void) -> (V) -> Void { 213| 3| return weakify(owner, curry(f)) 214| 3|} 215| | 216| 4|public func weakify (_ owner: T, _ f: @escaping (T, U?) throws -> Void) -> (V) throws -> Void { 217| 4| return weakify(owner, curry(f)) 218| 4|} 219| | 220| |// MARK: - Curry helper functions 221| | 222| 7|private func curry (_ f: @escaping (A, B) -> Result) -> (A) -> (B) -> Result { 223| 4| return { a in { b in f(a,b) } } 224| 7|} 225| | 226| 10|private func curry (_ f: @escaping (A, B) throws -> Result) -> (A) -> (B) throws -> Result { 227| 7| return { a in { b in try f(a,b) } } 228| 10|} <<<<<< EOF # path=fixes ./Package.swift:3,5 ./Sources/Weakify/Weakify.swift:2,4,8,9,10,14,15,16,18,22,23,24,28,29,30,32,43,44,45,55,56,57,59,63,64,65,69,70,71,73,83,84,85,95,96,97,99,102,103,106,107,109,119,120,121,131,132,133,135,139,140,141,145,146,147,149,159,160,161,171,172,173,175,178,179,182,183,185,195,196,197,207,208,209,211,214,215,218,219,221,224,225,228 ./Tests/WeakifyTests/WeakifyTest.swift:2,5,7,9,11,14,17,20,21,23,27,28,30,32,33,37,38,40,42,43,47,48,50,52,53,57,58,60,62,63,67,68,72,74,75,79,80,84,86,87,91,92,96,98,99,103,104,108,110,111,115,116,118,119,123,124,126,127,129,133,134,137,139,140,144,145,148,150,151,155,156,159,161,162,166,167,170,172,173,177,178,182,184,185,189,190,194,196,197,201,202,206,208,209,213,214,218,220,221,225,226,228,230,231,235,236,238,240,241,243,247,248,250,252,253,257,258,260,262,263,267,268,270,272,273,277,278,280,282,283,287,288,292,294,295,299,300,304,306,307,311,312,316,318,319,323,324,328,330,331,335,336,338,339,343,344,346,347,349,353,354,356,358,359,363,366,367,371,372,374,376,377,381,382,384,385,389,390,394,395,399,400,404,405,409,410,414,415,419,420,424,425,429,430,432,434,435,439,440,442,444,445,447,451,452,454,455,459,460,462,463,467,468,470,471,475,476,478,479,483,484,488,489,493,494,498,499,503,504,508,509,513,514,518,519,523,524,526,527,531,532,534,535,537,539,543,544,547,550,551,555,556,559,562,563,567,568,571,574,575,579,580,583,586,587,591,592,594,597,598,602,603,605,608,609,613,614,616,619,620,624,625,627,630,631,635,636,640,643,644,648,649,653,656,657,661,662,666,669,670,674,675,679,682,683,687,688,690,691,695,696,698,699 <<<<<< EOF