Permalink
Browse files

Fixed problem with scanHTMLColor:

- was unable to parse HTML color name
- caused shadow color written as color name to not be picked up
- Added unit test
  • Loading branch information...
1 parent 4827d70 commit dab5994db406f7a6df06178c8cfdd6a3533a201a @odrobnik odrobnik committed Jan 5, 2013
@@ -408,6 +408,11 @@ - (BOOL)scanHTMLColor:(DTColor **)color
colorName = [colorName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
}
+ else
+ {
+ // could be a plain html color name
+ [self scanCharactersFromSet:[NSCharacterSet alphanumericCharacterSet] intoString:&colorName];
+ }
DTColor *foundColor = nil;
@@ -0,0 +1,13 @@
+//
+// NSStringCSSTest.h
+// DTCoreText
+//
+// Created by Oliver Drobnik on 1/5/13.
+// Copyright (c) 2013 Drobnik.com. All rights reserved.
+//
+
+#import <SenTestingKit/SenTestingKit.h>
+
+@interface NSStringCSSTest : SenTestCase
+
+@end
@@ -0,0 +1,64 @@
+//
+// NSStringCSSTest.m
+// DTCoreText
+//
+// Created by Oliver Drobnik on 1/5/13.
+// Copyright (c) 2013 Drobnik.com. All rights reserved.
+//
+
+#import "NSStringCSSTest.h"
+#import "NSString+CSS.h"
+#import "DTColor+HTML.h"
+
+@implementation NSStringCSSTest
+
+- (void)testShadowColorFirst
+{
+ NSString *string = @"red 1px 2px 3px;";
+
+ DTColor *color = (DTColor *)[UIColor blackColor];
+ NSArray *shadows = [string arrayOfCSSShadowsWithCurrentTextSize:10.0 currentColor:color];
+
+ STAssertTrue([shadows count]==1, @"Could not find one shadow");
+
+ NSDictionary *oneShadow = [shadows lastObject];
+
+ STAssertTrue([oneShadow count]==3, @"Could not find 3 sub-values for shadow");
+
+ CGFloat blur = [[oneShadow objectForKey:@"Blur"] floatValue];
+ STAssertTrue(blur==3.0f, @"Blur should be 3");
+
+ CGSize offset = [[oneShadow objectForKey:@"Offset"] CGSizeValue];
+ CGSize expectedOffset = CGSizeMake(1, 2);
+ STAssertTrue(CGSizeEqualToSize(offset, expectedOffset), @"Offset should be 1,2");
+
+ DTColor *shadowColor = [oneShadow objectForKey:@"Color"];
+ STAssertEqualObjects(shadowColor, [UIColor redColor], @"Color should be red");
+}
+
+
+- (void)testShadowColorLast
+{
+ NSString *string = @"1px 2px 3px red;";
+
+ DTColor *color = (DTColor *)[UIColor blackColor];
+ NSArray *shadows = [string arrayOfCSSShadowsWithCurrentTextSize:10.0 currentColor:color];
+
+ STAssertTrue([shadows count]==1, @"Could not find one shadow");
+
+ NSDictionary *oneShadow = [shadows lastObject];
+
+ STAssertTrue([oneShadow count]==3, @"Could not find 3 sub-values for shadow");
+
+ CGFloat blur = [[oneShadow objectForKey:@"Blur"] floatValue];
+ STAssertTrue(blur==3.0f, @"Blur should be 3");
+
+ CGSize offset = [[oneShadow objectForKey:@"Offset"] CGSizeValue];
+ CGSize expectedOffset = CGSizeMake(1, 2);
+ STAssertTrue(CGSizeEqualToSize(offset, expectedOffset), @"Offset should be 1,2");
+
+ DTColor *shadowColor = [oneShadow objectForKey:@"Color"];
+ STAssertEqualObjects(shadowColor, [UIColor redColor], @"Color should be red");
+}
+
+@end
@@ -412,6 +412,8 @@
A7EB8541168FA33500D686B7 /* DTHTMLElementStylesheet.m in Sources */ = {isa = PBXBuildFile; fileRef = A7EB8538168FA33300D686B7 /* DTHTMLElementStylesheet.m */; };
A7EB8543169065F300D686B7 /* WhitespaceFollowingImagePromotedToParagraph.html in Resources */ = {isa = PBXBuildFile; fileRef = A7EB8542169065F200D686B7 /* WhitespaceFollowingImagePromotedToParagraph.html */; };
A7EB8544169065F300D686B7 /* WhitespaceFollowingImagePromotedToParagraph.html in Resources */ = {isa = PBXBuildFile; fileRef = A7EB8542169065F200D686B7 /* WhitespaceFollowingImagePromotedToParagraph.html */; };
+ A7F16CF61698491400B0E843 /* NSStringCSSTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A7F16CF51698491400B0E843 /* NSStringCSSTest.m */; };
+ A7F16CF71698491400B0E843 /* NSStringCSSTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A7F16CF51698491400B0E843 /* NSStringCSSTest.m */; };
A7F5671414D841EA00D1F167 /* NSString+CSS.h in Headers */ = {isa = PBXBuildFile; fileRef = A7F5671214D841E900D1F167 /* NSString+CSS.h */; settings = {ATTRIBUTES = (Public, ); }; };
A7F5671514D841EA00D1F167 /* NSString+CSS.h in Headers */ = {isa = PBXBuildFile; fileRef = A7F5671214D841E900D1F167 /* NSString+CSS.h */; settings = {ATTRIBUTES = (Public, ); }; };
A7F5671614D841EA00D1F167 /* NSString+CSS.m in Sources */ = {isa = PBXBuildFile; fileRef = A7F5671314D841E900D1F167 /* NSString+CSS.m */; };
@@ -941,6 +943,8 @@
A7EB8537168FA33000D686B7 /* DTHTMLElementStylesheet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DTHTMLElementStylesheet.h; sourceTree = "<group>"; };
A7EB8538168FA33300D686B7 /* DTHTMLElementStylesheet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DTHTMLElementStylesheet.m; sourceTree = "<group>"; };
A7EB8542169065F200D686B7 /* WhitespaceFollowingImagePromotedToParagraph.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = WhitespaceFollowingImagePromotedToParagraph.html; sourceTree = "<group>"; };
+ A7F16CF41698491400B0E843 /* NSStringCSSTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSStringCSSTest.h; sourceTree = "<group>"; };
+ A7F16CF51698491400B0E843 /* NSStringCSSTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSStringCSSTest.m; sourceTree = "<group>"; };
A7F5671214D841E900D1F167 /* NSString+CSS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = "NSString+CSS.h"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
A7F5671314D841E900D1F167 /* NSString+CSS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = "NSString+CSS.m"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
A7F5671C14D8469000D1F167 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Cocoa.framework; sourceTree = DEVELOPER_DIR; };
@@ -1384,6 +1388,8 @@
A7E3346D16837482002EFCBE /* DTCSSStylesheetTest.m */,
A7DBC1B51689BA20003F1D38 /* DTHTMLAttributedStringBuilderTest.h */,
A7DBC1B61689BA20003F1D38 /* DTHTMLAttributedStringBuilderTest.m */,
+ A7F16CF41698491400B0E843 /* NSStringCSSTest.h */,
+ A7F16CF51698491400B0E843 /* NSStringCSSTest.m */,
);
path = Source;
sourceTree = "<group>";
@@ -2218,6 +2224,7 @@
A7EB84EB168C657100D686B7 /* DTHTMLElementLI.m in Sources */,
A7EB8535168F336100D686B7 /* DTHTMLElementAttachment.m in Sources */,
A7EB853F168FA33500D686B7 /* DTHTMLElementStylesheet.m in Sources */,
+ A7F16CF61698491400B0E843 /* NSStringCSSTest.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -2259,6 +2266,7 @@
A7EB84EC168C657100D686B7 /* DTHTMLElementLI.m in Sources */,
A7EB8534168F336000D686B7 /* DTHTMLElementAttachment.m in Sources */,
A7EB8540168FA33500D686B7 /* DTHTMLElementStylesheet.m in Sources */,
+ A7F16CF71698491400B0E843 /* NSStringCSSTest.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

0 comments on commit dab5994

Please sign in to comment.