Author: ericwa
Date: Thu Mar 20 08:39:16 2014
New Revision: 10598

URL: http://svn.gna.org/viewcvs/etoile?rev=10598&view=rev
Log:
COAttributedString: fix bug when mixing underline & strikethrough

Added:
    
trunk/Etoile/Frameworks/CoreObject/Tests/Extras/Model/TestAttributedStringAttribute.m
Modified:
    trunk/Etoile/Frameworks/CoreObject/CoreObject.xcodeproj/project.pbxproj
    
trunk/Etoile/Frameworks/CoreObject/Extras/Model/COAttributedStringAttribute.m
    trunk/Etoile/Frameworks/CoreObject/Extras/Model/COAttributedStringWrapper.m
    
trunk/Etoile/Frameworks/CoreObject/Tests/Extras/Model/TestAttributedStringWrapper.m

Modified: 
trunk/Etoile/Frameworks/CoreObject/CoreObject.xcodeproj/project.pbxproj
URL: 
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/CoreObject.xcodeproj/project.pbxproj?rev=10598&r1=10597&r2=10598&view=diff
==============================================================================
--- trunk/Etoile/Frameworks/CoreObject/CoreObject.xcodeproj/project.pbxproj     
(original)
+++ trunk/Etoile/Frameworks/CoreObject/CoreObject.xcodeproj/project.pbxproj     
Thu Mar 20 08:39:16 2014
@@ -275,6 +275,7 @@
                66B1FC72187377ED00745859 /* TestAttributedString.m in Sources 
*/ = {isa = PBXBuildFile; fileRef = 66B1FC71187377ED00745859 /* 
TestAttributedString.m */; };
                66B6DC5C187A020900870370 /* TestDiffManager.m in Sources */ = 
{isa = PBXBuildFile; fileRef = 66B6DC5B187A020900870370 /* TestDiffManager.m 
*/; };
                66BA3D4A18DA6C4B00641D40 /* TestAttributedStringCommon.m in 
Sources */ = {isa = PBXBuildFile; fileRef = 660EE3B1186E3DA600E8C22C /* 
TestAttributedStringCommon.m */; };
+               66BA3D6318DACFAC00641D40 /* TestAttributedStringAttribute.m in 
Sources */ = {isa = PBXBuildFile; fileRef = 66BA3D6218DACFAC00641D40 /* 
TestAttributedStringAttribute.m */; };
                66BBB3BC18516ABC005430B1 /* TestItemStableSerialization.m in 
Sources */ = {isa = PBXBuildFile; fileRef = 66BBB3BB18516ABC005430B1 /* 
TestItemStableSerialization.m */; };
                66BDC4AF17B6ED27003B0EDA /* COBranchInfo.h in Headers */ = {isa 
= PBXBuildFile; fileRef = 66C3670917B5F9AF009ACF2F /* COBranchInfo.h */; 
settings = {ATTRIBUTES = (Public, ); }; };
                66BDC4B017B6ED27003B0EDA /* COPersistentRootInfo.h in Headers 
*/ = {isa = PBXBuildFile; fileRef = 66C3670D17B5FA0D009ACF2F /* 
COPersistentRootInfo.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -832,6 +833,7 @@
                66B1FC6818727D7E00745859 /* TestAttributedStringHistory.m */ = 
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = 
sourcecode.c.objc; path = TestAttributedStringHistory.m; sourceTree = 
"<group>"; };
                66B1FC71187377ED00745859 /* TestAttributedString.m */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path 
= TestAttributedString.m; sourceTree = "<group>"; };
                66B6DC5B187A020900870370 /* TestDiffManager.m */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path 
= TestDiffManager.m; sourceTree = "<group>"; };
+               66BA3D6218DACFAC00641D40 /* TestAttributedStringAttribute.m */ 
= {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = 
sourcecode.c.objc; path = TestAttributedStringAttribute.m; sourceTree = 
"<group>"; };
                66BBB3BB18516ABC005430B1 /* TestItemStableSerialization.m */ = 
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = 
sourcecode.c.objc; path = TestItemStableSerialization.m; sourceTree = 
"<group>"; };
                66C3669E17B426C0009ACF2F /* Typewriter-Info.plist */ = {isa = 
PBXFileReference; lastKnownFileType = text.plist; name = 
"Typewriter-Info.plist"; path = "Samples/Typewriter/Typewriter-Info.plist"; 
sourceTree = "<group>"; };
                66C366A017B426C0009ACF2F /* en */ = {isa = PBXFileReference; 
lastKnownFileType = text.plist.strings; name = en; path = 
en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
@@ -1190,6 +1192,7 @@
                                660EE3A4186E072500E8C22C /* 
TestAttributedStringDiffOperations.m */,
                                660EE3AE186E3D8700E8C22C /* 
TestAttributedStringWrapper.m */,
                                66B1FC6818727D7E00745859 /* 
TestAttributedStringHistory.m */,
+                               66BA3D6218DACFAC00641D40 /* 
TestAttributedStringAttribute.m */,
                        );
                        path = Model;
                        sourceTree = "<group>";
