Kaynağa Gözat

Add a test case for svg on macOS

onevcat 1 yıl önce
ebeveyn
işleme
00a5645bd2
1 değiştirilmiş dosya ile 22 ekleme ve 0 silme
  1. 22 0
      Tests/KingfisherTests/ImageExtensionTests.swift

+ 22 - 0
Tests/KingfisherTests/ImageExtensionTests.swift

@@ -344,4 +344,26 @@ class ImageExtensionTests: XCTestCase {
         // You can not "downsample" an image to a larger size.
         XCTAssertEqual(largerImage?.size, CGSize(width: 64, height: 64))
     }
+
+    #if os(macOS)
+    func testSVGImageSize() {
+        let svgString = """
+        <?xml version="1.0" encoding="UTF-8"?>
+        <svg width="100px" height="200px" viewBox="0 0 100 200" version="1.1" xmlns="http://www.w3.org/2000/svg">
+            <rect width="100" height="200" fill="red"/>
+        </svg>
+        """
+        
+        guard let data = svgString.data(using: .utf8),
+              let image = NSImage(data: data)
+        else {
+            XCTFail("Failed to create image from SVG data")
+            return
+        }
+        
+        let size = image.kf.size
+        XCTAssertEqual(size.width, 100)
+        XCTAssertEqual(size.height, 200)
+    }
+    #endif
 }