<commit_before>import Quick
import Nimble

import Faro
@testable import Faro_Example

class DeserializableObject: Deserializable {
    var uuid: String?
    var amount: Int?
    var price: Double?
    var tapped: Bool?
    var date: Date?
    
    required init?(from raw: Any) {
        map(from: raw)
    }
    
    var mappers: [String : ((Any?) -> ())]? {
        get {
            return [
                "uuid": {self.uuid <-> $0},
                "amount": {self.amount <-> $0},
                "price": {self.price <-> $0},
                "tapped": {self.tapped <-> $0},
                "date": {self.date <-> $0}
            ]
        }
    }

}

class DeserializeOperatorsSpec: QuickSpec {

    override func spec() {
        describe("DeserializeOperatorsSpec") {

            context("should give value for") {
                it("should work for relations") {
                    let relationId = ["relation 1", "relation 2"]
                    let animalArray =  [["uuid": relationId[0]], ["uuid": relationId[1]]]

                    let json = ["animalArray": animalArray] as Any?

                    var zoo = Zoo(from: ["":""])

                    zoo <-> json

                    expect(zoo?.animalArray?.count) == 2
                }
                
                it("should deserialize to object") {
                    let randomNumber = "randomNumber"
                    let json = ["cellNumber": randomNumber, "foodTicket": "ticket"] as Any?
                    
                    var gail = Gail(from: ["":""])
                    
                    gail <-> json
                    
                    expect(gail?.cellNumber) == randomNumber
                    
                }
                
                it("should deserialize to object Array") {
                    let json = [["uuid": "id1"],["uuid": "id2"]] as Any?
                    var animalArray: [Animal]?
                    
                    animalArray <-> json
                    
                    expect(animalArray?.count) == 2
                }
                
                it("should deserialize Integers") {
                    let o1 = DeserializableObject(from: ["": ""])
                    let anyInt = 10 as Any?
                    
                    o1?.amount <-> anyInt
                    
                    expect(o1?.amount) == anyInt as! Int?
                }
                
                it("should deserialize Doubles") {
                    let o1 = DeserializableObject(from: ["":""])
                    let anyDouble = 5.0 as Any?
                    
                    o1?.price <-> anyDouble
                    
                    expect(o1?.price) == anyDouble as! Double?
                }
                
                it("should deserialize Booleans") {
                    let o1 = DeserializableObject(from: ["":""])
                    let anyBool = true as Any?
                    
                    o1?.tapped <-> anyBool
                    
                    expect(o1?.tapped) == anyBool as! Bool?
                }
                
                it("should deserialize Strings") {
                    let o1 = DeserializableObject(from: ["":""])
                    let anyString = "randomID" as Any?
                    
                    o1?.uuid <-> anyString
                    
                    expect(o1?.uuid) == anyString as! String?
                }
                
                it("should deserialize Date with TimeInterval") {
                    let o1 = DeserializableObject(from: ["":""])
                    let anyTimeInterval = 1234.0 as Any?
                    
                    o1?.date <-> anyTimeInterval
                    
                    let date = Date(timeIntervalSince1970: anyTimeInterval as! TimeInterval)
                    expect(o1?.date) == date
                }
                
                it("should deserialize Date with String") {
                    let o1 = DeserializableObject(from: ["":""])
                    let anyTimeString = "20-08-1994" as Any?
                    
                    o1?.date <-> anyTimeString
                    
                    let formatter = DateFormatter()
                    let date = formatter.date(from: anyTimeString as! String)
                    
                    expect(o1?.date) == date
                    
                }
            }
        }
    }
    
}<commit_msg>FARO-26 Successful test with deserialize operator <-> where lhs = Date and rhs = String<commit_after>import Quick
import Nimble

import Faro
@testable import Faro_Example

class DeserializableObject: Deserializable {
    var uuid: String?
    var amount: Int?
    var price: Double?
    var tapped: Bool?
    var date: Date?
    
    required init?(from raw: Any) {
        map(from: raw)
    }
    
