-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from FelixHerrmann/feature/custom-packages-file
[Feature] Custom Packages File
- Loading branch information
Showing
8 changed files
with
123 additions
and
14 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// CustomPackages.swift | ||
// SwiftPackageList | ||
// | ||
// Created by Felix Herrmann on 17.02.25. | ||
// | ||
|
||
import Foundation | ||
import SwiftPackageList | ||
|
||
public struct CustomPackages: File { | ||
public let url: URL | ||
|
||
public init(url: URL) { | ||
self.url = url | ||
} | ||
} | ||
|
||
extension CustomPackages { | ||
public func packages() throws -> [Package] { | ||
let data = try Data(contentsOf: url) | ||
let decoder = JSONDecoder() | ||
return try decoder.decode([Package].self, from: data) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// CustomPackagesTests.swift | ||
// SwiftPackageList | ||
// | ||
// Created by Felix Herrmann on 17.02.25. | ||
// | ||
|
||
import XCTest | ||
@testable import SwiftPackageListCore | ||
|
||
final class CustomPackagesTests: XCTestCase { | ||
func testPackageParsing() throws { | ||
let url = Bundle.module.url( | ||
forResource: "custom-packages", | ||
withExtension: ".json", | ||
subdirectory: "Resources/CustomPackages" | ||
) | ||
let unwrappedURL = try XCTUnwrap(url) | ||
let customPackages = CustomPackages(url: unwrappedURL) | ||
let package = try XCTUnwrap(try customPackages.packages().first) | ||
|
||
XCTAssertEqual(package.branch, "branch-test") | ||
XCTAssertEqual(package.identity, "identity-test") | ||
XCTAssertEqual(package.license, "license-test") | ||
XCTAssertEqual(package.location, "location-tes") | ||
XCTAssertEqual(package.name, "name-test") | ||
XCTAssertEqual(package.revision, "revision-test") | ||
XCTAssertEqual(package.version, "version-test") | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Tests/SwiftPackageListCoreTests/Resources/CustomPackages/custom-packages.json
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[ | ||
{ | ||
"branch": "branch-test", | ||
"identity" : "identity-test", | ||
"license" : "license-test", | ||
"location" : "location-tes", | ||
"name" : "name-test", | ||
"revision": "revision-test", | ||
"version": "version-test" | ||
} | ||
] |