AtomicSpec.swift 854 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // AtomicSpec.swift
  3. // ReactiveCocoa
  4. //
  5. // Created by Justin Spahr-Summers on 2014-07-13.
  6. // Copyright (c) 2014 GitHub. All rights reserved.
  7. //
  8. import Nimble
  9. import Quick
  10. import ReactiveCocoa
  11. class AtomicSpec: QuickSpec {
  12. override func spec() {
  13. var atomic: Atomic<Int>!
  14. beforeEach {
  15. atomic = Atomic(1)
  16. }
  17. it("should read and write the value directly") {
  18. expect(atomic.value) == 1
  19. atomic.value = 2
  20. expect(atomic.value) == 2
  21. }
  22. it("should swap the value atomically") {
  23. expect(atomic.swap(2)) == 1
  24. expect(atomic.value) == 2
  25. }
  26. it("should modify the value atomically") {
  27. expect(atomic.modify({ $0 + 1 })) == 1
  28. expect(atomic.value) == 2
  29. }
  30. it("should perform an action with the value") {
  31. let result: Bool = atomic.withValue { $0 == 1 }
  32. expect(result) == true
  33. expect(atomic.value) == 1
  34. }
  35. }
  36. }