Skip to content

Commit d9cbb20

Browse files
committed
testRasterize
1 parent 0c5d464 commit d9cbb20

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

SwiftDrawTests/Parser.SVGTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
import XCTest
3434
@testable import SwiftDraw
3535

36-
final class SVGTests: XCTestCase {
37-
36+
final class ParserSVGTests: XCTestCase {
37+
3838
func testSVG() throws {
3939
let node = XML.Element(name: "svg", attributes: ["width": "100", "height": "200"])
4040
let parser = XMLParser()

SwiftDrawTests/ImageTests.swift renamed to SwiftDrawTests/SVGTests.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// ScannerTests.swift
2+
// SVGTests.swift
33
// SwiftDraw
44
//
55
// Created by Simon Whitty on 19/11/18.
@@ -32,7 +32,7 @@
3232
import XCTest
3333
@testable import SwiftDraw
3434

35-
final class ImageTests: XCTestCase {
35+
final class SVGTests: XCTestCase {
3636

3737
func testValidSVGLoads() {
3838
XCTAssertNotNil(SVG(named: "lines.svg", in: .test))
@@ -73,6 +73,20 @@ final class ImageTests: XCTestCase {
7373
}
7474
#endif
7575

76+
#if canImport(UIKit)
77+
func testRasterize() {
78+
let svg = SVG(named: "gradient-apple.svg", in: .test)!
79+
let image = svg.rasterize(with: CGSize(width: 100, height: 100), scale: 3)
80+
XCTAssertEqual(image.size, CGSize(width: 100, height: 100))
81+
XCTAssertEqual(image.scale, 3)
82+
83+
let data = image.pngData()!
84+
let reloaded = UIImage(data: data)!
85+
XCTAssertEqual(reloaded.size, CGSize(width: 300, height: 300))
86+
XCTAssertEqual(reloaded.scale, 1)
87+
}
88+
#endif
89+
7690
}
7791

7892
private extension SVG {

0 commit comments

Comments
 (0)