Skip to content

Commit

Permalink
Merge pull request #87 from iZettle/TextStyle_Equatable_BugFix
Browse files Browse the repository at this point in the history
TextStyle Equatable bug fix
  • Loading branch information
mayur8657 authored Feb 13, 2019
2 parents 7c5a45f + 566cbd0 commit 971929b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Form.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
CA6755EA1D4B6F1C000662FF /* SegmentedControlStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA6755E91D4B6F1C000662FF /* SegmentedControlStyle.swift */; };
CD49499B1C199520000176D3 /* (null) in Sources */ = {isa = PBXBuildFile; };
CDD2A5211F42DE7500E2B78B /* HighlightedTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD2A5201F42DE7500E2B78B /* HighlightedTests.swift */; };
CFD2FFE3221323BF002D4D36 /* TextStyleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFD2FFE2221323BF002D4D36 /* TextStyleTests.swift */; };
E63D89BF1DF59D6100AAB381 /* DisplayableString.swift in Sources */ = {isa = PBXBuildFile; fileRef = E63D89BE1DF59D6100AAB381 /* DisplayableString.swift */; };
F60102311DAE2D410020015B /* TableChange.swift in Sources */ = {isa = PBXBuildFile; fileRef = F60102301DAE2D410020015B /* TableChange.swift */; };
F604260A20B6A47E00BC4CAB /* ParentChildRelationalTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F604260920B6A47E00BC4CAB /* ParentChildRelationalTests.swift */; };
Expand Down Expand Up @@ -139,6 +140,7 @@
B35F8B4B1F3783E400904E37 /* CollectionDiffTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionDiffTests.swift; sourceTree = "<group>"; };
CA6755E91D4B6F1C000662FF /* SegmentedControlStyle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SegmentedControlStyle.swift; path = Form/SegmentedControlStyle.swift; sourceTree = "<group>"; };
CDD2A5201F42DE7500E2B78B /* HighlightedTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HighlightedTests.swift; sourceTree = "<group>"; };
CFD2FFE2221323BF002D4D36 /* TextStyleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextStyleTests.swift; sourceTree = "<group>"; };
E63D89BE1DF59D6100AAB381 /* DisplayableString.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DisplayableString.swift; path = Form/DisplayableString.swift; sourceTree = SOURCE_ROOT; };
F60102301DAE2D410020015B /* TableChange.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TableChange.swift; path = Form/TableChange.swift; sourceTree = "<group>"; };
F604260920B6A47E00BC4CAB /* ParentChildRelationalTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParentChildRelationalTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -263,6 +265,7 @@
F62E45B51CABFB5300C6867E /* FormTests */ = {
isa = PBXGroup;
children = (
CFD2FFE2221323BF002D4D36 /* TextStyleTests.swift */,
CDD2A5201F42DE7500E2B78B /* HighlightedTests.swift */,
1C2881821F20EE2000666A21 /* SelectViewTests.swift */,
1CDD56A91D9C10D7004B0CA9 /* TableTests.swift */,
Expand Down Expand Up @@ -572,6 +575,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
CFD2FFE3221323BF002D4D36 /* TextStyleTests.swift in Sources */,
F604260A20B6A47E00BC4CAB /* ParentChildRelationalTests.swift in Sources */,
F6B81B9420CA906000B6AC39 /* NumberEditorTests.swift in Sources */,
CDD2A5211F42DE7500E2B78B /* HighlightedTests.swift in Sources */,
Expand Down
7 changes: 6 additions & 1 deletion Form/TextStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ public extension TextStyle {
var style = ((self.attribute(for: .paragraphStyle) as NSParagraphStyle?)?.mutableCopy() as? NSMutableParagraphStyle) ?? NSMutableParagraphStyle()
update(&style)
attributes[.paragraphStyle] = style

if equatableForAttribute[.paragraphStyle] == nil {
equatableForAttribute[.paragraphStyle] = { $0 as! NSMutableParagraphStyle == $1 as! NSMutableParagraphStyle }
}

}

/// Register a custom `transfrom` for `attribute`
Expand All @@ -159,7 +164,7 @@ extension TextStyle: Equatable {
}

for (attribute, left) in lhs.attributes {
guard let right = rhs.attributes[attribute], attribute != .paragraphStyle else {
guard let right = rhs.attributes[attribute] else {
return false
}

Expand Down
26 changes: 26 additions & 0 deletions FormTests/TextStyleTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// TextStyleTests.swift
// FormTests
//
// Created by Mayur Deshmukh on 12/02/19.
// Copyright © 2019 iZettle. All rights reserved.
//

import XCTest
import Form

class TextStyleTests: XCTestCase {

func testTextStyleEquality() {
let textStyle1 = TextStyle(font: .systemFont(ofSize: 14.0), color: .red, alignment: .left, lineBreakMode: .byWordWrapping)
let textStyle2 = TextStyle(font: .systemFont(ofSize: 14.0), color: .red, alignment: .left, lineBreakMode: .byWordWrapping)
let textStyle3 = TextStyle(font: .systemFont(ofSize: 14.0), color: .red, alignment: .left, lineBreakMode: .byCharWrapping)
let textStyle4 = TextStyle(font: .systemFont(ofSize: 15.0), color: .red, alignment: .left, lineBreakMode: .byWordWrapping)
let textStyle5 = TextStyle(font: .systemFont(ofSize: 14.0), color: .green, alignment: .left, lineBreakMode: .byWordWrapping)

XCTAssertEqual(textStyle1, textStyle2)
XCTAssertNotEqual(textStyle1, textStyle3)
XCTAssertNotEqual(textStyle1, textStyle4)
XCTAssertNotEqual(textStyle1, textStyle5)
}
}

0 comments on commit 971929b

Please sign in to comment.