Permalink
Browse files

Added unit tests for #649

  • Loading branch information...
1 parent 0d556dc commit c53bb512cc5e39d03028c164c5d85dd5dbe95c2c @odrobnik odrobnik committed Nov 15, 2013
Showing with 38 additions and 0 deletions.
  1. +38 −0 Test/Source/DTHTMLAttributedStringBuilderTest.m
View
38 Test/Source/DTHTMLAttributedStringBuilderTest.m
@@ -1031,4 +1031,42 @@ - (void)testDisplayStyleInheritance
NSArray *lines = [[[attributedString string] stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]] componentsSeparatedByString:@"\n"];
STAssertTrue([lines count]==1, @"There should only be one line, display style block should not be inherited");
}
+
+#pragma mark - Parsing Options
+
+// issue 649
+- (void)testIgnoreInlineStyle
+{
+ NSDictionary *options = @{DTIgnoreInlineStylesOption: @(YES)};
+ NSAttributedString *attributedString = [self attributedStringFromHTMLString:@"<html><head><style>.container { color: red }</style></head><body><span class='container' style=\"color: blue\">Text</span></body></html>" options:options];
+
+ NSRange effectiveRange;
+ NSDictionary *attributes = [attributedString attributesAtIndex:0 effectiveRange:&effectiveRange];
+
+ NSRange expectedRange = NSMakeRange(0, [attributedString length]);
+ STAssertEquals(expectedRange, effectiveRange, @"Attributes should cover all text");
+
+ DTColor *color = [attributes foregroundColor];
+ NSString *hexColor = DTHexStringFromDTColor(color);
+
+ STAssertEqualObjects(hexColor, @"ff0000", @"Color should be red because inline style should be ignored through option");
+}
+
+// issue 649
+- (void)testProcessInlineStyle
+{
+ NSAttributedString *attributedString = [self attributedStringFromHTMLString:@"<html><head><style>.container { color: red }</style></head><body><span class='container' style=\"color: blue\">Text</span></body></html>" options:NULL];
+
+ NSRange effectiveRange;
+ NSDictionary *attributes = [attributedString attributesAtIndex:0 effectiveRange:&effectiveRange];
+
+ NSRange expectedRange = NSMakeRange(0, [attributedString length]);
+ STAssertEquals(expectedRange, effectiveRange, @"Attributes should cover all text");
+
+ DTColor *color = [attributes foregroundColor];
+ NSString *hexColor = DTHexStringFromDTColor(color);
+
+ STAssertEqualObjects(hexColor, @"0000ff", @"Color should be blue because inline style should be processed through lack of ignore option");
+}
+
@end

0 comments on commit c53bb51

Please sign in to comment.