@@ -2427,6 +2430,7 @@
                                66E40D6C1836D08D00E5B4A7 /* TestSQLiteStore.m 
in Sources */,
                                660EE3B2186E3DA600E8C22C /* 
TestAttributedStringCommon.m in Sources */,
                                66BBB3BC18516ABC005430B1 /* 
TestItemStableSerialization.m in Sources */,
+                               66BA3D6318DACFAC00641D40 /* 
TestAttributedStringAttribute.m in Sources */,
                                6610116A184D8CA6001A3E24 /* 
UnorderedGroupWithOpposite.m in Sources */,
                                66E40D5B1836D08D00E5B4A7 /* 
TestCopierWithIsShared.m in Sources */,
                                66E40D6F1836D08D00E5B4A7 /* 
TestSQLiteStoreSharedPersistentRoots.m in Sources */,

Modified: 
trunk/Etoile/Frameworks/CoreObject/Extras/Model/COAttributedStringAttribute.m
URL: 
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Extras/Model/COAttributedStringAttribute.m?rev=10598&r1=10597&r2=10598&view=diff
==============================================================================
--- 
trunk/Etoile/Frameworks/CoreObject/Extras/Model/COAttributedStringAttribute.m   
    (original)
+++ 
trunk/Etoile/Frameworks/CoreObject/Extras/Model/COAttributedStringAttribute.m   
    Thu Mar 20 08:39:16 2014
@@ -43,30 +43,30 @@
        return result;
 }
 
-+ (NSDictionary *) dictionaryForAttributeSet: (NSSet *)aSet
++ (NSSet *) setOfStringPairsForAttributeSet: (NSSet *)aSet
 {
-       NSMutableDictionary *result = [NSMutableDictionary new];
+       NSMutableSet *result = [NSMutableSet new];
        for (COAttributedStringAttribute *attr in aSet)
        {
-               result[attr.styleKey] = attr.styleValue;
+               [result addObject: @[attr.styleKey, attr.styleValue]];
        }
        return result;
 }
 
 + (BOOL) isAttributeSet: (NSSet *)aSet equalToSet: (NSSet *)anotherSet
 {
-       return [[self dictionaryForAttributeSet: aSet]
-                       isEqual: [self dictionaryForAttributeSet: anotherSet]];
+       return [[self setOfStringPairsForAttributeSet: aSet]
+                       isEqual: [self setOfStringPairsForAttributeSet: 
anotherSet]];
 }
 
 + (NSSet *) attributeSet: (NSSet *)aSet minusSet: (NSSet *)anotherSet
 {
-       NSDictionary *pairsToRemove = [self dictionaryForAttributeSet: 
anotherSet];
+       NSSet *pairsToRemove = [self setOfStringPairsForAttributeSet: 
anotherSet];
        
        NSMutableSet *result = [NSMutableSet set];
        for (COAttributedStringAttribute *attr in aSet)
        {
-               if (![pairsToRemove[attr.styleKey] isEqualToString: 
attr.styleValue])
+               if (![pairsToRemove containsObject: @[attr.styleKey, 
attr.styleValue]])
                {
                        [result addObject: attr];
                }

Modified: 
trunk/Etoile/Frameworks/CoreObject/Extras/Model/COAttributedStringWrapper.m
URL: 
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Extras/Model/COAttributedStringWrapper.m?rev=10598&r1=10597&r2=10598&view=diff
==============================================================================
--- trunk/Etoile/Frameworks/CoreObject/Extras/Model/COAttributedStringWrapper.m 
(original)
+++ trunk/Etoile/Frameworks/CoreObject/Extras/Model/COAttributedStringWrapper.m 
Thu Mar 20 08:39:16 2014
@@ -533,6 +533,8 @@
                }
        }
 
+       //NSLog(@">>> Returning %@ for %@", newAttribs, attrs);
+       
        return newAttribs;
 }
 

Added: 
trunk/Etoile/Frameworks/CoreObject/Tests/Extras/Model/TestAttributedStringAttribute.m
URL: 
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Tests/Extras/Model/TestAttributedStringAttribute.m?rev=10598&view=auto
==============================================================================
--- 
trunk/Etoile/Frameworks/CoreObject/Tests/Extras/Model/TestAttributedStringAttribute.m
       (added)
+++ 
trunk/Etoile/Frameworks/CoreObject/Tests/Extras/Model/TestAttributedStringAttribute.m
       Thu Mar 20 08:39:16 2014
