Merge pull request #24 from diegosanchezr/master

Removes deprecated '++/--'. Fixes linter issues.
This commit is contained in:
Diego Sánchez 2016-01-27 22:57:03 +00:00
commit 2cdbdc9063
40 changed files with 113 additions and 121 deletions

11
.swiftlint.yml Normal file
View File

@ -0,0 +1,11 @@
disabled_rules: # rule identifiers to exclude from running
- file_length
- force_cast
- function_body_length
- line_length
- todo
- type_body_length
- variable_name
- variable_name_min_length
- variable_name_max_length
- type_name

View File

@ -1,11 +0,0 @@
disabled_rules: # rule identifiers to exclude from running
- file_length
- force_cast
- function_body_length
- line_length
- todo
- type_body_length
- variable_name
included: # paths to include during linting. `--path` is ignored if present. takes precendence over `excluded`.
- Source
excluded: # paths to ignore during linting. overridden by `included`.

1
Chatto/.swiftlint.yml Symbolic link
View File

@ -0,0 +1 @@
../.swiftlint.yml

View File

@ -52,7 +52,7 @@ class AccessoryViewRevealer: NSObject, UIGestureRecognizerDelegate {
case .Ended, .Cancelled, .Failed:
self.revealAccessoryView(atOffset: 0)
default:
break;
break
}
}

View File

