forked from exyte/SVGView
-
Notifications
You must be signed in to change notification settings - Fork 0
Improve DX ergonomic #6
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
Merged
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8daa5d7
Move tests to SwiftPM
khoi 2be3277
Remove CocoaPods support
khoi d18479d
Delete color-prop-04 as it requires system collors
khoi 7ec49e9
Migrate test generation from shell script to Makefile
khoi 880e9d8
Consolidate test jobs using matrix strategy
khoi 2660c5e
Replace Makefile with direct Swift test command in CI
khoi b1c2f0f
Split matrix test job into separate Linux and macOS jobs
khoi e7b9ebb
Simplify CGAffineTransform serialization implementation
khoi 9785911
Update README to reflect fork status and customizations
khoi 9c4c910
Significantly improve the developer experience for testing
khoi 0168685
Restore the original logic of serialization
khoi aadbb34
Update tests
khoi cd7ef31
Improve CI workflow formatting and focus Linux tests
khoi 567ddde
Update decimal
khoi 63701c3
Add Darwin-only restriction to reference generation CLI
khoi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| import Foundation | ||
| import ArgumentParser | ||
|
|
||
| @testable import SVGView | ||
|
|
||
| #if os(macOS) | ||
| @main | ||
| struct cli: ParsableCommand { | ||
| @Argument(help: "Path to a folder that contains 1.1F2/ and 1.2T/") | ||
| var input: String | ||
|
|
||
| static let v11Refs: [String] = [ | ||
| "color-prop-01-b", | ||
| "color-prop-02-f", | ||
| "color-prop-03-t", | ||
| "color-prop-04-t", | ||
| "color-prop-05-t", | ||
| "coords-coord-01-t", | ||
| "coords-coord-02-t", | ||
| "coords-trans-01-b", | ||
| "coords-trans-02-t", | ||
| "coords-trans-03-t", | ||
| "coords-trans-04-t", | ||
| "coords-trans-05-t", | ||
| "coords-trans-06-t", | ||
| "coords-trans-07-t", | ||
| "coords-trans-08-t", | ||
| "coords-trans-09-t", | ||
| "coords-trans-10-f", | ||
| "coords-trans-11-f", | ||
| "coords-trans-12-f", | ||
| "coords-trans-13-f", | ||
| "coords-trans-14-f", | ||
| "coords-transformattr-01-f", | ||
| "coords-transformattr-02-f", | ||
| "coords-transformattr-03-f", | ||
| "coords-transformattr-04-f", | ||
| "coords-transformattr-05-f", | ||
| "coords-units-02-b", | ||
| "coords-units-03-b", | ||
| "masking-opacity-01-b", | ||
| "painting-control-02-f", | ||
| "painting-control-03-f", | ||
| "painting-marker-01-f", | ||
| "painting-fill-01-t", | ||
| "painting-fill-02-t", | ||
| "painting-fill-03-t", | ||
| "painting-fill-04-t", | ||
| "painting-fill-05-b", | ||
| "painting-stroke-01-t", | ||
| "painting-stroke-02-t", | ||
| "painting-stroke-03-t", | ||
| "painting-stroke-04-t", | ||
| "painting-stroke-05-t", | ||
| "painting-stroke-07-t", | ||
| "painting-stroke-08-t", | ||
| "painting-stroke-09-t", | ||
| "paths-data-01-t", | ||
| "paths-data-02-t", | ||
| "paths-data-03-f", | ||
| "paths-data-04-t", | ||
| "paths-data-05-t", | ||
| "paths-data-06-t", | ||
| "paths-data-07-t", | ||
| "paths-data-08-t", | ||
| "paths-data-09-t", | ||
| "paths-data-10-t", | ||
| "paths-data-12-t", | ||
| "paths-data-13-t", | ||
| "paths-data-14-t", | ||
| "paths-data-15-t", | ||
| "paths-data-16-t", | ||
| "paths-data-17-f", | ||
| "paths-data-18-f", | ||
| "paths-data-19-f", | ||
| "paths-data-20-f", | ||
| "pservers-grad-01-b", | ||
| "pservers-grad-02-b", | ||
| "pservers-grad-04-b", | ||
| "pservers-grad-05-b", | ||
| "pservers-grad-07-b", | ||
| "pservers-grad-09-b", | ||
| "render-elems-01-t", | ||
| "render-elems-02-t", | ||
| "render-elems-03-t", | ||
| "shapes-circle-01-t", | ||
| "shapes-circle-02-t", | ||
| "shapes-ellipse-01-t", | ||
| "shapes-ellipse-02-t", | ||
| "shapes-ellipse-03-f", | ||
| "shapes-grammar-01-f", | ||
| "shapes-intro-01-t", | ||
| "shapes-line-01-t", | ||
| "shapes-line-02-f", | ||
| "shapes-polygon-01-t", | ||
| "shapes-polygon-02-t", | ||
| "shapes-polygon-03-t", | ||
| "shapes-polyline-01-t", | ||
| "shapes-polyline-02-t", | ||
| "shapes-rect-02-t", | ||
| "shapes-rect-04-f", | ||
| "shapes-rect-05-f", | ||
| "shapes-rect-06-f", | ||
| "struct-defs-01-t", | ||
| "struct-frag-01-t", | ||
| "struct-frag-06-t", | ||
| "struct-group-01-t", | ||
| "struct-image-01-t", | ||
| "struct-image-04-t", | ||
| "struct-use-03-t", | ||
| "styling-class-01-f", | ||
| "styling-css-01-b", | ||
| "styling-pres-01-t", | ||
| "types-basic-01-f", | ||
| ] | ||
|
|
||
| static let v12Refs: [String] = [ | ||
| "coords-trans-01-t", | ||
| "coords-trans-02-t", | ||
| "coords-trans-03-t", | ||
| "coords-trans-04-t", | ||
| "coords-trans-05-t", | ||
| "coords-trans-06-t", | ||
| "coords-trans-07-t", | ||
| "coords-trans-08-t", | ||
| "coords-trans-09-t", | ||
| "paint-color-03-t", | ||
| "paint-color-201-t", | ||
| "paint-fill-04-t", | ||
| "paint-fill-06-t", | ||
| "paint-stroke-01-t", | ||
| "paths-data-01-t", | ||
| "paths-data-02-t", | ||
| "render-elems-01-t", | ||
| "render-elems-02-t", | ||
| "render-elems-03-t", | ||
| "shapes-circle-01-t", | ||
| "shapes-ellipse-01-t", | ||
| "shapes-line-01-t", | ||
| "shapes-polygon-01-t", | ||
| "shapes-polyline-01-t", | ||
| "shapes-rect-02-t", | ||
| "struct-defs-01-t", | ||
| "struct-frag-01-t", | ||
| "struct-use-03-t", | ||
| ] | ||
|
|
||
| mutating func run() throws { | ||
| let inputURL = URL(fileURLWithPath: input) | ||
|
|
||
| guard FileManager.default.fileExists(atPath: input) else { | ||
| throw ValidationError("Input path '\(input)' does not exist") | ||
| } | ||
|
|
||
| let v11FolderURL = inputURL.appendingPathComponent("1.1F2") | ||
| let v12FolderURL = inputURL.appendingPathComponent("1.2T") | ||
|
|
||
| guard FileManager.default.fileExists(atPath: v11FolderURL.path) || FileManager.default.fileExists(atPath: v12FolderURL.path) else { | ||
| throw ValidationError("1.1F2/ or 1.2T/ folder does not exist in '\(input)'") | ||
| } | ||
|
|
||
| for ref in Self.v11Refs { | ||
| let svgURL = v11FolderURL.appending(path: "svg/\(ref).svg") | ||
| let svgContent = try serialize(inputURL: svgURL) | ||
| let refURL = v11FolderURL.appending(path: "refs/\(ref).ref") | ||
| try svgContent.write(to: refURL, atomically: true, encoding: .utf8) | ||
| } | ||
|
|
||
| for ref in Self.v12Refs { | ||
| let svgURL = v12FolderURL.appending(path: "svg/\(ref).svg") | ||
| let svgContent = try serialize(inputURL: svgURL) | ||
| let refURL = v12FolderURL.appending(path: "refs/\(ref).ref") | ||
| try svgContent.write(to: refURL, atomically: true, encoding: .utf8) | ||
| } | ||
| } | ||
|
|
||
| private func serialize(inputURL: URL) throws -> String { | ||
| guard FileManager.default.fileExists(atPath: input) else { | ||
| throw ValidationError("Input path '\(input)' does not exist") | ||
| } | ||
|
|
||
| guard let node = SVGParser.parse(contentsOf: inputURL) else { | ||
| throw ValidationError("Failed to parse SVG file") | ||
| } | ||
|
|
||
| return Serializer.serialize(node) | ||
| } | ||
| } | ||
| #endif |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # Derived values (DO NOT TOUCH). | ||
| CURRENT_MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) | ||
| CURRENT_MAKEFILE_DIR := $(patsubst %/,%,$(dir $(CURRENT_MAKEFILE_PATH))) | ||
|
|
||
| # If no target is specified, display help | ||
| .DEFAULT_GOAL := help | ||
|
|
||
| help: # Display this help. | ||
| @-+echo "Run make with one of the following targets:" | ||
| @-+echo | ||
| @-+grep -Eh "^[a-z-]+:.*#" $(CURRENT_MAKEFILE_PATH) | sed -E 's/^(.*:)(.*#+)(.*)/ \1 @@@ \3 /' | column -t -s "@@@" | ||
|
|
||
| test: # Run tests | ||
| swift test | ||
|
|
||
| generate-test-cases: # Generate test cases from w3c reference files | ||
| @cd Tests/SVGViewTests && \ | ||
| generateTest() { \ | ||
| local dir=$$1; \ | ||
| local class=$$2; \ | ||
| printf "// Generated by make generate-test-cases\n\n" > ../SVGViewTests/$$class.swift; \ | ||
| printf "import XCTest\n" >> ../SVGViewTests/$$class.swift; \ | ||
| printf "@testable import SVGView\n\n" >> ../SVGViewTests/$$class.swift; \ | ||
| printf "class $$class: BaseTestCase {\n\n" >> ../SVGViewTests/$$class.swift; \ | ||
| printf " override var dir: String {\n" >> ../SVGViewTests/$$class.swift; \ | ||
| printf " return \"$$dir\"\n" >> ../SVGViewTests/$$class.swift; \ | ||
| printf " }\n\n" >> ../SVGViewTests/$$class.swift; \ | ||
| find "w3c/$$dir/refs/" -type f -regex '.*\.ref$$' | sort | while read ref_file; do \ | ||
| name=$$(basename "$${ref_file%.*}"); \ | ||
| test_name=""; \ | ||
| IFS='-' read -ra arr <<< "$$name"; \ | ||
| for part in "$${arr[@]}"; do \ | ||
| test_name+=$$(printf "%s" "$${part:0:1}" | tr '[:lower:]' '[:upper:]')$${part:1}; \ | ||
| done; \ | ||
| printf " func test$$test_name() {\n" >> ../SVGViewTests/$$class.swift; \ | ||
| printf " compareToReference(\"$$name\")\n" >> ../SVGViewTests/$$class.swift; \ | ||
| printf " }\n\n" >> ../SVGViewTests/$$class.swift; \ | ||
| done; \ | ||
| printf "}" >> ../SVGViewTests/$$class.swift; \ | ||
| }; \ | ||
| generateTest "1.1F2" "SVG11Tests"; \ | ||
| generateTest "1.2T" "SVG12Tests" | ||
|
|
||
| update-references-snapshots: # Update .ref from .svg files | ||
| swift run GenerateReferencesCLI Tests/SVGViewTests/w3c/ | ||
|
|
||
| .PHONY: help test generate-test-cases update-references-snapshots |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
how to use