<commit_before>//
//  MappingTestCase.swift
//  DTModelStorage
//
//  Created by <NAME> on 27.11.15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import XCTest
import UIKit
import DTModelStorage
import Nimble

protocol MappingTestProtocol {}

class ProtocolTestableTableViewCell : UITableViewCell, ModelTransfer {
    var model : MappingTestProtocol?
    
    func updateWithModel(_ model: MappingTestProtocol) {
        self.model = model
    }
}

class ConformingClass : MappingTestProtocol {
    
}

class AncestorClass {}
class Subclass : AncestorClass {}

class SubclassTestableTableViewCell : UITableViewCell, ModelTransfer {
    func updateWithModel(_ model: AncestorClass) {
        
    }
}

class MappingTestCase: XCTestCase {
    
    var mappings : [ViewModelMapping]!
    
    override func setUp() {
        super.setUp()
        mappings = []
    }
    
    func testProtocolModelIsFindable() {
        mappings.addMappingForViewType(.cell, viewClass: ProtocolTestableTableViewCell.self)
        
        let candidates = mappings.mappingCandidatesForViewType(.cell, model: ConformingClass())
        
        expect(candidates.count) == 1
        expect(candidates.first?.viewClass == ProtocolTestableTableViewCell.self).to(beTrue())
    }
    
    func testOptionalModelOfProtocolIsFindable() {
        mappings.addMappingForViewType(.cell, viewClass: ProtocolTestableTableViewCell.self)
        let optional: ConformingClass? = ConformingClass()
        let candidates = mappings.mappingCandidatesForViewType(.cell, model: optional)
        expect(candidates.count) == 1
        expect(candidates.first?.viewClass == ProtocolTestableTableViewCell.self).to(beTrue())
    }
    
    func testSubclassModelMappingIsFindable() {
        mappings.addMappingForViewType(.cell, viewClass: SubclassTestableTableViewCell.self)
        let candidates = mappings.mappingCandidatesForViewType(.cell, model: Subclass())
        
        expect(candidates.count) == 1
        expect(candidates.first?.viewClass == SubclassTestableTableViewCell.self).to(beTrue())
    }
    
    func testNilModelDoesNotReturnMappingCandidates() {
        mappings.addMappingForViewType(.cell, viewClass: SubclassTestableTableViewCell.self)
        let model : AncestorClass? = nil
        let candidates = mappings.mappingCandidatesForViewType(.cell, model: model)
        
        expect(candidates.count) == 0
    }
    
    func testUpdateBlockCanBeSuccessfullyCalled() {
        mappings.addMappingForViewType(.cell, viewClass: ProtocolTestableTableViewCell.self)
        
        let candidates = mappings.mappingCandidatesForViewType(.cell, model: ConformingClass())
        
        expect(candidates.count) == 1
        expect(candidates.first?.viewClass == ProtocolTestableTableViewCell.self).to(beTrue())
        
        let cell = ProtocolTestableTableViewCell()
        candidates.first?.updateBlock(cell, ConformingClass())
        
        expect(cell.model is ConformingClass).to(beTrue())
    }
}

struct Transferable : ModelTransfer {
    func updateWithModel(_ model: Int) {}
}

class ViewModelMappingTestCase: XCTestCase {
    
    func testComparisons() {
        let type = ViewType.cell
        
        expect(type.supplementaryKind()).to(beNil())
        expect(ViewType.supplementaryView(kind: "foo")) == ViewType.supplementaryView(kind: "foo")
    }
    
    func testSupplementaryKindEnum()
    {
        let type = ViewType.supplementaryView(kind: "foo")
        
        expect(type.supplementaryKind()) == "foo"
    }
    
    func testComparisonsOfDifferentViewTypes()
    {
        let cellType = ViewType.cell
        let supplementaryType = ViewType.supplementaryView(kind: "foo")
        
        expect(cellType == supplementaryType).to(beFalse())
    }
    
    func testAddingMappingNotForClassDoesNotWork() {
        var mappings = [ViewModelMapping]()
        mappings.addMappingForViewType(.cell, viewClass: Transferable.self)
        
        expect(mappings.count) == 0
    }
    
}<commit_msg>fix test, that was failing because ModelTransfer change<commit_after>//
//  MappingTestCase.swift
//  DTModelStorage
//
//  Created by <NAME> on 27.11.15.
//  Copyright © 2015 <NAME>zhkin. All rights reserved.
//