@ -202,8 +202,7 @@ extension ChatViewController: ChatDataSourceDelegateProtocol {
let newDecoratedItems = self.chatItemsDecorator?.decorateItems(newItems) ?? newItems.map { DecoratedChatItem(chatItem: $0, decorationAttributes: nil) }
let changes = Chatto.generateChanges(
oldCollection: oldItems.map { $0 },
newCollection: newDecoratedItems.map { $0.chatItem }
)
newCollection: newDecoratedItems.map { $0.chatItem })
let layoutModel = self.createLayoutModel(newDecoratedItems, collectionViewWidth: collectionViewWidth)
let updateModelClosure : () -> Void = { [weak self] in
self?.layoutModel = layoutModel
@ -252,7 +251,7 @@ extension ChatViewController: ChatDataSourceDelegateProtocol {
public func chatCollectionViewLayoutModel() -> ChatCollectionViewLayoutModel {
if self.layoutModel.calculatedForWidth != self.collectionView.bounds.width {
self.layoutModel = self.createLayoutModel(self.decoratedChatItems, collectionViewWidth: self.collectionView.bounds.width);
self.layoutModel = self.createLayoutModel(self.decoratedChatItems, collectionViewWidth: self.collectionView.bounds.width)
}
return self.layoutModel

View File

@ -81,7 +81,7 @@ public class ChatViewController: UIViewController, UICollectionViewDataSource, U
}
private func addCollectionView() {
self.collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: self.createCollectionViewLayout)
self.collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: self.createCollectionViewLayout)
self.collectionView.contentInset = self.constants.defaultContentInsets
self.collectionView.scrollIndicatorInsets = self.constants.defaultScrollIndicatorInsets
self.collectionView.alwaysBounceVertical = true
@ -111,7 +111,7 @@ public class ChatViewController: UIViewController, UICollectionViewDataSource, U
private var inputContainerBottomConstraint: NSLayoutConstraint!
private func addInputViews() {
self.inputContainer = UIView(frame: CGRectZero)
self.inputContainer = UIView(frame: CGRect.zero)
self.inputContainer.autoresizingMask = .None
self.inputContainer.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(self.inputContainer)

View File

@ -134,12 +134,12 @@ class KeyboardTracker {
let inputContainerHeight = self.inputContainer.bounds.height
let trackerViewHeight = self.trackingView.bounds.height
if trackerViewHeight != inputContainerHeight {
self.keyboardTrackerView.bounds = CGRect(origin: CGPointZero, size: CGSize(width: self.keyboardTrackerView.bounds.width, height: inputContainerHeight))
self.keyboardTrackerView.bounds = CGRect(origin: CGPoint.zero, size: CGSize(width: self.keyboardTrackerView.bounds.width, height: inputContainerHeight))
}
}
private func layoutInputAtBottom() {
self.keyboardTrackerView.bounds = CGRect(origin: CGPointZero, size: CGSize(width: self.keyboardTrackerView.bounds.width, height: 0))
self.keyboardTrackerView.bounds = CGRect(origin: CGPoint.zero, size: CGSize(width: self.keyboardTrackerView.bounds.width, height: 0))
self.inputContainerBottomConstraint.constant = 0
self.view.layoutIfNeeded()
}
@ -154,7 +154,7 @@ class KeyboardTracker {
private class KeyboardTrackingView: UIView {
var positionChangedCallback: (() -> Void)?;
var positionChangedCallback: (() -> Void)?
var observedView: UIView?
deinit {

View File

@ -26,7 +26,7 @@ import XCTest
@testable import Chatto
class BaseChatItemPresenterTests: XCTestCase {
var presenter: BaseChatItemPresenter<UICollectionViewCell>!
override func setUp() {

View File

@ -59,4 +59,4 @@ private func Atttributes(item item: Int, frame: CGRect) -> UICollectionViewLayou
let attributes = UICollectionViewLayoutAttributes(forCellWithIndexPath: indexPath)
attributes.frame = frame
return attributes
}
}

View File

@ -89,7 +89,7 @@ class FakePresenterBuilder: ChatItemPresenterBuilderProtocol {
}
func createPresenterWithChatItem(chatItem: ChatItemProtocol) -> ChatItemPresenterProtocol {
self.presentersCreatedCount++
self.presentersCreatedCount += 1
return FakePresenter()
}

View File

@ -100,7 +100,7 @@ class ChatViewControllerTests: XCTestCase {
self.fakeDidAppearAndLayout(controller: controller)
controller.updateQueue.addTask { (completion) -> Void in
fakeDataSource.hasMorePrevious = true
controller.collectionView.contentOffset = CGPointZero
controller.collectionView.contentOffset = CGPoint.zero
controller.scrollViewDidScrollToTop(controller.collectionView)
completion()
asyncExpectation.fulfill()
@ -185,7 +185,7 @@ class ChatViewControllerTests: XCTestCase {
notificationCenter.postNotificationName(UIKeyboardWillShowNotification, object: self, userInfo: [UIKeyboardFrameEndUserInfoKey: NSValue(CGRect: CGRect(x: 0, y: 400, width: 400, height: 500))])
XCTAssertEqual(400, controller.view.convertRect(controller.chatInputView.bounds, fromView: controller.chatInputView).maxY)
}
func testThat_LayoutAdaptsWhenKeyboardIsHidden() {
let controller = TesteableChatViewController()
let notificationCenter = NSNotificationCenter()

View File

@ -89,7 +89,7 @@ func Item(uid: String) -> UniqueIdentificable {
return UniqueIdentificableItem(uid: uid)
}
func Move(from: Int, to:Int) -> CollectionChangeMove {
func Move(from: Int, to: Int) -> CollectionChangeMove {
return CollectionChangeMove(indexPathOld: NSIndexPath(forItem: from, inSection: 0), indexPathNew: NSIndexPath(forItem: to, inSection: 0))
}

View File

@ -26,7 +26,7 @@ import XCTest
@testable import Chatto
class SerialTaskQueueTests: XCTestCase {
func testThat_GivenIsFreshlyCreated_WhenNewTaskIsAdded_ThenTaskIsNotExecuted() {
let queue = SerialTaskQueue()
var executed = false

View File

@ -1,11 +0,0 @@
disabled_rules: # rule identifiers to exclude from running
- file_length
- force_cast
- function_body_length
- line_length
- todo
- type_body_length
- variable_name
included: # paths to include during linting. `--path` is ignored if present. takes precendence over `excluded`.
- Source
excluded: # paths to ignore during linting. overridden by `included`.

View File

@ -0,0 +1 @@
../.swiftlint.yml

View File

@ -28,8 +28,8 @@ public extension CABasicAnimation {
animation.duration = duration
animation.fromValue = 0
animation.toValue = 1
animation.fillMode = kCAFillModeForwards;
animation.additive = false;
animation.fillMode = kCAFillModeForwards
animation.additive = false
return animation
}
}

View File

@ -197,13 +197,13 @@ public class BaseMessageCollectionViewCell<BubbleViewType where BubbleViewType:U
// TODO: refactor accessorView?
if let accessoryView = self.accessoryTimestamp {
accessoryView.bounds = CGRect(origin: CGPointZero, size: accessoryView.intrinsicContentSize())
accessoryView.bounds = CGRect(origin: CGPoint.zero, size: accessoryView.intrinsicContentSize())
let accessoryViewWidth = CGRectGetWidth(accessoryView.bounds)
let accessoryViewMargin: CGFloat = 10
let leftDisplacement = max(0, min(self.timestampMaxVisibleOffset, accessoryViewWidth + accessoryViewMargin))
var contentViewframe = self.contentView.frame
if self.messageViewModel.isIncoming {
contentViewframe.origin = CGPointZero
contentViewframe.origin = CGPoint.zero
} else {
contentViewframe.origin.x = -leftDisplacement
}
@ -308,9 +308,9 @@ public class BaseMessageCollectionViewCell<BubbleViewType where BubbleViewType:U
}
struct BaseMessageLayoutModel {
private (set) var size = CGSizeZero
private (set) var failedViewFrame = CGRectZero
private (set) var bubbleViewFrame = CGRectZero
private (set) var size = CGSize.zero
private (set) var failedViewFrame = CGRect.zero
private (set) var bubbleViewFrame = CGRect.zero
private (set) var preferredMaxWidthForBubble: CGFloat = 0
mutating func calculateLayout(parameters parameters: BaseMessageLayoutModelParameters) {
@ -324,7 +324,7 @@ struct BaseMessageLayoutModel {
let preferredWidthForBubble = containerWidth * parameters.maxContainerWidthPercentageForBubbleView
let bubbleSize = bubbleView.sizeThatFits(CGSize(width: preferredWidthForBubble, height: CGFloat.max))
let containerRect = CGRect(origin: CGPointZero, size: CGSize(width: containerWidth, height: bubbleSize.height))
let containerRect = CGRect(origin: CGPoint.zero, size: CGSize(width: containerWidth, height: bubbleSize.height))
self.bubbleViewFrame = bubbleSize.bma_rect(inContainer: containerRect, xAlignament: .Center, yAlignment: .Center, dx: 0, dy: 0)

View File

@ -193,7 +193,7 @@ public final class PhotoBubbleView: UIView, MaximumLayoutWidthSpecificable, Back
let layout = self.calculateTextBubbleLayout(maximumWidth: self.preferredMaxLayoutWidth)
self.progressIndicatorView.center = layout.visualCenter
self.placeholderIconView.center = layout.visualCenter
self.placeholderIconView.bounds = CGRect(origin: CGPointZero, size: self.placeholderIconView.image?.size ?? CGSizeZero)
self.placeholderIconView.bounds = CGRect(origin: CGPoint.zero, size: self.placeholderIconView.image?.size ?? CGSize.zero)
self.imageView.bma_rect = layout.photoFrame
self.imageView.layer.mask?.frame = self.imageView.layer.bounds
self.overlayView.bma_rect = self.imageView.bounds
@ -215,9 +215,9 @@ public final class PhotoBubbleView: UIView, MaximumLayoutWidthSpecificable, Back
private class PhotoBubbleLayoutModel {
var photoFrame: CGRect = CGRectZero
var visualCenter: CGPoint = CGPointZero // Because image is cropped a few points on the side of the tail, the apparent center will be a bit shifted
var size: CGSize = CGSizeZero
var photoFrame: CGRect = CGRect.zero
var visualCenter: CGPoint = CGPoint.zero // Because image is cropped a few points on the side of the tail, the apparent center will be a bit shifted
var size: CGSize = CGSize.zero
struct LayoutContext {
let photoSize: CGSize
@ -244,7 +244,7 @@ private class PhotoBubbleLayoutModel {
func calculateLayout() {
let photoSize = self.layoutContext.photoSize
self.photoFrame = CGRect(origin: CGPointZero, size: photoSize)
self.photoFrame = CGRect(origin: CGPoint.zero, size: photoSize)
let offsetX: CGFloat = 0.5 * self.layoutContext.tailWidth * (self.layoutContext.isIncoming ? 1.0 : -1.0)
self.visualCenter = self.photoFrame.bma_center.bma_offsetBy(dx: offsetX, dy: 0)
self.size = photoSize

View File

@ -29,7 +29,7 @@ public typealias PhotoMessageCollectionViewCellStyleProtocol = PhotoBubbleViewSt
public final class PhotoMessageCollectionViewCell: BaseMessageCollectionViewCell<PhotoBubbleView> {
static func sizingCell() -> PhotoMessageCollectionViewCell {
let cell = PhotoMessageCollectionViewCell(frame: CGRectZero)
let cell = PhotoMessageCollectionViewCell(frame: CGRect.zero)
cell.viewContext = .Sizing
return cell
}

View File

@ -194,9 +194,9 @@ public final class TextBubbleView: UIView, MaximumLayoutWidthSpecificable, Backg
private final class TextBubbleLayoutModel {
let layoutContext: LayoutContext
var textFrame: CGRect = CGRectZero
var bubbleFrame: CGRect = CGRectZero
var size: CGSize = CGSizeZero
var textFrame: CGRect = CGRect.zero
var bubbleFrame: CGRect = CGRect.zero
var size: CGSize = CGSize.zero
init(layoutContext: LayoutContext) {
self.layoutContext = layoutContext
@ -226,7 +226,7 @@ private final class TextBubbleLayoutModel {
let maxTextWidth = self.layoutContext.preferredMaxLayoutWidth - textHorizontalInset
let textSize = self.textSizeThatFitsWidth(maxTextWidth)
let bubbleSize = textSize.bma_outsetBy(dx: textHorizontalInset, dy: self.layoutContext.textInsets.bma_verticalInset)
self.bubbleFrame = CGRect(origin: CGPointZero, size: bubbleSize)
self.bubbleFrame = CGRect(origin: CGPoint.zero, size: bubbleSize)
self.textFrame = UIEdgeInsetsInsetRect(self.bubbleFrame, self.layoutContext.textInsets)
self.size = bubbleSize
}

View File

@ -29,7 +29,7 @@ public typealias TextMessageCollectionViewCellStyleProtocol = TextBubbleViewStyl
public final class TextMessageCollectionViewCell: BaseMessageCollectionViewCell<TextBubbleView> {
public static func sizingCell() -> TextMessageCollectionViewCell {
let cell = TextMessageCollectionViewCell(frame: CGRectZero)
let cell = TextMessageCollectionViewCell(frame: CGRect.zero)
cell.viewContext = .Sizing
return cell
}

View File

@ -50,7 +50,7 @@ public class ChatInputBar: ReusableXibView {
class public func loadNib() -> ChatInputBar {
let view = NSBundle(forClass: self).loadNibNamed(self.nibName(), owner: nil, options: nil).first as! ChatInputBar
view.translatesAutoresizingMaskIntoConstraints = false
view.frame = CGRectZero
view.frame = CGRect.zero
return view
}
@ -212,7 +212,7 @@ class SingleViewContainerView: UIView {
if let subview = self.subviews.first {
return subview.intrinsicContentSize()
} else {
return CGSizeZero
return CGSize.zero
}
}

View File

@ -25,7 +25,7 @@
import UIKit
@objc public class ChatInputBarPresenter: NSObject {
let chatInputView: ChatInputBar;
let chatInputView: ChatInputBar
let chatInputItems: [ChatInputItemProtocol]
public init(chatInputView: ChatInputBar, chatInputItems: [ChatInputItemProtocol]) {

View File

@ -48,7 +48,7 @@ import Foundation
public var selected = false {
didSet {
self.internalTabView.selected = self.selected;
self.internalTabView.selected = self.selected
if self.selected != oldValue {
self.photosInputView.reload()
}

View File

@ -133,7 +133,7 @@ extension PhotosInputView: UICollectionViewDataSource {
func configureCollectionView() {
self.collectionViewLayout = UICollectionViewFlowLayout()
self.collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: self.collectionViewLayout)
self.collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: self.collectionViewLayout)
self.collectionView.backgroundColor = UIColor.whiteColor()
self.collectionView.translatesAutoresizingMaskIntoConstraints = false
self.collectionView.registerClass(LiveCameraCell.self, forCellWithReuseIdentifier: "bar")

View File

@ -27,7 +27,7 @@ struct PhotosInputViewItemSizeCalculator {
var interitemSpace: CGFloat = 0
func itemSizeForWidth(width: CGFloat, atIndex index: Int) -> CGSize {
let availableWidth = width - self.interitemSpace * CGFloat((self.itemsPerRow - 1));
let availableWidth = width - self.interitemSpace * CGFloat((self.itemsPerRow - 1))
if availableWidth <= 0 {
return CGSize.zero
}
@ -37,7 +37,7 @@ struct PhotosInputViewItemSizeCalculator {
let extraPixels = Int(availableWidth) % self.itemsPerRow
let isItemWithExtraPixel = index % self.itemsPerRow < extraPixels
if isItemWithExtraPixel {
itemWidth++
itemWidth += 1
}
return CGSize(width: itemWidth, height: itemHeigth)
}

View File

@ -35,14 +35,14 @@ import UIKit
override public func awakeAfterUsingCoder(aDecoder: NSCoder) -> AnyObject? {
if self.subviews.count > 0 {
return self;
return self
}
let bundle = NSBundle(forClass: self.dynamicType)
if let loadedView = bundle.loadNibNamed(self.dynamicType.nibName(), owner: nil, options: nil).first as! UIView? {
loadedView.frame = frame
loadedView.autoresizingMask = autoresizingMask
loadedView.translatesAutoresizingMaskIntoConstraints = translatesAutoresizingMaskIntoConstraints;
loadedView.translatesAutoresizingMaskIntoConstraints = translatesAutoresizingMaskIntoConstraints
for constraint in constraints {
let firstItem = constraint.firstItem === self ? loadedView : constraint.firstItem
let secondItem = constraint.secondItem === self ? loadedView : constraint.secondItem
@ -55,7 +55,7 @@ import UIKit
}
class func nibName() -> String {
assert(false, "Must be overriden");
assert(false, "Must be overriden")
return ""
}
}

View File

@ -38,7 +38,7 @@ import Foundation
public var selected = false {
didSet {
self.internalTabView.selected = self.selected;
self.internalTabView.selected = self.selected
}
}
}

View File

@ -83,7 +83,7 @@ public extension CGSize {
public extension CGRect {
var bma_bounds: CGRect {
return CGRect(origin: CGPointZero, size: self.size)
return CGRect(origin: CGPoint.zero, size: self.size)
}
var bma_center: CGPoint {
@ -145,7 +145,7 @@ public extension UIEdgeInsets {
public extension UIImage {
public func bma_tintWithColor(color: UIColor) -> UIImage {
let rect = CGRect(origin: CGPointZero, size: self.size)
let rect = CGRect(origin: CGPoint.zero, size: self.size)
UIGraphicsBeginImageContextWithOptions(rect.size, false, self.scale)
let context = UIGraphicsGetCurrentContext()
color.setFill()
@ -157,7 +157,7 @@ public extension UIImage {
}
public func bma_blendWithColor(color: UIColor) -> UIImage {
let rect = CGRect(origin: CGPointZero, size: self.size)
let rect = CGRect(origin: CGPoint.zero, size: self.size)
UIGraphicsBeginImageContextWithOptions(rect.size, false, UIScreen.mainScreen().scale)
let context = UIGraphicsGetCurrentContext()
CGContextTranslateCTM(context, 0, rect.height)
@ -166,15 +166,15 @@ public extension UIImage {
CGContextDrawImage(context, rect, self.CGImage)
CGContextClipToMask(context, rect, self.CGImage)
color.setFill()
CGContextAddRect(context, rect);
CGContextDrawPath(context, .Fill);
CGContextAddRect(context, rect)
CGContextDrawPath(context, .Fill)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image.resizableImageWithCapInsets(self.capInsets)
}
public static func bma_imageWithColor(color: UIColor, size: CGSize) -> UIImage {
let rect = CGRectMake(0, 0, size.width, size.height)
let rect = CGRect(origin: CGPoint.zero, size: size)
UIGraphicsBeginImageContextWithOptions(size, false, 0)
color.setFill()
UIRectFill(rect)

View File

@ -44,21 +44,21 @@ class BaseMessagePresenterTests: XCTestCase {
}
func testThat_WhenCellIsTappedOnFailIcon_ThenInteractionHandlerHandlesEvent() {
let cell = PhotoMessageCollectionViewCell(frame: CGRectZero)
let cell = PhotoMessageCollectionViewCell(frame: CGRect.zero)
self.presenter.configureCell(cell, decorationAttributes: self.decorationAttributes)
cell.failedButtonTapped()
XCTAssertTrue(self.interactionHandler.didHandleTapOnFailIcon)
}
func testThat_WhenCellIsTappedOnBubble_ThenInteractionHandlerHandlesEvent() {
let cell = PhotoMessageCollectionViewCell(frame: CGRectZero)
let cell = PhotoMessageCollectionViewCell(frame: CGRect.zero)
self.presenter.configureCell(cell, decorationAttributes: self.decorationAttributes)
cell.bubbleTapped(UITapGestureRecognizer())
XCTAssertTrue(self.interactionHandler.didHandleTapOnBubble)
}
func testThat_WhenCellIsLongPressedOnBubble_ThenInteractionHandlerHandlesEvent() {
let cell = PhotoMessageCollectionViewCell(frame: CGRectZero)
let cell = PhotoMessageCollectionViewCell(frame: CGRect.zero)
self.presenter.configureCell(cell, decorationAttributes: self.decorationAttributes)
cell.bubbleLongPressed()
XCTAssertTrue(self.interactionHandler.didHandleLongPressOnBubble)

View File

@ -46,7 +46,7 @@ class PhotoMessagePresenterTests: XCTestCase, UICollectionViewDataSource {
}
func testThat_CellIsConfigured() {
let cell = PhotoMessageCollectionViewCell(frame: CGRectZero)
let cell = PhotoMessageCollectionViewCell(frame: CGRect.zero)
self.presenter.configureCell(cell, decorationAttributes: self.decorationAttributes)
XCTAssertEqual(self.testImage, cell.bubbleView.photoMessageViewModel.image.value)
}
@ -56,7 +56,7 @@ class PhotoMessagePresenterTests: XCTestCase, UICollectionViewDataSource {
}
func testThat_RegistersAndDequeuesCells() {
let collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: UICollectionViewFlowLayout())
let collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: UICollectionViewFlowLayout())
PhotoMessagePresenter<PhotoMessageViewModelDefaultBuilder, PhotoMessageTestHandler>.registerCells(collectionView)
collectionView.dataSource = self
collectionView.reloadData()

View File

@ -42,7 +42,7 @@ class TextMessagePresenterTests: XCTestCase, UICollectionViewDataSource {
func testThat_RegistersAndDequeuesCells() {
let collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: UICollectionViewFlowLayout())
let collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: UICollectionViewFlowLayout())
TextMessagePresenter<TextMessageViewModelDefaultBuilder, TextMessageTestHandler>.registerCells(collectionView)
collectionView.dataSource = self
collectionView.reloadData()
@ -56,7 +56,7 @@ class TextMessagePresenterTests: XCTestCase, UICollectionViewDataSource {
}
func testThat_CellIsConfigured() {
let cell = TextMessageCollectionViewCell(frame: CGRectZero)
let cell = TextMessageCollectionViewCell(frame: CGRect.zero)
self.presenter.configureCell(cell, decorationAttributes: self.decorationAttributes)
XCTAssertEqual("Some text", cell.bubbleView.textMessageViewModel.text)
}
@ -66,7 +66,7 @@ class TextMessagePresenterTests: XCTestCase, UICollectionViewDataSource {
}
func testThat_ShouldShowMenuReturnsTrue() {
let cell = TextMessageCollectionViewCell(frame: CGRectZero)
let cell = TextMessageCollectionViewCell(frame: CGRect.zero)
self.presenter.cellWillBeShown(cell) // Needs to have a reference to the current cell before getting menu calls
XCTAssertTrue(self.presenter.shouldShowMenu())
}

View File

@ -30,7 +30,7 @@ class ChatInputItemTests: XCTestCase {
@objc
class MockInputItem: NSObject, ChatInputItemProtocol {
var selected = false;
var selected = false
var presentationMode: ChatInputItemPresentationMode = .Keyboard
var showsSendButton = false
var inputView: UIView? = nil

View File

@ -139,7 +139,7 @@ class ChatInputManagerTests: XCTestCase {
self.presenter.inputBarSendButtonPressed(self.bar)
XCTAssertEqual(itemThatHandledInput, 1)
}
// MARK: - Bar editing tests
func testThat_GivenPresenterHasFocusedItem_WhenBarDidEndEditing_FocusedItemLostFocus() {
let item = MockInputItem()

View File

@ -1,11 +0,0 @@
disabled_rules: # rule identifiers to exclude from running
- file_length
- force_cast
- function_body_length
- line_length
- todo
- type_body_length
- variable_name
included: # paths to include during linting. `--path` is ignored if present. takes precendence over `excluded`.
- ChattoApp
excluded: # paths to ignore during linting. overridden by `included`.

1
ChattoApp/.swiftlint.yml Symbolic link
View File

@ -0,0 +1 @@
../.swiftlint.yml

View File

@ -44,7 +44,7 @@ class DemoChatViewController: ChatViewController {
let image = UIImage(named: "bubble-incoming-tail-border", inBundle: NSBundle(forClass: self.dynamicType), compatibleWithTraitCollection: nil)?.bma_tintWithColor(UIColor.blueColor())
super.chatItemsDecorator = ChatItemsDemoDecorator()
let addIncomingMessageButton = UIBarButtonItem(image: image, style: .Plain, target: self, action: "addRandomIncomingMessage")
self.navigationItem.rightBarButtonItem = addIncomingMessageButton;
self.navigationItem.rightBarButtonItem = addIncomingMessageButton
}
@objc

View File

@ -26,13 +26,14 @@ import Foundation
import Chatto
class FakeDataSource: ChatDataSourceProtocol {
var lastMessageId: Int = 0
var nextMessageId: Int = 0
let preferredMaxWindowSize = 500
var slidingWindow: SlidingDataSource<ChatItemProtocol>!
init(count: Int, pageSize: Int) {
self.slidingWindow = SlidingDataSource(count: count, pageSize: pageSize) { () -> ChatItemProtocol in
return FakeMessageFactory.createChatItem("\(self.lastMessageId++)")
defer { self.nextMessageId += 1 }
return FakeMessageFactory.createChatItem("\(self.nextMessageId)")
}
}
@ -76,7 +77,8 @@ class FakeDataSource: ChatDataSourceProtocol {
}
func addTextMessage(text: String) {
let uid = "\(self.lastMessageId++)"
let uid = "\(self.nextMessageId)"
self.nextMessageId += 1
let message = createTextMessageModel(uid, text: text, isIncoming: false)
self.messageSender.sendMessage(message)
self.slidingWindow.insertItem(message, position: .Bottom)
@ -84,7 +86,8 @@ class FakeDataSource: ChatDataSourceProtocol {
}
func addPhotoMessage(image: UIImage) {
let uid = "\(self.lastMessageId++)"
let uid = "\(self.nextMessageId)"
self.nextMessageId += 1
let message = createPhotoMessageModel(uid, image: image, size: image.size, isIncoming: false)
self.messageSender.sendMessage(message)
self.slidingWindow.insertItem(message, position: .Bottom)
@ -92,7 +95,8 @@ class FakeDataSource: ChatDataSourceProtocol {
}
func addRandomIncomingMessage() {
let message = FakeMessageFactory.createChatItem("\(self.lastMessageId++)", isIncoming: true)
let message = FakeMessageFactory.createChatItem("\(self.nextMessageId)", isIncoming: true)
self.nextMessageId += 1
self.slidingWindow.insertItem(message, position: .Bottom)
self.delegate?.chatDataSourceDidUpdate(self)
}

View File

@ -72,15 +72,15 @@ public class SlidingDataSource<Element> {
if position == .Top {
self.items.insert(item, atIndex: 0)
let shouldExpandWindow = self.itemsOffset == self.windowOffset
self.itemsOffset--
self.itemsOffset -= 1
if shouldExpandWindow {
self.windowOffset--
self.windowCount++
self.windowOffset -= 1
self.windowCount += 1
}
} else {
let shouldExpandWindow = self.itemsOffset + self.items.count == self.windowOffset + self.windowCount
if shouldExpandWindow {
self.windowCount++
self.windowCount += 1
}
self.items.append(item)
}

View File

@ -90,7 +90,7 @@ class SendingStatusPresenter: ChatItemPresenterProtocol {
]
statusCell.text = NSAttributedString(
string: self.statusText(),
attributes: attrs);
attributes: attrs)
}
func statusText() -> String {

View File

@ -79,7 +79,7 @@ class FakeMessageFactory {
}
class func createPhotoMessageModel(uid: String, isIncoming: Bool) -> PhotoMessageModel {
var imageSize = CGSizeZero
var imageSize = CGSize.zero
switch arc4random_uniform(100) % 3 {
case 0:
imageSize = CGSize(width: 400, height: 300)

View File

@ -33,7 +33,8 @@ class SlidingDataSourceTests: XCTestCase {
return "\(id)"
}
let dataSource = SlidingDataSource(count: 10000, pageSize: 50) { () -> String in
return "\(uid++)"
defer { uid += 1 }
return "\(uid)"
}
XCTAssertEqual(expectedArray, dataSource.itemsInWindow)
@ -47,7 +48,8 @@ class SlidingDataSourceTests: XCTestCase {
return "\(id)"
}
let dataSource = SlidingDataSource(count: 10, pageSize: 50) { () -> String in
return "\(uid++)"
defer { uid += 1 }
return "\(uid)"
}
XCTAssertEqual(expectedArray, dataSource.itemsInWindow)
@ -58,7 +60,8 @@ class SlidingDataSourceTests: XCTestCase {
func testThat_WhenCountIsZero_ThenInitializesCorrectly() {
var uid = 0
let dataSource = SlidingDataSource(count: 0, pageSize: 50) { () -> String in
return "\(uid++)"
defer { uid += 1 }
return "\(uid)"
}
XCTAssertEqual([], dataSource.itemsInWindow)
XCTAssertFalse(dataSource.hasPrevious())
@ -72,7 +75,8 @@ class SlidingDataSourceTests: XCTestCase {
return "\(id)"
}
let dataSource = SlidingDataSource(count: 10000, pageSize: 50) { (id) -> String in
return "\(uid++)"
defer { uid += 1 }
return "\(uid)"
}
dataSource.loadPrevious()
@ -89,7 +93,8 @@ class SlidingDataSourceTests: XCTestCase {
}
let dataSource = SlidingDataSource(count: 10000, pageSize: 50) { (id) -> String in
return "\(uid++)"
defer { uid += 1 }
return "\(uid)"
}
for _ in 0..<10 {
@ -108,7 +113,8 @@ class SlidingDataSourceTests: XCTestCase {
}
let dataSource = SlidingDataSource(count: 10000, pageSize: 50) { (id) -> String in
return "\(uid++)"
defer { uid += 1 }
return "\(uid)"
}
dataSource.loadPrevious()
dataSource.loadPrevious()
@ -128,7 +134,8 @@ class SlidingDataSourceTests: XCTestCase {
expectedArray.append("test")
let dataSource = SlidingDataSource(count: 10000, pageSize: 50) { (id) -> String in
return "\(uid++)"
defer { uid += 1 }
return "\(uid)"
}
for _ in 0..<10 {
@ -154,7 +161,8 @@ class SlidingDataSourceTests: XCTestCase {
return "\(id)"
}
let dataSource = SlidingDataSource(count: 52, pageSize: 50) { (id) -> String in
return "\(uid++)"
defer { uid += 1 }
return "\(uid)"
}
dataSource.loadPrevious()

View File

@ -25,12 +25,12 @@
import XCTest
class ChattoAppUITests: XCTestCase {
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
// In UI tests it is usually best to stop immediately when a failure occurs.
continueAfterFailure = false
// UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
@ -42,15 +42,15 @@ class ChattoAppUITests: XCTestCase {
// In UI tests its important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testExample() {
// Use recording to get started writing UI tests.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
}