<commit_before>import Foundation
import Quick
import Nimble
@testable import KeyedMapper

fileprivate enum NilConvertibleEnum: NilConvertible {
    case nothing
    case something
    
    fileprivate static func fromMap(_ value: Any?) throws -> NilConvertibleEnum {
        return value.map { _ in .something } ?? .nothing
    }
}

extension NilConvertibleEnum: Equatable {}

fileprivate func == (lhs: NilConvertibleEnum, rhs: NilConvertibleEnum) -> Bool {
    switch lhs {
        case .nothing:
            switch rhs {
                case .nothing: return true
                case .something: return false
            }
        case .something:
            switch rhs {
                case .nothing: return false
                case .something: return true
            }
    }
}

fileprivate struct Model: Mappable {
    fileprivate enum Key: String, JSONKey {
        case enumProperty
    }
    
    fileprivate let enumProperty: NilConvertibleEnum
    
    fileprivate init(map: KeyedMapper<Model>) throws {
        try self.enumProperty = map.from(.enumProperty)
    }
}

class KeyedMapperNilConvertibleSpec: QuickSpec {
    override func spec() {
        describe("KeyedMapper+NilConvertible") {
            describe("from<T: NilConvertible>") {
                context("when the given JSON does not contain the value") {
                    it("should map correctly to the nothing case") {
                        let JSON: NSDictionary = [:]
                        let model = try! Model.from(JSON: JSON)
                        
                        expect(model.enumProperty) == NilConvertibleEnum.nothing
                    }
                }
                
                context("when the given JSON does contain the value") {
                    it("should map correctly to the something case") {
                        let JSON: NSDictionary = ["enumProperty": ""]
                        let model = try! Model.from(JSON: JSON)
                        
                        expect(model.enumProperty) == NilConvertibleEnum.something
                    }
                }
            }
        }
    }
}<commit_msg>Added an underscore to the NilConvertible spec name as it looks better.<commit_after>import Foundation
import Quick
import Nimble
@testable import KeyedMapper

fileprivate enum NilConvertibleEnum: NilConvertible {
    case nothing
    case something
    
    fileprivate static func fromMap(_ value: Any?) throws -> NilConvertibleEnum {
        return value.map { _ in .something } ?? .nothing
    }
}

extension NilConvertibleEnum: Equatable {}

fileprivate func == (lhs: NilConvertibleEnum, rhs: NilConvertibleEnum) -> Bool {
    switch lhs {
        case .nothing:
            switch rhs {
                case .nothing: return true
                case .something: return false
            }
        case .something:
            switch rhs {
                case .nothing: return false
                case .something: return true
            }
    }
}

fileprivate struct Model: Mappable {
    fileprivate enum Key: String, JSONKey {
        case enumProperty
    }
    
    fileprivate let enumProperty: NilConvertibleEnum
    
    fileprivate init(map: KeyedMapper<Model>) throws {
        try self.enumProperty = map.from(.enumProperty)
    }
}

class KeyedMapper_NilConvertibleSpec: QuickSpec {
    override func spec() {
        describe("KeyedMapper+NilConvertible") {
            describe("from<T: NilConvertible>") {
                context("when the given JSON does not contain the value") {
                    it("should map correctly to the nothing case") {
                        let JSON: NSDictionary = [:]
                        let model = try! Model.from(JSON: JSON)
                        
                        expect(model.enumProperty) == NilConvertibleEnum.nothing
                    }
                }
                
                context("when the given JSON does contain the value") {
                    it("should map correctly to the something case") {
                        let JSON: NSDictionary = ["enumProperty": ""]
                        let model = try! Model.from(JSON: JSON)
                        
                        expect(model.enumProperty) == NilConvertibleEnum.something
                    }
                }
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.07357322942929177, 'fraction_numerical': 0.0, 'mean_word_length': 1.5837773830669035, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 11, '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': '6438395', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1012, 'n_words': 309}