Browse Source

Fix typos and marks, as requested.

Jon Shier 8 năm trước cách đây
mục cha
commit
8099f506cf
2 tập tin đã thay đổi với 18 bổ sung8 xóa
  1. 2 2
      Source/Result.swift
  2. 16 6
      Tests/ResultTests.swift

+ 2 - 2
Source/Result.swift

@@ -246,7 +246,7 @@ extension Result {
         }
     }
     
-    /// Evaluates the specified closure when the `Result` is a success, passing the unwrapped value as a paramter.
+    /// Evaluates the specified closure when the `Result` is a success, passing the unwrapped value as a parameter.
     ///
     /// Use the `withValue` function to evaluate the passed closure without modifying the `Result` instance.
     ///
@@ -259,7 +259,7 @@ extension Result {
         return self
     }
     
-    /// Evaluates the specified closure when the `Result` is a failure, passing the unwrapped error as a paramter.
+    /// Evaluates the specified closure when the `Result` is a failure, passing the unwrapped error as a parameter.
     ///
     /// Use the `withError` function to evaluate the passed closure without modifying the `Result` instance.
     ///

+ 16 - 6
Tests/ResultTests.swift

@@ -281,7 +281,7 @@ class ResultTestCase: BaseTestCase {
         }
     }
     
-    // MARK: - map/flatMapError Tests
+    // MARK: - Error Mapping Tests
     
     func testMapErrorTransformsErrorValue() {
         // Given
@@ -342,6 +342,7 @@ class ResultTestCase: BaseTestCase {
         
         // When
         let mappedResult = result.flatMapError { try OtherError(error: $0) }
+        
         // Then
         if let error = mappedResult.error {
             XCTAssertTrue(error is ThrownError)
@@ -350,7 +351,7 @@ class ResultTestCase: BaseTestCase {
         }
     }
     
-    // MARK: with/if Tests
+    // MARK: - With Value or Error Tests
     
     func testWithValueExecutesWhenSuccess() {
         // Given
@@ -387,7 +388,11 @@ class ResultTestCase: BaseTestCase {
         result.withError { string = "\(type(of: $0))" }
         
         // Then
+        #if swift(>=3.2)
+        XCTAssertEqual(string, "ResultError #1")
+        #else
         XCTAssertEqual(string, "(ResultError #1)")
+        #endif
     }
     
     func testWithErrorDoesNotExecuteWhenSuccess() {
@@ -402,6 +407,8 @@ class ResultTestCase: BaseTestCase {
         XCTAssertEqual(string, "success")
     }
     
+    // MARK: - If Success or Failure Tests
+    
     func testIfSuccessExecutesWhenSuccess() {
         // Given
         let result: Result<String> = .success("success")
@@ -452,6 +459,8 @@ class ResultTestCase: BaseTestCase {
         XCTAssertEqual(string, "success")
     }
     
+    // MARK: - Functional Chaining Tests
+    
     func testFunctionalMethodsCanBeChained() {
         // Given
         struct ResultError: Error {}
@@ -460,10 +469,11 @@ class ResultTestCase: BaseTestCase {
         var success = false
         
         // When
-        let endResult = result.map { _ in "second" }
-                              .flatMap { _ in "third" }
-                              .withValue { if $0 == "third" { string = "fourth" } }
-                              .ifSuccess { success = true }
+        let endResult = result
+            .map { _ in "second" }
+            .flatMap { _ in "third" }
+            .withValue { if $0 == "third" { string = "fourth" } }
+            .ifSuccess { success = true }
         
         // Then
         XCTAssertEqual(endResult.value, "third")