Best VfsStream code snippet using has
KVOObservableTests.swift
Source:KVOObservableTests.swift
1//2// KVOObservableTests.swift3// Tests4//5// Created by Krunoslav Zaher on 5/19/15.6// Copyright © 2015 Krunoslav Zaher. All rights reserved.7//8import XCTest9import RxSwift10import RxCocoa11#if os(iOS)12 import UIKit13#elseif os(macOS)14 import Cocoa15#endif16final class KVOObservableTests : RxTest {17}18final class TestClass : NSObject {19 @objc dynamic var pr: String? = "0"20}21final class Parent : NSObject {22 var disposeBag: DisposeBag! = DisposeBag()23 @objc dynamic var val: String = ""24 init(callback: @escaping (String?) -> Void) {25 super.init()26 27 self.rx.observe(String.self, "val", options: [.initial, .new], retainSelf: false)28 .subscribe(onNext: callback)29 .disposed(by: disposeBag)30 }31 32 deinit {33 disposeBag = nil34 }35}36final class Child : NSObject {37 let disposeBag = DisposeBag()38 39 init(parent: ParentWithChild, callback: @escaping (String?) -> Void) {40 super.init()41 parent.rx.observe(String.self, "val", options: [.initial, .new], retainSelf: false)42 .subscribe(onNext: callback)43 .disposed(by: disposeBag)44 }45 46 deinit {47 48 }49}50final class ParentWithChild : NSObject {51 @objc dynamic var val: String = ""52 53 var child: Child? = nil54 55 init(callback: @escaping (String?) -> Void) {56 super.init()57 child = Child(parent: self, callback: callback)58 }59}60@objc enum IntEnum: Int {61 typealias RawValue = Int62 case one63 case two64}65@objc enum UIntEnum: UInt {66 case one67 case two68}69@objc enum Int32Enum: Int32 {70 case one71 case two72}73@objc enum UInt32Enum: UInt32 {74 case one75 case two76}77@objc enum Int64Enum: Int64 {78 case one79 case two80}81@objc enum UInt64Enum: UInt64 {82 case one83 case two84}85final class HasStrongProperty : NSObject {86 @objc dynamic var property: NSObject? = nil87 @objc dynamic var frame: CGRect88 @objc dynamic var point: CGPoint89 @objc dynamic var size: CGSize90 @objc dynamic var intEnum: IntEnum = .one91 @objc dynamic var uintEnum: UIntEnum = .one92 @objc dynamic var int32Enum: Int32Enum = .one93 @objc dynamic var uint32Enum: UInt32Enum = .one94 @objc dynamic var int64Enum: Int64Enum = .one95 @objc dynamic var uint64Enum: UInt64Enum = .one96 97 @objc dynamic var integer: Int98 @objc dynamic var uinteger: UInt99 100 override init() {101 self.frame = CGRect(x: 0, y: 0, width: 100, height: 100)102 self.point = CGPoint(x: 3, y: 5)103 self.size = CGSize(width: 1, height: 2)104 105 self.integer = 1106 self.uinteger = 1107 super.init()108 }109}110final class HasWeakProperty : NSObject {111 @objc dynamic weak var property: NSObject? = nil112 113 override init() {114 super.init()115 }116}117// test fast observe118extension KVOObservableTests {119 func test_New() {120 let testClass = TestClass()121 122 let os = testClass.rx.observe(String.self, "pr", options: .new)123 124 var latest: String?125 126 let d = os.subscribe(onNext: { latest = $0 })127 128 XCTAssertTrue(latest == nil)129 130 testClass.pr = "1"131 132 XCTAssertEqual(latest!, "1")133 134 testClass.pr = "2"135 136 XCTAssertEqual(latest!, "2")137 testClass.pr = nil138 139 XCTAssertTrue(latest == nil)140 testClass.pr = "3"141 142 XCTAssertEqual(latest!, "3")143 144 d.dispose()145 146 testClass.pr = "4"147 XCTAssertEqual(latest!, "3")148 }149 150 func test_New_And_Initial() {151 let testClass = TestClass()152 153 let os = testClass.rx.observe(String.self, "pr", options: [.initial, .new])154 155 var latest: String?156 157 let d = os.subscribe(onNext: { latest = $0 })158 159 XCTAssertTrue(latest == "0")160 161 testClass.pr = "1"162 163 XCTAssertEqual(latest ?? "", "1")164 165 testClass.pr = "2"166 167 XCTAssertEqual(latest ?? "", "2")168 169 testClass.pr = nil170 171 XCTAssertTrue(latest == nil)172 173 testClass.pr = "3"174 175 XCTAssertEqual(latest ?? "", "3")176 177 d.dispose()178 179 testClass.pr = "4"180 181 XCTAssertEqual(latest ?? "", "3")182 }183 184 func test_Default() {185 let testClass = TestClass()186 187 let os = testClass.rx.observe(String.self, "pr")188 189 var latest: String?190 191 let d = os.subscribe(onNext: { latest = $0 })192 193 XCTAssertTrue(latest == "0")194 195 testClass.pr = "1"196 197 XCTAssertEqual(latest!, "1")198 199 testClass.pr = "2"200 201 XCTAssertEqual(latest!, "2")202 203 testClass.pr = nil204 205 XCTAssertTrue(latest == nil)206 207 testClass.pr = "3"208 209 XCTAssertEqual(latest!, "3")210 211 d.dispose()212 213 testClass.pr = "4"214 215 XCTAssertEqual(latest!, "3")216 }217 218 func test_ObserveAndDontRetainWorks() {219 var latest: String?220 var isDisposed = false221 222 var parent: Parent! = Parent { n in223 latest = n224 }225 226 _ = parent.rx.deallocated227 .subscribe(onCompleted: {228 isDisposed = true229 })230 XCTAssertTrue(latest == "")231 XCTAssertTrue(isDisposed == false)232 233 parent.val = "1"234 235 XCTAssertTrue(latest == "1")236 XCTAssertTrue(isDisposed == false)237 238 parent = nil239 240 XCTAssertTrue(latest == "1")241 XCTAssertTrue(isDisposed == true)242 }243 244 func test_ObserveAndDontRetainWorks2() {245 var latest: String?246 var isDisposed = false247 248 var parent: ParentWithChild! = ParentWithChild { n in249 latest = n250 }251 252 _ = parent.rx.deallocated253 .subscribe(onCompleted: {254 isDisposed = true255 })256 XCTAssertTrue(latest == "")257 XCTAssertTrue(isDisposed == false)258 259 parent.val = "1"260 261 XCTAssertTrue(latest == "1")262 XCTAssertTrue(isDisposed == false)263 264 parent = nil265 266 XCTAssertTrue(latest == "1")267 XCTAssertTrue(isDisposed == true)268 }269}270#if !DISABLE_SWIZZLING271// test weak observe 272extension KVOObservableTests {273 274 func testObserveWeak_SimpleStrongProperty() {275 var latest: String?276 var isDisposed = false277 278 var root: HasStrongProperty! = HasStrongProperty()279 280 _ = root.rx.observeWeakly(String.self, "property")281 .subscribe(onNext: { n in282 latest = n283 })284 285 _ = root.rx.deallocated286 .subscribe(onCompleted: {287 isDisposed = true288 })289 XCTAssertTrue(latest == nil)290 XCTAssertTrue(!isDisposed)291 292 root.property = "a".duplicate()293 XCTAssertTrue(latest == "a")294 XCTAssertTrue(!isDisposed)295 296 root = nil297 XCTAssertTrue(latest == nil)298 XCTAssertTrue(isDisposed)299 }300 301 func testObserveWeak_SimpleWeakProperty() {302 var latest: String?303 var isDisposed = false304 305 var root: HasWeakProperty! = HasWeakProperty()306 307 _ = root.rx.observeWeakly(String.self, "property")308 .subscribe(onNext: { n in309 latest = n310 })311 312 _ = root.rx.deallocated313 .subscribe(onCompleted: {314 isDisposed = true315 })316 XCTAssertTrue(latest == nil)317 XCTAssertTrue(!isDisposed)318 319 let a: NSString! = "a".duplicate()320 321 root.property = a322 323 XCTAssertTrue(latest == "a")324 XCTAssertTrue(!isDisposed)325 326 root = nil327 328 XCTAssertTrue(latest == nil)329 XCTAssertTrue(isDisposed)330 }331 func testObserveWeak_ObserveFirst_Weak_Strong_Basic() {332 var latest: String?333 var isDisposed = false334 335 var child: HasStrongProperty! = HasStrongProperty()336 337 var root: HasWeakProperty! = HasWeakProperty()338 339 _ = root.rx.observeWeakly(String.self, "property.property")340 .subscribe(onNext: { n in341 latest = n342 })343 344 _ = root.rx.deallocated345 .subscribe(onCompleted: {346 isDisposed = true347 })348 XCTAssertTrue(latest == nil)349 XCTAssertTrue(isDisposed == false)350 351 root.property = child352 353 XCTAssertTrue(latest == nil)354 XCTAssertTrue(isDisposed == false)355 356 let one: NSString! = "1".duplicate()357 358 child.property = one359 360 XCTAssertTrue(latest == "1")361 XCTAssertTrue(isDisposed == false)362 363 root = nil364 child = nil365 366 XCTAssertTrue(latest == nil)367 XCTAssertTrue(isDisposed == true)368 }369 370 func testObserveWeak_Weak_Strong_Observe_Basic() {371 var latest: String?372 var isDisposed = false373 374 var child: HasStrongProperty! = HasStrongProperty()375 376 var root: HasWeakProperty! = HasWeakProperty()377 378 root.property = child379 380 let one: NSString! = "1".duplicate()381 382 child.property = one383 384 XCTAssertTrue(latest == nil)385 XCTAssertTrue(isDisposed == false)386 387 _ = root.rx.observeWeakly(String.self, "property.property")388 .subscribe(onNext: { n in389 latest = n390 })391 392 _ = root.rx.deallocated393 .subscribe(onCompleted: {394 isDisposed = true395 })396 XCTAssertTrue(latest == "1")397 XCTAssertTrue(isDisposed == false)398 399 root = nil400 child = nil401 402 XCTAssertTrue(latest == nil)403 XCTAssertTrue(isDisposed == true)404 }405 406 func testObserveWeak_ObserveFirst_Strong_Weak_Basic() {407 var latest: String?408 var isDisposed = false409 410 var child: HasWeakProperty! = HasWeakProperty()411 412 var root: HasStrongProperty! = HasStrongProperty()413 414 _ = root.rx.observeWeakly(String.self, "property.property")415 .subscribe(onNext: { n in416 latest = n417 })418 419 _ = root.rx.deallocated420 .subscribe(onCompleted: {421 isDisposed = true422 })423 XCTAssertTrue(latest == nil)424 XCTAssertTrue(isDisposed == false)425 426 root.property = child427 428 XCTAssertTrue(latest == nil)429 XCTAssertTrue(isDisposed == false)430 431 let one: NSString! = "1".duplicate()432 433 child.property = one434 435 XCTAssertTrue(latest == "1")436 XCTAssertTrue(isDisposed == false)437 438 root = nil439 child = nil440 441 XCTAssertTrue(latest == nil)442 XCTAssertTrue(isDisposed == true)443 }444 445 func testObserveWeak_Strong_Weak_Observe_Basic() {446 var latest: String?447 var isDisposed = false448 449 var child: HasWeakProperty! = HasWeakProperty()450 451 var root: HasStrongProperty! = HasStrongProperty()452 453 root.property = child454 455 let one: NSString! = "1".duplicate()456 457 child.property = one458 459 XCTAssertTrue(latest == nil)460 XCTAssertTrue(isDisposed == false)461 462 _ = root.rx.observeWeakly(String.self, "property.property")463 .subscribe(onNext: { n in464 latest = n465 })466 467 _ = root.rx.deallocated468 .subscribe(onCompleted: {469 isDisposed = true470 })471 XCTAssertTrue(latest == "1")472 XCTAssertTrue(isDisposed == false)473 474 root = nil475 child = nil476 477 XCTAssertTrue(latest == nil)478 XCTAssertTrue(isDisposed == true)479 }480 481 // compiler won't release weak references otherwise :(482 func _testObserveWeak_Strong_Weak_Observe_NilLastPropertyBecauseOfWeak() -> (HasWeakProperty, NSObject?, Observable<Void>) {483 var dealloc: Observable<Void>! = nil484 let child: HasWeakProperty! = HasWeakProperty()485 var latest: NSObject? = nil486 487 autoreleasepool {488 let root: HasStrongProperty! = HasStrongProperty()489 490 root.property = child491 492 var one: NSObject! = nil493 494 one = NSObject()495 496 child.property = one497 498 XCTAssertTrue(latest == nil)499 500 let observable = root.rx.observeWeakly(NSObject.self, "property.property")501 _ = observable502 .subscribe(onNext: { n in503 latest = n504 })505 506 XCTAssertTrue(latest! === one)507 508 dealloc = one.rx.deallocating509 510 one = nil511 }512 return (child, latest, dealloc)513 }514 515 func testObserveWeak_Strong_Weak_Observe_NilLastPropertyBecauseOfWeak() {516 var gone = false517 let (child, latest, dealloc) = _testObserveWeak_Strong_Weak_Observe_NilLastPropertyBecauseOfWeak()518 _ = dealloc519 .subscribe(onNext: { n in520 gone = true521 })522 523 XCTAssertTrue(gone)524 XCTAssertTrue(child.property == nil)525 XCTAssertTrue(latest == nil)526 }527 528 func _testObserveWeak_Weak_Weak_Weak_middle_NilifyCorrectly() -> (HasWeakProperty, NSObject?, Observable<Void>) {529 var dealloc: Observable<Void>! = nil530 var middle: HasWeakProperty! = HasWeakProperty()531 var latest: NSObject? = nil532 let root: HasWeakProperty! = HasWeakProperty()533 534 autoreleasepool {535 middle = HasWeakProperty()536 let leaf = HasWeakProperty()537 538 root.property = middle539 middle.property = leaf540 541 XCTAssertTrue(latest == nil)542 543 let observable = root.rx.observeWeakly(NSObject.self, "property.property.property")544 _ = observable545 .subscribe(onNext: { n in546 latest = n547 })548 549 XCTAssertTrue(latest == nil)550 551 let one = NSObject()552 553 leaf.property = one554 555 XCTAssertTrue(latest === one)556 557 dealloc = middle.rx.deallocating558 }559 return (root!, latest, dealloc)560 }561 562 func testObserveWeak_Weak_Weak_Weak_middle_NilifyCorrectly() {563 let (root, latest, deallocatedMiddle) = _testObserveWeak_Weak_Weak_Weak_middle_NilifyCorrectly()564 565 var gone = false566 567 _ = deallocatedMiddle568 .subscribe(onCompleted: {569 gone = true570 })571 572 XCTAssertTrue(gone)573 XCTAssertTrue(root.property == nil)574 XCTAssertTrue(latest == nil)575 }576 577 func testObserveWeak_TargetDeallocated() {578 var root: HasStrongProperty! = HasStrongProperty()579 580 var latest: String? = nil581 582 root.property = "a".duplicate()583 584 XCTAssertTrue(latest == nil)585 586 _ = root587 .rx.observeWeakly(String.self, "property")588 .subscribe(onNext: { n in589 latest = n590 })591 592 XCTAssertTrue(latest == "a")593 594 var rootDeallocated = false595 596 _ = root597 .rx.deallocated598 .subscribe(onCompleted: {599 rootDeallocated = true600 })601 602 root = nil603 604 XCTAssertTrue(latest == nil)605 XCTAssertTrue(rootDeallocated)606 }607 608 func testObserveWeakWithOptions_ObserveNotInitialValue() {609 var root: HasStrongProperty! = HasStrongProperty()610 611 var latest: String? = nil612 613 root.property = "a".duplicate()614 615 XCTAssertTrue(latest == nil)616 617 _ = root618 .rx.observeWeakly(String.self, "property", options: .new)619 .subscribe(onNext: { n in620 latest = n621 })622 623 XCTAssertTrue(latest == nil)624 625 root.property = "b".duplicate()626 XCTAssertTrue(latest == "b")627 628 var rootDeallocated = false629 630 _ = root631 .rx.deallocated632 .subscribe(onCompleted: {633 rootDeallocated = true634 })635 636 root = nil637 638 XCTAssertTrue(latest == nil)639 XCTAssertTrue(rootDeallocated)640 }641 642 #if os(macOS)643 // just making sure it's all the same for NS extensions644 func testObserve_ObserveNSRect() {645 var root: HasStrongProperty! = HasStrongProperty()646 647 var latest: NSRect? = nil648 649 XCTAssertTrue(latest == nil)650 651 let disposable = root.rx.observe(NSRect.self, "frame")652 .subscribe(onNext: { n in653 latest = n654 })655 XCTAssertTrue(latest == root.frame)656 657 root.frame = NSRect(x: -2, y: 0, width: 0, height: 1)658 659 XCTAssertTrue(latest == NSRect(x: -2, y: 0, width: 0, height: 1))660 661 var rootDeallocated = false662 663 _ = root664 .rx.deallocated665 .subscribe(onCompleted: {666 rootDeallocated = true667 })668 669 root = nil670 671 XCTAssertTrue(latest == NSRect(x: -2, y: 0, width: 0, height: 1))672 XCTAssertTrue(!rootDeallocated)673 674 disposable.dispose()675 }676 #endif677 678 // let's just check for one, otherones should have the same check679 func testObserve_ObserveCGRectForBiggerStructureDoesntCrashPropertyTypeReturnsNil() {680 var root: HasStrongProperty! = HasStrongProperty()681 682 var latest: CGSize? = nil683 684 XCTAssertTrue(latest == nil)685 686 let d = root.rx.observe(CGSize.self, "frame")687 .subscribe(onNext: { n in688 latest = n689 })690 defer {691 d.dispose()692 }693 XCTAssertTrue(latest == nil)694 695 root.size = CGSize(width: 56, height: 1)696 697 XCTAssertTrue(latest == nil)698 699 var rootDeallocated = false700 701 _ = root702 .rx.deallocated703 .subscribe(onCompleted: {704 rootDeallocated = true705 })706 707 root = nil708 709 XCTAssertTrue(latest == nil)710 XCTAssertTrue(!rootDeallocated)711 }712 713 func testObserve_ObserveCGRect() {714 var root: HasStrongProperty! = HasStrongProperty()715 716 var latest: CGRect? = nil717 718 XCTAssertTrue(latest == nil)719 720 let d = root.rx.observe(CGRect.self, "frame")721 .subscribe(onNext: { n in722 latest = n723 })724 defer {725 d.dispose()726 }727 XCTAssertTrue(latest == root.frame)728 729 root.frame = CGRect(x: -2, y: 0, width: 0, height: 1)730 731 XCTAssertTrue(latest == CGRect(x: -2, y: 0, width: 0, height: 1))732 733 var rootDeallocated = false734 735 _ = root736 .rx.deallocated737 .subscribe(onCompleted: {738 rootDeallocated = true739 })740 741 root = nil742 743 XCTAssertTrue(latest == CGRect(x: -2, y: 0, width: 0, height: 1))744 XCTAssertTrue(!rootDeallocated)745 }746 747 func testObserve_ObserveCGSize() {748 var root: HasStrongProperty! = HasStrongProperty()749 750 var latest: CGSize? = nil751 752 XCTAssertTrue(latest == nil)753 754 let d = root.rx.observe(CGSize.self, "size")755 .subscribe(onNext: { n in756 latest = n757 })758 defer {759 d.dispose()760 }761 XCTAssertTrue(latest == root.size)762 763 root.size = CGSize(width: 56, height: 1)764 765 XCTAssertTrue(latest == CGSize(width: 56, height: 1))766 767 var rootDeallocated = false768 769 _ = root770 .rx.deallocated771 .subscribe(onCompleted: {772 rootDeallocated = true773 })774 775 root = nil776 777 XCTAssertTrue(latest == CGSize(width: 56, height: 1))778 XCTAssertTrue(!rootDeallocated)779 }780 781 func testObserve_ObserveCGPoint() {782 var root: HasStrongProperty! = HasStrongProperty()783 784 var latest: CGPoint? = nil785 786 XCTAssertTrue(latest == nil)787 788 let d = root.rx.observe(CGPoint.self, "point")789 .subscribe(onNext: { n in790 latest = n791 })792 defer {793 d.dispose()794 }795 796 XCTAssertTrue(latest == root.point)797 798 root.point = CGPoint(x: -100, y: 1)799 800 XCTAssertTrue(latest == CGPoint(x: -100, y: 1))801 802 var rootDeallocated = false803 804 _ = root805 .rx.deallocated806 .subscribe(onCompleted: {807 rootDeallocated = true808 })809 810 root = nil811 812 XCTAssertTrue(latest == CGPoint(x: -100, y: 1))813 XCTAssertTrue(!rootDeallocated)814 }815 816 817 func testObserveWeak_ObserveCGRect() {818 var root: HasStrongProperty! = HasStrongProperty()819 820 var latest: CGRect? = nil821 822 XCTAssertTrue(latest == nil)823 824 _ = root825 .rx.observeWeakly(CGRect.self, "frame")826 .subscribe(onNext: { n in827 latest = n828 })829 XCTAssertTrue(latest == root.frame)830 831 root.frame = CGRect(x: -2, y: 0, width: 0, height: 1)832 833 XCTAssertTrue(latest == CGRect(x: -2, y: 0, width: 0, height: 1))834 835 var rootDeallocated = false836 837 _ = root838 .rx.deallocated839 .subscribe(onCompleted: {840 rootDeallocated = true841 })842 843 root = nil844 845 XCTAssertTrue(latest == nil)846 XCTAssertTrue(rootDeallocated)847 }848 849 func testObserveWeak_ObserveCGSize() {850 var root: HasStrongProperty! = HasStrongProperty()851 852 var latest: CGSize? = nil853 854 XCTAssertTrue(latest == nil)855 856 _ = root857 .rx.observeWeakly(CGSize.self, "size")858 .subscribe(onNext: { n in859 latest = n860 })861 XCTAssertTrue(latest == root.size)862 863 root.size = CGSize(width: 56, height: 1)864 865 XCTAssertTrue(latest == CGSize(width: 56, height: 1))866 867 var rootDeallocated = false868 869 _ = root870 .rx.deallocated871 .subscribe(onCompleted: {872 rootDeallocated = true873 })874 875 root = nil876 877 XCTAssertTrue(latest == nil)878 XCTAssertTrue(rootDeallocated)879 }880 881 func testObserveWeak_ObserveCGPoint() {882 var root: HasStrongProperty! = HasStrongProperty()883 884 var latest: CGPoint? = nil885 886 XCTAssertTrue(latest == nil)887 888 _ = root889 .rx.observeWeakly(CGPoint.self, "point")890 .subscribe(onNext: { n in891 latest = n892 })893 894 XCTAssertTrue(latest == root.point)895 896 root.point = CGPoint(x: -100, y: 1)897 898 XCTAssertTrue(latest == CGPoint(x: -100, y: 1))899 900 var rootDeallocated = false901 902 _ = root903 .rx.deallocated904 .subscribe(onCompleted: {905 rootDeallocated = true906 })907 908 root = nil909 910 XCTAssertTrue(latest == nil)911 XCTAssertTrue(rootDeallocated)912 }913 914 func testObserveWeak_ObserveInt() {915 var root: HasStrongProperty! = HasStrongProperty()916 917 var latest: Int? = nil918 919 XCTAssertTrue(latest == nil)920 921 _ = root922 .rx.observeWeakly(NSNumber.self, "integer")923 .subscribe(onNext: { n in924 latest = n?.intValue925 })926 XCTAssertTrue(latest == root.integer)927 928 root.integer = 10929 930 XCTAssertTrue(latest == 10)931 932 var rootDeallocated = false933 934 _ = root935 .rx.deallocated936 .subscribe(onCompleted: {937 rootDeallocated = true938 })939 940 root = nil941 942 XCTAssertTrue(latest == nil)943 XCTAssertTrue(rootDeallocated)944 }945 func testObserveWeak_PropertyDoesntExist() {946 var root: HasStrongProperty! = HasStrongProperty()947 948 var lastError: Swift.Error? = nil949 950 _ = root.rx.observeWeakly(NSNumber.self, "notExist")951 .subscribe(onError: { error in952 lastError = error953 })954 955 XCTAssertTrue(lastError != nil)956 lastError = nil957 var rootDeallocated = false958 959 _ = root960 .rx.deallocated961 .subscribe(onCompleted: {962 rootDeallocated = true963 })964 965 root = nil966 967 XCTAssertTrue(rootDeallocated)968 }969 970 func testObserveWeak_HierarchyPropertyDoesntExist() {971 var root: HasStrongProperty! = HasStrongProperty()972 973 var lastError: Swift.Error? = nil974 975 _ = root.rx.observeWeakly(NSNumber.self, "property.notExist")976 .subscribe(onError: { error in977 lastError = error978 })979 980 XCTAssertTrue(lastError == nil)981 982 root.property = HasStrongProperty()983 XCTAssertTrue(lastError != nil)984 985 var rootDeallocated = false986 987 _ = root988 .rx.deallocated989 .subscribe(onCompleted: {990 rootDeallocated = true991 })992 993 root = nil994 995 XCTAssertTrue(rootDeallocated)996 }997}998#endif999// MARK: KVORepresentable1000extension KVOObservableTests {1001 func testObserve_ObserveIntegerRepresentable() {1002 var root: HasStrongProperty! = HasStrongProperty()1003 var latest: Int?1004 XCTAssertTrue(latest == nil)1005 let disposable = root.rx.observe(Int.self, "integer")1006 .subscribe(onNext: { n in1007 latest = n1008 })1009 XCTAssertTrue(latest == 1)1010 root.integer = 21011 XCTAssertTrue(latest == 2)1012 var rootDeallocated = false1013 _ = root1014 .rx.deallocated1015 .subscribe(onCompleted: {1016 rootDeallocated = true1017 })1018 root = nil1019 XCTAssertTrue(latest == 2)1020 XCTAssertTrue(!rootDeallocated)1021 disposable.dispose()1022 }1023 func testObserve_ObserveUIntegerRepresentable() {1024 var root: HasStrongProperty! = HasStrongProperty()1025 var latest: UInt?1026 XCTAssertTrue(latest == nil)1027 let disposable = root.rx.observe(UInt.self, "uinteger")1028 .subscribe(onNext: { n in1029 latest = n1030 })1031 XCTAssertTrue(latest == 1)1032 root.uinteger = 21033 XCTAssertTrue(latest == 2)1034 var rootDeallocated = false1035 _ = root1036 .rx.deallocated1037 .subscribe(onCompleted: {1038 rootDeallocated = true1039 })1040 root = nil1041 XCTAssertTrue(latest == 2)1042 XCTAssertTrue(!rootDeallocated)1043 1044 disposable.dispose()1045 }1046}1047#if !DISABLE_SWIZZLING1048 extension KVOObservableTests {1049 func testObserveWeak_ObserveIntegerRepresentable() {1050 var root: HasStrongProperty! = HasStrongProperty()1051 var latest: Int?1052 XCTAssertTrue(latest == nil)1053 _ = root1054 .rx.observeWeakly(Int.self, "integer")1055 .subscribe(onNext: { n in1056 latest = n1057 })1058 XCTAssertTrue(latest == 1)1059 root.integer = 21060 XCTAssertTrue(latest == 2)1061 var rootDeallocated = false1062 _ = root1063 .rx.deallocated1064 .subscribe(onCompleted: {1065 rootDeallocated = true1066 })1067 1068 root = nil1069 1070 XCTAssertTrue(latest == nil)1071 XCTAssertTrue(rootDeallocated)1072 }1073 func testObserveWeak_ObserveUIntegerRepresentable() {1074 var root: HasStrongProperty! = HasStrongProperty()1075 var latest: UInt?1076 XCTAssertTrue(latest == nil)1077 _ = root1078 .rx.observeWeakly(UInt.self, "uinteger")1079 .subscribe(onNext: { n in1080 latest = n1081 })1082 XCTAssertTrue(latest == 1)1083 root.uinteger = 21084 XCTAssertTrue(latest == 2)1085 var rootDeallocated = false1086 _ = root1087 .rx.deallocated1088 .subscribe(onCompleted: {1089 rootDeallocated = true1090 })1091 root = nil1092 XCTAssertTrue(latest == nil)1093 XCTAssertTrue(rootDeallocated)1094 }1095 }1096#endif1097// MARK: RawRepresentable1098extension KVOObservableTests {1099 func testObserve_ObserveIntEnum() {1100 var root: HasStrongProperty! = HasStrongProperty()1101 var latest: IntEnum?1102 XCTAssertTrue(latest == nil)1103 let disposable = root.rx.observe(IntEnum.self, "intEnum")1104 .subscribe(onNext: { n in1105 latest = n1106 })1107 XCTAssertTrue(latest == .one)1108 root.intEnum = .two1109 XCTAssertTrue(latest == .two)1110 var rootDeallocated = false1111 _ = root1112 .rx.deallocated1113 .subscribe(onCompleted: {1114 rootDeallocated = true1115 })1116 root = nil1117 XCTAssertTrue(latest == .two)1118 XCTAssertTrue(!rootDeallocated)1119 disposable.dispose()1120 }1121 func testObserve_ObserveInt32Enum() {1122 var root: HasStrongProperty! = HasStrongProperty()1123 var latest: Int32Enum?1124 XCTAssertTrue(latest == nil)1125 let disposable = root.rx.observe(Int32Enum.self, "int32Enum")1126 .subscribe(onNext: { n in1127 latest = n1128 })1129 XCTAssertTrue(latest == .one)1130 root.int32Enum = .two1131 XCTAssertTrue(latest == .two)1132 var rootDeallocated = false1133 _ = root1134 .rx.deallocated1135 .subscribe(onCompleted: {1136 rootDeallocated = true1137 })1138 root = nil1139 XCTAssertTrue(latest == .two)1140 XCTAssertTrue(!rootDeallocated)1141 1142 disposable.dispose()1143 }1144 func testObserve_ObserveInt64Enum() {1145 var root: HasStrongProperty! = HasStrongProperty()1146 var latest: Int64Enum?1147 XCTAssertTrue(latest == nil)1148 let disposable = root.rx.observe(Int64Enum.self, "int64Enum")1149 .subscribe(onNext: { n in1150 latest = n1151 })1152 XCTAssertTrue(latest == .one)1153 root.int64Enum = .two1154 XCTAssertTrue(latest == .two)1155 var rootDeallocated = false1156 _ = root1157 .rx.deallocated1158 .subscribe(onCompleted: {1159 rootDeallocated = true1160 })1161 root = nil1162 XCTAssertTrue(latest == .two)1163 XCTAssertTrue(!rootDeallocated)1164 1165 disposable.dispose()1166 }1167 func testObserve_ObserveUIntEnum() {1168 var root: HasStrongProperty! = HasStrongProperty()1169 var latest: UIntEnum?1170 XCTAssertTrue(latest == nil)1171 let disposable = root.rx.observe(UIntEnum.self, "uintEnum")1172 .subscribe(onNext: { n in1173 latest = n1174 })1175 XCTAssertTrue(latest == .one)1176 root.uintEnum = .two1177 XCTAssertTrue(latest == .two)1178 var rootDeallocated = false1179 _ = root1180 .rx.deallocated1181 .subscribe(onCompleted: {1182 rootDeallocated = true1183 })1184 root = nil1185 XCTAssertTrue(latest == .two)1186 XCTAssertTrue(!rootDeallocated)1187 disposable.dispose()1188 }1189 func testObserve_ObserveUInt32Enum() {1190 var root: HasStrongProperty! = HasStrongProperty()1191 var latest: UInt32Enum?1192 XCTAssertTrue(latest == nil)1193 let disposable = root.rx.observe(UInt32Enum.self, "uint32Enum")1194 .subscribe(onNext: { n in1195 latest = n1196 })1197 XCTAssertTrue(latest == .one)1198 root.uint32Enum = .two1199 XCTAssertTrue(latest == .two)1200 var rootDeallocated = false1201 _ = root1202 .rx.deallocated1203 .subscribe(onCompleted: {1204 rootDeallocated = true1205 })1206 root = nil1207 XCTAssertTrue(latest == .two)1208 XCTAssertTrue(!rootDeallocated)1209 1210 disposable.dispose()1211 }1212 func testObserve_ObserveUInt64Enum() {1213 var root: HasStrongProperty! = HasStrongProperty()1214 var latest: UInt64Enum?1215 XCTAssertTrue(latest == nil)1216 let disposable = root.rx.observe(UInt64Enum.self, "uint64Enum")1217 .subscribe(onNext: { n in1218 latest = n1219 })1220 XCTAssertTrue(latest == .one)1221 root.uint64Enum = .two1222 XCTAssertTrue(latest == .two)1223 var rootDeallocated = false1224 _ = root1225 .rx.deallocated1226 .subscribe(onCompleted: {1227 rootDeallocated = true1228 })1229 root = nil1230 XCTAssertTrue(latest == .two)1231 XCTAssertTrue(!rootDeallocated)1232 1233 disposable.dispose()1234 }1235}1236#if !DISABLE_SWIZZLING1237extension KVOObservableTests {1238 func testObserveWeak_ObserveIntEnum() {1239 var root: HasStrongProperty! = HasStrongProperty()1240 var latest: IntEnum?1241 XCTAssertTrue(latest == nil)1242 _ = root1243 .rx.observeWeakly(IntEnum.self, "intEnum")1244 .subscribe(onNext: { n in1245 latest = n1246 })1247 XCTAssertTrue(latest == .one)1248 root.intEnum = .two1249 XCTAssertTrue(latest == .two)1250 var rootDeallocated = false1251 _ = root1252 .rx.deallocated1253 .subscribe(onCompleted: {1254 rootDeallocated = true1255 })1256 root = nil1257 XCTAssertTrue(latest == nil)1258 XCTAssertTrue(rootDeallocated)1259 }1260 func testObserveWeak_ObserveInt32Enum() {1261 var root: HasStrongProperty! = HasStrongProperty()1262 var latest: Int32Enum?1263 XCTAssertTrue(latest == nil)1264 _ = root1265 .rx.observeWeakly(Int32Enum.self, "int32Enum")1266 .subscribe(onNext: { n in1267 latest = n1268 })1269 XCTAssertTrue(latest == .one)1270 root.int32Enum = .two1271 XCTAssertTrue(latest == .two)1272 var rootDeallocated = false1273 _ = root1274 .rx.deallocated1275 .subscribe(onCompleted: {1276 rootDeallocated = true1277 })1278 root = nil1279 XCTAssertTrue(latest == nil)1280 XCTAssertTrue(rootDeallocated)1281 }1282 func testObserveWeak_ObserveInt64Enum() {1283 var root: HasStrongProperty! = HasStrongProperty()1284 var latest: Int64Enum?1285 XCTAssertTrue(latest == nil)1286 _ = root1287 .rx.observeWeakly(Int64Enum.self, "int64Enum")1288 .subscribe(onNext: { n in1289 latest = n1290 })1291 XCTAssertTrue(latest == .one)1292 root.int64Enum = .two1293 XCTAssertTrue(latest == .two)1294 var rootDeallocated = false1295 _ = root1296 .rx.deallocated1297 .subscribe(onCompleted: {1298 rootDeallocated = true1299 })1300 root = nil1301 XCTAssertTrue(latest == nil)1302 XCTAssertTrue(rootDeallocated)1303 }1304 func testObserveWeak_ObserveUIntEnum() {1305 var root: HasStrongProperty! = HasStrongProperty()1306 var latest: UIntEnum?1307 XCTAssertTrue(latest == nil)1308 _ = root1309 .rx.observeWeakly(UIntEnum.self, "uintEnum")1310 .subscribe(onNext: { n in1311 latest = n1312 })1313 XCTAssertTrue(latest == .one)1314 root.uintEnum = .two1315 XCTAssertTrue(latest == .two)1316 var rootDeallocated = false1317 _ = root1318 .rx.deallocated1319 .subscribe(onCompleted: {1320 rootDeallocated = true1321 })1322 root = nil1323 XCTAssertTrue(latest == nil)1324 XCTAssertTrue(rootDeallocated)1325 }1326 func testObserveWeak_ObserveUInt32Enum() {1327 var root: HasStrongProperty! = HasStrongProperty()1328 var latest: UInt32Enum?1329 XCTAssertTrue(latest == nil)1330 _ = root1331 .rx.observeWeakly(UInt32Enum.self, "uint32Enum")1332 .subscribe(onNext: { n in1333 latest = n1334 })1335 XCTAssertTrue(latest == .one)1336 root.uint32Enum = .two1337 XCTAssertTrue(latest == .two)1338 var rootDeallocated = false1339 _ = root1340 .rx.deallocated1341 .subscribe(onCompleted: {1342 rootDeallocated = true1343 })1344 root = nil1345 XCTAssertTrue(latest == nil)1346 XCTAssertTrue(rootDeallocated)1347 }1348 func testObserveWeak_ObserveUInt64Enum() {1349 var root: HasStrongProperty! = HasStrongProperty()1350 var latest: UInt32Enum?1351 XCTAssertTrue(latest == nil)1352 _ = root1353 .rx.observeWeakly(UInt32Enum.self, "uint64Enum")1354 .subscribe(onNext: { n in1355 latest = n1356 })1357 XCTAssertTrue(latest == .one)1358 root.uint64Enum = .two1359 XCTAssertTrue(latest == .two)1360 var rootDeallocated = false1361 _ = root1362 .rx.deallocated1363 .subscribe(onCompleted: {1364 rootDeallocated = true1365 })1366 root = nil1367 XCTAssertTrue(latest == nil)1368 XCTAssertTrue(rootDeallocated)1369 }1370}1371#endif1372extension NSString {1373 func duplicate() -> NSString {1374 return NSMutableString(string: self)1375 }1376}...
Mapper.php
Source:Mapper.php
...29 'loadedExtensions' => [],30 'unavailableExtensions' => [],31 'notLoadedExtensions' => [],32 ];33 if ($arguments->hasColors()) {34 $result['colors'] = $arguments->colors();35 }36 if ($arguments->hasBootstrap()) {37 $result['bootstrap'] = $arguments->bootstrap();38 }39 if ($arguments->hasCacheResult()) {40 $result['cacheResult'] = $arguments->cacheResult();41 }42 if ($arguments->hasCacheResultFile()) {43 $result['cacheResultFile'] = $arguments->cacheResultFile();44 }45 if ($arguments->hasColumns()) {46 $result['columns'] = $arguments->columns();47 }48 if ($arguments->hasConfiguration()) {49 $result['configuration'] = $arguments->configuration();50 }51 if ($arguments->hasCoverageCacheDirectory()) {52 $result['coverageCacheDirectory'] = $arguments->coverageCacheDirectory();53 }54 if ($arguments->hasWarmCoverageCache()) {55 $result['warmCoverageCache'] = $arguments->warmCoverageCache();56 }57 if ($arguments->hasCoverageClover()) {58 $result['coverageClover'] = $arguments->coverageClover();59 }60 if ($arguments->hasCoverageCobertura()) {61 $result['coverageCobertura'] = $arguments->coverageCobertura();62 }63 if ($arguments->hasCoverageCrap4J()) {64 $result['coverageCrap4J'] = $arguments->coverageCrap4J();65 }66 if ($arguments->hasCoverageHtml()) {67 $result['coverageHtml'] = $arguments->coverageHtml();68 }69 if ($arguments->hasCoveragePhp()) {70 $result['coveragePHP'] = $arguments->coveragePhp();71 }72 if ($arguments->hasCoverageText()) {73 $result['coverageText'] = $arguments->coverageText();74 }75 if ($arguments->hasCoverageTextShowUncoveredFiles()) {76 $result['coverageTextShowUncoveredFiles'] = $arguments->hasCoverageTextShowUncoveredFiles();77 }78 if ($arguments->hasCoverageTextShowOnlySummary()) {79 $result['coverageTextShowOnlySummary'] = $arguments->coverageTextShowOnlySummary();80 }81 if ($arguments->hasCoverageXml()) {82 $result['coverageXml'] = $arguments->coverageXml();83 }84 if ($arguments->hasPathCoverage()) {85 $result['pathCoverage'] = $arguments->pathCoverage();86 }87 if ($arguments->hasDebug()) {88 $result['debug'] = $arguments->debug();89 }90 if ($arguments->hasHelp()) {91 $result['help'] = $arguments->help();92 }93 if ($arguments->hasFilter()) {94 $result['filter'] = $arguments->filter();95 }96 if ($arguments->hasTestSuite()) {97 $result['testsuite'] = $arguments->testSuite();98 }99 if ($arguments->hasGroups()) {100 $result['groups'] = $arguments->groups();101 }102 if ($arguments->hasExcludeGroups()) {103 $result['excludeGroups'] = $arguments->excludeGroups();104 }105 if ($arguments->hasTestsCovering()) {106 $result['testsCovering'] = $arguments->testsCovering();107 }108 if ($arguments->hasTestsUsing()) {109 $result['testsUsing'] = $arguments->testsUsing();110 }111 if ($arguments->hasTestSuffixes()) {112 $result['testSuffixes'] = $arguments->testSuffixes();113 }114 if ($arguments->hasIncludePath()) {115 $result['includePath'] = $arguments->includePath();116 }117 if ($arguments->hasListGroups()) {118 $result['listGroups'] = $arguments->listGroups();119 }120 if ($arguments->hasListSuites()) {121 $result['listSuites'] = $arguments->listSuites();122 }123 if ($arguments->hasListTests()) {124 $result['listTests'] = $arguments->listTests();125 }126 if ($arguments->hasListTestsXml()) {127 $result['listTestsXml'] = $arguments->listTestsXml();128 }129 if ($arguments->hasPrinter()) {130 $result['printer'] = $arguments->printer();131 }132 if ($arguments->hasLoader()) {133 $result['loader'] = $arguments->loader();134 }135 if ($arguments->hasJunitLogfile()) {136 $result['junitLogfile'] = $arguments->junitLogfile();137 }138 if ($arguments->hasTeamcityLogfile()) {139 $result['teamcityLogfile'] = $arguments->teamcityLogfile();140 }141 if ($arguments->hasExecutionOrder()) {142 $result['executionOrder'] = $arguments->executionOrder();143 }144 if ($arguments->hasExecutionOrderDefects()) {145 $result['executionOrderDefects'] = $arguments->executionOrderDefects();146 }147 if ($arguments->hasExtensions()) {148 $result['extensions'] = $arguments->extensions();149 }150 if ($arguments->hasUnavailableExtensions()) {151 $result['unavailableExtensions'] = $arguments->unavailableExtensions();152 }153 if ($arguments->hasResolveDependencies()) {154 $result['resolveDependencies'] = $arguments->resolveDependencies();155 }156 if ($arguments->hasProcessIsolation()) {157 $result['processIsolation'] = $arguments->processIsolation();158 }159 if ($arguments->hasRepeat()) {160 $result['repeat'] = $arguments->repeat();161 }162 if ($arguments->hasStderr()) {163 $result['stderr'] = $arguments->stderr();164 }165 if ($arguments->hasStopOnDefect()) {166 $result['stopOnDefect'] = $arguments->stopOnDefect();167 }168 if ($arguments->hasStopOnError()) {169 $result['stopOnError'] = $arguments->stopOnError();170 }171 if ($arguments->hasStopOnFailure()) {172 $result['stopOnFailure'] = $arguments->stopOnFailure();173 }174 if ($arguments->hasStopOnWarning()) {175 $result['stopOnWarning'] = $arguments->stopOnWarning();176 }177 if ($arguments->hasStopOnIncomplete()) {178 $result['stopOnIncomplete'] = $arguments->stopOnIncomplete();179 }180 if ($arguments->hasStopOnRisky()) {181 $result['stopOnRisky'] = $arguments->stopOnRisky();182 }183 if ($arguments->hasStopOnSkipped()) {184 $result['stopOnSkipped'] = $arguments->stopOnSkipped();185 }186 if ($arguments->hasFailOnEmptyTestSuite()) {187 $result['failOnEmptyTestSuite'] = $arguments->failOnEmptyTestSuite();188 }189 if ($arguments->hasFailOnIncomplete()) {190 $result['failOnIncomplete'] = $arguments->failOnIncomplete();191 }192 if ($arguments->hasFailOnRisky()) {193 $result['failOnRisky'] = $arguments->failOnRisky();194 }195 if ($arguments->hasFailOnSkipped()) {196 $result['failOnSkipped'] = $arguments->failOnSkipped();197 }198 if ($arguments->hasFailOnWarning()) {199 $result['failOnWarning'] = $arguments->failOnWarning();200 }201 if ($arguments->hasTestdoxGroups()) {202 $result['testdoxGroups'] = $arguments->testdoxGroups();203 }204 if ($arguments->hasTestdoxExcludeGroups()) {205 $result['testdoxExcludeGroups'] = $arguments->testdoxExcludeGroups();206 }207 if ($arguments->hasTestdoxHtmlFile()) {208 $result['testdoxHTMLFile'] = $arguments->testdoxHtmlFile();209 }210 if ($arguments->hasTestdoxTextFile()) {211 $result['testdoxTextFile'] = $arguments->testdoxTextFile();212 }213 if ($arguments->hasTestdoxXmlFile()) {214 $result['testdoxXMLFile'] = $arguments->testdoxXmlFile();215 }216 if ($arguments->hasUseDefaultConfiguration()) {217 $result['useDefaultConfiguration'] = $arguments->useDefaultConfiguration();218 }219 if ($arguments->hasNoExtensions()) {220 $result['noExtensions'] = $arguments->noExtensions();221 }222 if ($arguments->hasNoCoverage()) {223 $result['noCoverage'] = $arguments->noCoverage();224 }225 if ($arguments->hasNoLogging()) {226 $result['noLogging'] = $arguments->noLogging();227 }228 if ($arguments->hasNoInteraction()) {229 $result['noInteraction'] = $arguments->noInteraction();230 }231 if ($arguments->hasBackupGlobals()) {232 $result['backupGlobals'] = $arguments->backupGlobals();233 }234 if ($arguments->hasBackupStaticAttributes()) {235 $result['backupStaticAttributes'] = $arguments->backupStaticAttributes();236 }237 if ($arguments->hasVerbose()) {238 $result['verbose'] = $arguments->verbose();239 }240 if ($arguments->hasReportUselessTests()) {241 $result['reportUselessTests'] = $arguments->reportUselessTests();242 }243 if ($arguments->hasStrictCoverage()) {244 $result['strictCoverage'] = $arguments->strictCoverage();245 }246 if ($arguments->hasDisableCodeCoverageIgnore()) {247 $result['disableCodeCoverageIgnore'] = $arguments->disableCodeCoverageIgnore();248 }249 if ($arguments->hasBeStrictAboutChangesToGlobalState()) {250 $result['beStrictAboutChangesToGlobalState'] = $arguments->beStrictAboutChangesToGlobalState();251 }252 if ($arguments->hasDisallowTestOutput()) {253 $result['disallowTestOutput'] = $arguments->disallowTestOutput();254 }255 if ($arguments->hasBeStrictAboutResourceUsageDuringSmallTests()) {256 $result['beStrictAboutResourceUsageDuringSmallTests'] = $arguments->beStrictAboutResourceUsageDuringSmallTests();257 }258 if ($arguments->hasDefaultTimeLimit()) {259 $result['defaultTimeLimit'] = $arguments->defaultTimeLimit();260 }261 if ($arguments->hasEnforceTimeLimit()) {262 $result['enforceTimeLimit'] = $arguments->enforceTimeLimit();263 }264 if ($arguments->hasDisallowTodoAnnotatedTests()) {265 $result['disallowTodoAnnotatedTests'] = $arguments->disallowTodoAnnotatedTests();266 }267 if ($arguments->hasReverseList()) {268 $result['reverseList'] = $arguments->reverseList();269 }270 if ($arguments->hasCoverageFilter()) {271 $result['coverageFilter'] = $arguments->coverageFilter();272 }273 if ($arguments->hasRandomOrderSeed()) {274 $result['randomOrderSeed'] = $arguments->randomOrderSeed();275 }276 if ($arguments->hasXdebugFilterFile()) {277 $result['xdebugFilterFile'] = $arguments->xdebugFilterFile();278 }279 return $result;280 }281}...
HasText.swift
Source:HasText.swift
1extension String {2 public var wmf_hasText: Bool {3 return !isEmpty4 }5 public var wmf_hasNonWhitespaceText: Bool {6 return wmf_hasText && !self.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty7 }8 public var wmf_hasAlphanumericText: Bool {9 return wmf_hasText && (self.components(separatedBy: .alphanumerics).count > 1)10 }11}12extension NSAttributedString {13 public var wmf_hasText: Bool {14 return string.wmf_hasText15 }16 public var wmf_hasNonWhitespaceText: Bool {17 return string.wmf_hasNonWhitespaceText18 }19}20extension UILabel {21 public var wmf_hasText: Bool {22 guard let text = text else {23 return false24 }25 return text.wmf_hasText26 }27 @objc public var wmf_hasNonWhitespaceText: Bool {28 guard let text = text else {29 return false30 }31 return text.wmf_hasNonWhitespaceText32 }33 public var wmf_hasAttributedText: Bool {34 guard let attributedText = attributedText else {35 return false36 }37 return attributedText.wmf_hasText38 }39 public var wmf_hasNonWhitespaceAttributedText: Bool {40 guard let attributedText = attributedText else {41 return false42 }43 return attributedText.wmf_hasNonWhitespaceText44 }45 46 public var wmf_hasAnyText: Bool {47 return wmf_hasText || wmf_hasAttributedText48 }49 50 public var wmf_hasAnyNonWhitespaceText: Bool {51 return wmf_hasNonWhitespaceText || wmf_hasNonWhitespaceAttributedText52 }53}54extension UITextView {55 public var wmf_hasAnyNonWhitespaceText: Bool {56 return text?.wmf_hasNonWhitespaceText ?? false || attributedText?.wmf_hasNonWhitespaceText ?? false57 }58}59extension UIButton {60 public var wmf_hasText: Bool {61 guard let label = titleLabel else {62 return false63 }64 return label.wmf_hasText65 }66 67 public var wmf_hasNonWhitespaceText: Bool {68 guard let label = titleLabel else {69 return false70 }71 return label.wmf_hasNonWhitespaceText72 }73 74 public var wmf_hasAttributedText: Bool {75 guard let label = titleLabel else {76 return false77 }78 return label.wmf_hasText79 }80 81 public var wmf_hasNonWhitespaceAttributedText: Bool {82 guard let label = titleLabel else {83 return false84 }85 return label.wmf_hasNonWhitespaceText86 }87 88 public var wmf_hasAnyText: Bool {89 return wmf_hasText || wmf_hasAttributedText90 }91 92 public var wmf_hasAnyNonWhitespaceText: Bool {93 return wmf_hasNonWhitespaceText || wmf_hasNonWhitespaceAttributedText94 }95}96extension UITextField {97 public var wmf_hasText: Bool {98 guard let text = text else {99 return false100 }101 return text.wmf_hasText102 }103 104 public var wmf_hasNonWhitespaceText: Bool {105 guard let text = text else {106 return false107 }108 return text.wmf_hasNonWhitespaceText109 }110 111 public var wmf_hasAttributedText: Bool {112 guard let attributedText = attributedText else {113 return false114 }115 return attributedText.wmf_hasText116 }117 118 public var wmf_hasNonWhitespaceAttributedText: Bool {119 guard let attributedText = attributedText else {120 return false121 }122 return attributedText.wmf_hasNonWhitespaceText123 }124 125 public var wmf_hasAnyText: Bool {126 return wmf_hasText || wmf_hasAttributedText127 }128 129 public var wmf_hasAnyNonWhitespaceText: Bool {130 return wmf_hasNonWhitespaceText || wmf_hasNonWhitespaceAttributedText131 }132}...
AudioDevice.swift
Source:AudioDevice.swift
...12 let objectID: ObjectID13 14 var canMute: Bool {15 16 hasProperty(.mute) && isPropertySettable(.mute)17 }18 19 var muted: Bool {20 21 get {22 23 try! get(from: .mute).boolValue24 }25 26 nonmutating set(mute) {27 28 try! set(AudioObjectPropertyValue(mute), to: .mute)29 }30 }31 32 var hasName: Bool {33 34 hasProperty(.name)35 }36 37 var name: String {38 39 try! get(from: .name).stringValue40 }41 42 var hasModelName: Bool {43 44 hasProperty(.modelName)45 }46 47 var modelName: String {48 49 try! get(from: .modelName).stringValue50 }51 52 var hasManufacturer: Bool {53 54 hasProperty(.manufacturer)55 }56 57 var manufacturer: String {58 59 try! get(from: .manufacturer).stringValue60 }61 62 var hasElementName: Bool {63 64 hasProperty(.elementName)65 }66 67 var elementName: String {68 69 try! get(from: .elementName).stringValue70 }71 72 var hasCategoryName: Bool {73 74 hasProperty(.categoryName)75 }76 77 var categoryName: String {78 79 try! get(from: .elementName).stringValue80 }81 82 var hasNumberName: Bool {83 84 hasProperty(.numberName)85 }86 87 var numberName: String {88 89 try! get(from: .elementName).stringValue90 }91 92 var hasIdentify: Bool {93 94 hasProperty(.identify)95 }96 97 var identify: UInt32 {98 99 try! get(from: .identify).number100 }101 102 var hasSerialNumber: Bool {103 104 hasProperty(.serialNumber)105 }106 107 var serialNumber: String {108 109 try! get(from: .serialNumber).stringValue110 }111 112 var hasFirmwareVersion: Bool {113 114 hasProperty(.firmwareVersion)115 }116 117 var firmwareVersion: String {118 119 try! get(from: .firmwareVersion).stringValue120 }121}122extension AudioDevice {123 124 func hasProperty(_ property: AudioDeviceProperty) -> Bool {125 AudioObjectController.propertyExists(property, on: objectID)126 }127 128 func hasProperty(_ property: AudioObjectProperty) -> Bool {129 AudioObjectController.propertyExists(property, on: objectID)130 }131 132 func isPropertySettable(_ property: AudioDeviceProperty) -> Bool {133 134 do {135 return try AudioObjectController.propertySettable(property, on: objectID)136 }137 catch {138 139 return false140 }141 }142 ...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.
Test now for FreeGet 100 minutes of automation test minutes FREE!!