Skip to content

Commit

Permalink
post talk update
Browse files Browse the repository at this point in the history
  • Loading branch information
ytyubox committed Feb 23, 2021
1 parent 65f5832 commit 5e5648a
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand Down
9 changes: 9 additions & 0 deletions Tests/PropertyWrapperTests/LoggingExcludedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ import XCTest
class Object {
@LoggingExcluded
var i = 0
/**
// uncomment to see compile failure
@LoggingExcluded
weak var i2: NSObject?
@LoggingExcluded
unowned var i3: NSObject?
@LoggingExcluded
lazy var i4: NSObject?
*/
}

class LogExcludeTests: XCTestCase {
Expand Down
9 changes: 0 additions & 9 deletions Tests/PropertyWrapperTests/NestedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ final class NestedTests: XCTestCase {

import SwiftUI

struct Nested {
@State
@LoggingExcluded
var nest1 = 0

@LoggingExcluded
@State
var nest2 = 0
}

struct OrderDifferent {
@LoggingExcluding
Expand Down
66 changes: 66 additions & 0 deletions Tests/PropertyWrapperTests/PropertyObserverTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
/*
* Created by 游宗諭 in 2021/2/23
*
* Using Swift 5.0
*
* Running on macOS 11.2
*/


import XCTest
@propertyWrapper struct Wrapper {
var wrappedValue: Int
var anotherValue = 0
}
class ProperyObserverTests: XCTestCase {
@Wrapper var i = 0 {
willSet {
captured.append(.willSet(newValue))
}
didSet {
captured.append(.didSet(i))
}
}
var captured = [Setting]()
func test() {
XCTAssertTrue(captured.isEmpty)
_i.anotherValue = 1
XCTAssertEqual(captured, [])
_i.wrappedValue = 1
XCTAssertEqual(captured, [])
i = 1
XCTAssertEqual(captured, [.willSet(1), .didSet(1)])
}
func testInStruct() {
var owner = Owner()
owner._addAnother()
XCTAssertEqual(owner.captured, [])
owner._addWrapped()
XCTAssertEqual(owner.captured, [])
owner.i = 1
XCTAssertEqual(owner.captured, [.willSet(1), .didSet(1)])
}
}

enum Setting:Equatable {
case didSet(Int), willSet(Int)
}
struct Owner {
@Wrapper var i = 0 {
willSet {
captured.append(.willSet(newValue))
}
didSet {
captured.append(.didSet(i))
}
}
var captured = [Setting]()
mutating func _addAnother() {
_i.anotherValue += 1
}
mutating func _addWrapped() {
_i.wrappedValue += 1
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class BarrierTests: XCTestCase {
@Atomic var lockSingleValue = 0
func testLockValue() {
randomQueueAsync { _ in
self.lockSingleValue += 1
let value = self.lockSingleValue
self.lockSingleValue = 1 + value
}
XCTAssertEqual(lockSingleValue, expect)
}
Expand Down
1 change: 1 addition & 0 deletions Tests/PropertyWrapperTests/ThreadSafe/Lock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class ThreadSaveTests: XCTestCase {
}
wait(for: [await], timeout: 1)
XCTAssertEqual(lockDicWithArray.count, total)
XCTAssertTrue(lockDicWithArray.values.allSatisfy{$0.count == total})
}

// MARK: - help
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
/*
* Created by 游宗諭 in 2021/2/23
*
* Using Swift 5.0
*
* Running on macOS 11.2
*/


import XCTest
@propertyWrapper struct GetOnly {
var wrappedValue: Int {0}
}
class WrappedValueGetOnlyOwnerWillSetTests: XCTestCase {
@GetOnly var i
@GetOnly var i2 {
willSet {}
}
@GetOnly var i3 {
didSet {}
}
@GetOnly var i4 {
willSet {}
didSet {}
}

/**
//uncomment to see
func test() {
i = 1
i2 = 2
i3 = 3
i4 = 4
}
*/
}

0 comments on commit 5e5648a

Please sign in to comment.