    var mappers: [String : ((Any?) -> ())]? {
        get {
            return [
                "uuid": {self.uuid <-> $0},
                "amount": {self.amount <-> $0},
                "price": {self.price <-> $0},
                "tapped": {self.tapped <-> $0},
                "date": {self.date <-> ($0, "yyyy-MM-dd")}
            ]
        }
    }

}

class DeserializeOperatorsSpec: QuickSpec {

    override func spec() {
        describe("DeserializeOperatorsSpec") {

            context("should give value for") {
                it("should work for relations") {
                    let relationId = ["relation 1", "relation 2"]
                    let animalArray =  [["uuid": relationId[0]], ["uuid": relationId[1]]]

                    let json = ["animalArray": animalArray] as Any?

                    var zoo = Zoo(from: ["":""])

                    zoo <-> json

                    expect(zoo?.animalArray?.count) == 2
                }
                
                it("should deserialize to object") {
                    let randomNumber = "randomNumber"
                    let json = ["cellNumber": randomNumber, "foodTicket": "ticket"] as Any?
                    
                    var gail = Gail(from: ["":""])
                    
                    gail <-> json
                    
                    expect(gail?.cellNumber) == randomNumber
                    
                }
                
                it("should deserialize to object Array") {
                    let json = [["uuid": "id1"],["uuid": "id2"]] as Any?
                    var animalArray: [Animal]?
                    
                    animalArray <-> json
                    
                    expect(animalArray?.count) == 2
                }
                
                it("should deserialize Integers") {
                    let o1 = DeserializableObject(from: ["": ""])
                    let anyInt = 10 as Any?
                    
                    o1?.amount <-> anyInt
                    
                    expect(o1?.amount) == anyInt as! Int?
                }
                
                it("should deserialize Doubles") {
                    let o1 = DeserializableObject(from: ["":""])
                    let anyDouble = 5.0 as Any?
                    
                    o1?.price <-> anyDouble
                    
                    expect(o1?.price) == anyDouble as! Double?
                }
                
                it("should deserialize Booleans") {
                    let o1 = DeserializableObject(from: ["":""])
                    let anyBool = true as Any?
                    
                    o1?.tapped <-> anyBool
                    
                    expect(o1?.tapped) == anyBool as! Bool?
                }
                
                it("should deserialize Strings") {
                    let o1 = DeserializableObject(from: ["":""])
                    let anyString = "randomID" as Any?
                    
                    o1?.uuid <-> anyString
                    
                    expect(o1?.uuid) == anyString as! String?
                }
                
                it("should deserialize Date with String") {
                    let o1 = DeserializableObject(from: ["":""])
                    let timeString = "1994-08-20" as String?
                    
                    /// Don't forget to set the date format by calling setDateFormat(_format: String)
                    setDateFormat("yyyy-MM-dd")
                    
                    o1?.date <-> timeString
                    
                    let formatter = DateFormatter()
                    formatter.dateFormat = "yyyy-MM-dd"
                    let currentDate = formatter.date(from: timeString!)
                    
                    expect(o1?.date).toNot(beNil())
                    expect(o1?.date) == currentDate
                    
                }
                
                it("should deserialize Date with TimeInterval") {
                    let o1 = DeserializableObject(from: ["":""])
                    let anyTimeInterval = 1234.0 as Any?
                    
                    o1?.date <-> anyTimeInterval
                    
                    let date = Date(timeIntervalSince1970: anyTimeInterval as! TimeInterval)
                    expect(o1?.date) == date
                }
                
                it("should deserialize Date with String") {
                    let o1 = DeserializableObject(from: ["":""])
                    let anyTimeString = "20-08-1994" as Any?
                    
                    o1?.date <-> anyTimeString
                    
                    let formatter = DateFormatter()
                    let date = formatter.date(from: anyTimeString as! String)
                    
                    expect(o1?.date) == date
                    
                }
            }
        }
    }
    
}
{'fraction_non_alphanumeric': 0.10383289393632124, 'fraction_numerical': 0.011965118637193267, 'mean_word_length': 0.950751582278481, 'pattern_counts': {'":': 41, '<': 33, '<?xml version=': 0, '>': 35, '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': '3390286', 'n_tokens_mistral': 2523, 'n_tokens_neox': 2257, 'n_words': 555}