-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignore unknown elements #121
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
88be637
Ignore unknown elements
cysp 4a1ce47
Treat a elements like g in terms of respecting attributes
cysp 796b456
Update changelog
cysp 0e89905
Type the return value of +[SVGBezierPath pathsFromSVGString:]
cysp a5127fa
Test that mask elements are ignored
cysp 87e6b71
Test that attributes are respected on a elements
cysp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,5 +82,54 @@ class PocketSVGTests: XCTestCase { | |
|
||
XCTAssertEqual(rectanglePath.svgRepresentation, representation) | ||
} | ||
|
||
|
||
func testIgnoresMaskElement() { | ||
let svgString = """ | ||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px"> | ||
<g> | ||
<mask> | ||
<g> | ||
<rect width="100" height="100" style="fill: #FFFFFF" /> | ||
</g> | ||
</mask> | ||
<rect x="20" y="20" width="60" height="60" style="fill: #FF0000"/> | ||
</g> | ||
</svg> | ||
""" | ||
|
||
let paths = SVGBezierPath.paths(fromSVGString: svgString) | ||
XCTAssertEqual(paths.count, 1) | ||
|
||
guard let path = paths.first else { | ||
return | ||
} | ||
|
||
XCTAssertEqual(path.bounds, CGRect(x: 20, y: 20, width: 60, height: 60)) | ||
} | ||
|
||
func testRespectsAttributesOnAElement() { | ||
let svgString = """ | ||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px"> | ||
<a transform="translate(5 10)"> | ||
<rect x="15" y="10" width="60" height="60"/> | ||
</a> | ||
</svg> | ||
""" | ||
|
||
let paths = SVGBezierPath.paths(fromSVGString: svgString) | ||
XCTAssertEqual(paths.count, 1) | ||
|
||
guard let path = paths.first else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto as above. |
||
return | ||
} | ||
|
||
let pathTransform = (path.svgAttributes["transform"]! as! NSValue).cgAffineTransformValue | ||
let pathBounds = path.bounds | ||
let translatedPathBounds = pathBounds.applying(pathTransform) | ||
|
||
XCTAssertEqual(pathTransform, CGAffineTransform(translationX: 5, y: 10)) | ||
XCTAssertEqual(pathBounds, CGRect(x: 15, y: 10, width: 60, height: 60)) | ||
XCTAssertEqual(translatedPathBounds, CGRect(x: 20, y: 20, width: 60, height: 60)) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if
XCTAssertEqual(paths.count, 1)
passes, then we know thatpaths.first != nil
, so thisguard let
is redundant and it's safe to dopath!.bounds
below.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured that bailing after failing the assertion was friendlier than hitting a fatal error and breaking the whole test run in the case that we don't parse any paths out of the svg?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an individual test's execution stops as soon as an assertion fails, so if we don't parse any paths out of the svg we'll duly fail the assertion on line 101 and we're guaranteed not to execute the code with the force unwrap.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. That’s not how Xcode (9.3) behaves on my computer and I can’t see
.continueAfterFailure
being set anywhere. Is that a global configuration option in Xcode?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, sorry, you're absolutely right, I hadn't set
.continueAfterFailure
tofalse
I have now: 1c014fa