@@ -0,0 +1,45 @@
+/*
+       Copyright (C) 2014 Eric Wasylishen
+ 
+       Date:  March 2014
+       License:  MIT  (see COPYING)
+ */
+
+#import "TestAttributedStringCommon.h"
+
+@interface TestAttributedStringAttribute : EditingContextTestCase <UKTest>
+@end
+
+@implementation TestAttributedStringAttribute
+
+- (void) testEqualsAndMinusConvenienceMethods
+{
+       COObjectGraphContext *graph1 = [COObjectGraphContext new];
+       
+       COAttributedStringAttribute *attr1a = [[COAttributedStringAttribute 
alloc] initWithObjectGraphContext: graph1];
+       attr1a.styleKey = @"text-decoration";
+       attr1a.styleValue = @"line-through";
+       
+       COAttributedStringAttribute *attr1b = [[COAttributedStringAttribute 
alloc] initWithObjectGraphContext: graph1];
+       attr1b.styleKey = @"text-decoration";
+       attr1b.styleValue = @"underline";
+       
+       COObjectGraphContext *graph2 = [COObjectGraphContext new];
+       
+       COAttributedStringAttribute *attr2a = [[COAttributedStringAttribute 
alloc] initWithObjectGraphContext: graph2];
+       attr2a.styleKey = @"text-decoration";
+       attr2a.styleValue = @"line-through";
+       
+       UKFalse([COAttributedStringAttribute isAttributeSet: S(attr1a, attr1b) 
equalToSet: S(attr2a)]);
+       UKFalse([COAttributedStringAttribute isAttributeSet: S(attr1b) 
equalToSet: S(attr2a)]);
+       UKFalse([COAttributedStringAttribute isAttributeSet: S() equalToSet: 
S(attr2a)]);
+       UKFalse([COAttributedStringAttribute isAttributeSet: S(attr1b) 
equalToSet: S()]);
+       
+       UKTrue([COAttributedStringAttribute isAttributeSet: S(attr1a) 
equalToSet: S(attr2a)]);
+       UKTrue([COAttributedStringAttribute isAttributeSet: S(attr2a) 
equalToSet: S(attr2a)]);
+       
+       UKObjectsEqual(S(attr1b), [COAttributedStringAttribute attributeSet: 
S(attr1a, attr1b) minusSet: S(attr2a)]);
+       UKObjectsEqual(S(attr1a, attr1b), [COAttributedStringAttribute 
attributeSet: S(attr1a, attr1b) minusSet: S()]);
+}
+
+@end

Modified: 
trunk/Etoile/Frameworks/CoreObject/Tests/Extras/Model/TestAttributedStringWrapper.m
URL: 
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Tests/Extras/Model/TestAttributedStringWrapper.m?rev=10598&r1=10597&r2=10598&view=diff
==============================================================================
--- 
trunk/Etoile/Frameworks/CoreObject/Tests/Extras/Model/TestAttributedStringWrapper.m
 (original)
+++ 
trunk/Etoile/Frameworks/CoreObject/Tests/Extras/Model/TestAttributedStringWrapper.m
 Thu Mar 20 08:39:16 2014
@@ -308,6 +308,22 @@
        [self checkFontHasTraits: 0 withLongestEffectiveRange: NSMakeRange(0, 
1) inAttributedString: as];
 }
 
+- (void) testAddUnderlineAndStrikethrough
+{
+       [as replaceCharactersInRange: NSMakeRange(0, 0) withString: @"abc"];
+       
+       [self checkBlock: ^() {
+               [as addAttribute: NSUnderlineStyleAttributeName value: 
@(NSUnderlineStyleSingle) range: NSMakeRange(1, 1)];
+       } modifiesRange: NSMakeRange(1, 1) mask: NSTextStorageEditedAttributes 
delta: 0 newString: @"abc"];
+       
+       [self checkBlock: ^() {
+               [as addAttribute: NSStrikethroughStyleAttributeName value: 
@(NSUnderlineStyleSingle) range: NSMakeRange(0, 3)];
+       } modifiesRange: NSMakeRange(0, 3) mask: NSTextStorageEditedAttributes 
delta: 0 newString: @"abc"];
+       
+       [self checkAttribute: NSStrikethroughStyleAttributeName hasValue: 
@(NSUnderlineStyleSingle) withLongestEffectiveRange: NSMakeRange(0, 3) 
inAttributedString: as];
+       [self checkAttribute: NSUnderlineStyleAttributeName hasValue: 
@(NSUnderlineStyleSingle) withLongestEffectiveRange: NSMakeRange(1, 1) 
inAttributedString: as];
+}
+
 @end
 
 


_______________________________________________
Etoile-cvs mailing list
Etoile-cvs@gna.org
https://mail.gna.org/listinfo/etoile-cvs

Reply via email to