<commit_before>@testable import Swish
import Argo
import Quick
import Nimble
import Result

struct User: Decodable {
  let name: String
  
  static func decode(json: JSON) -> Decoded<User> {
    return User.init <^> json <| "name"
  }
}

struct DecodableRequest: Request {
  typealias ResponseType = User
  
  func build() -> NSURLRequest {
    return NSURLRequest()
  }
}

struct DecodableCollectionRequest: Request {
  typealias ResponseType = [User]
  
  func build() -> NSURLRequest {
    return NSURLRequest()
  }
}

class RequestSpec: QuickSpec {
  override func spec() {
    describe("Request") {
      describe("default parse implementation") {
        context("when the ResponseType is decodable") {
          let request = DecodableRequest()
          let json = JSON.parse(["name": "gvg"])
          let result = request.parse(json)
          
          expect(result.value?.name).to(equal("gvg"))
        }
        
        context("when the ResponseType is a collection type of decodable objects") {
          let request = DecodableCollectionRequest()
          let json = JSON.parse([
            ["name": "giles"],
            ["name": "gordon"]
          ])
          let result = request.parse(json)
          
          expect(result.value?.count).to(equal(2))
          expect(result.value?.first?.name).to(equal("giles"))
        }
      }
    }
  }
}<commit_msg>Add spec for Void ResponseType.<commit_after>@testable import Swish
import Argo
import Quick
import Nimble
import Result

struct User: Decodable {
  let name: String
  
  static func decode(json: JSON) -> Decoded<User> {
    return User.init <^> json <| "name"
  }
}

struct DecodableRequest: Request {
  typealias ResponseType = User
  
  func build() -> NSURLRequest {
    return NSURLRequest()
  }
}

struct DecodableCollectionRequest: Request {
  typealias ResponseType = [User]
  
  func build() -> NSURLRequest {
    return NSURLRequest()
  }
}

struct VoidResponseRequest: Request {
  typealias ResponseType = Void
  
  func build() -> NSURLRequest {
    return NSURLRequest()
  }
}

class RequestSpec: QuickSpec {
  override func spec() {
    describe("Request") {
      describe("default parse implementation") {
        context("when the ResponseType is decodable") {
          let request = DecodableRequest()
          let json = JSON.parse(["name": "gvg"])
          let result = request.parse(json)
          
          expect(result.value?.name).to(equal("gvg"))
        }
        
        context("when the ResponseType is a collection type of decodable objects") {
          let request = DecodableCollectionRequest()
          let json = JSON.parse([
            ["name": "giles"],
            ["name": "gordon"]
          ])
          let result = request.parse(json)
          
          expect(result.value?.count).to(equal(2))
          expect(result.value?.first?.name).to(equal("giles"))
        }
        
        context("when the ResponseType is Void") {
          it("should have a nil Result value") {
            let request = VoidResponseRequest()
            let json = JSON.parse([])
            let result = request.parse(json)
            
            switch result {
            case .Success:
              XCTAssert(true)
            default:
              XCTFail("Unexpected Failure")
            }            
          }
        }
      }
    }
  }
}
{'fraction_non_alphanumeric': 0.11167061611374407, 'fraction_numerical': 0.0005924170616113745, 'mean_word_length': 2.1384758364312266, 'pattern_counts': {'":': 6, '<': 9, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7293486', 'n_tokens_mistral': 953, 'n_tokens_neox': 941, 'n_words': 241}