import XCTest
import UIKit
import DTModelStorage
import Nimble

protocol MappingTestProtocol {}

class ProtocolTestableTableViewCell : UITableViewCell, ModelTransfer {
    var model : MappingTestProtocol?
    
    func updateWithModel(_ model: MappingTestProtocol) {
        self.model = model
    }
}

class ConformingClass : MappingTestProtocol {
    
}

class AncestorClass {}
class Subclass : AncestorClass {}

class SubclassTestableTableViewCell : UITableViewCell, ModelTransfer {
    func updateWithModel(_ model: AncestorClass) {
        
    }
}

class MappingTestCase: XCTestCase {
    
    var mappings : [ViewModelMapping]!
    
    override func setUp() {
        super.setUp()
        mappings = []
    }
    
    func testProtocolModelIsFindable() {
        mappings.addMappingForViewType(.cell, viewClass: ProtocolTestableTableViewCell.self)
        
        let candidates = mappings.mappingCandidatesForViewType(.cell, model: ConformingClass())
        
        expect(candidates.count) == 1
        expect(candidates.first?.viewClass == ProtocolTestableTableViewCell.self).to(beTrue())
    }
    
    func testOptionalModelOfProtocolIsFindable() {
        mappings.addMappingForViewType(.cell, viewClass: ProtocolTestableTableViewCell.self)
        let optional: ConformingClass? = ConformingClass()
        let candidates = mappings.mappingCandidatesForViewType(.cell, model: optional)
        expect(candidates.count) == 1
        expect(candidates.first?.viewClass == ProtocolTestableTableViewCell.self).to(beTrue())
    }
    
    func testSubclassModelMappingIsFindable() {
        mappings.addMappingForViewType(.cell, viewClass: SubclassTestableTableViewCell.self)
        let candidates = mappings.mappingCandidatesForViewType(.cell, model: Subclass())
        
        expect(candidates.count) == 1
        expect(candidates.first?.viewClass == SubclassTestableTableViewCell.self).to(beTrue())
    }
    
    func testNilModelDoesNotReturnMappingCandidates() {
        mappings.addMappingForViewType(.cell, viewClass: SubclassTestableTableViewCell.self)
        let model : AncestorClass? = nil
        let candidates = mappings.mappingCandidatesForViewType(.cell, model: model)
        
        expect(candidates.count) == 0
    }
    
    func testUpdateBlockCanBeSuccessfullyCalled() {
        mappings.addMappingForViewType(.cell, viewClass: ProtocolTestableTableViewCell.self)
        
        let candidates = mappings.mappingCandidatesForViewType(.cell, model: ConformingClass())
        
        expect(candidates.count) == 1
        expect(candidates.first?.viewClass == ProtocolTestableTableViewCell.self).to(beTrue())
        
        let cell = ProtocolTestableTableViewCell()
        candidates.first?.updateBlock(cell, ConformingClass())
        
        expect(cell.model is ConformingClass).to(beTrue())
    }
}

class Transferable : ModelTransfer {
    func updateWithModel(_ model: Int) {}
}

class ViewModelMappingTestCase: XCTestCase {
    
    func testComparisons() {
        let type = ViewType.cell
        
        expect(type.supplementaryKind()).to(beNil())
        expect(ViewType.supplementaryView(kind: "foo")) == ViewType.supplementaryView(kind: "foo")
    }
    
    func testSupplementaryKindEnum()
    {
        let type = ViewType.supplementaryView(kind: "foo")
        
        expect(type.supplementaryKind()) == "foo"
    }
    
    func testComparisonsOfDifferentViewTypes()
    {
        let cellType = ViewType.cell
        let supplementaryType = ViewType.supplementaryView(kind: "foo")
        
        expect(cellType == supplementaryType).to(beFalse())
    }
    
}
{'fraction_non_alphanumeric': 0.09461001902346226, 'fraction_numerical': 0.00393151553582752, 'mean_word_length': 3.115866388308977, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6697952', 'n_tokens_mistral': 2309, 'n_tokens_neox': 2168, 'n_words': 393}