Skip to content
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

Some house keeping #65

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
disabled_rules:
- line_length
- trailing_comma
- redundant_optional_initialization

opt_in_rules:
Expand All @@ -10,3 +9,8 @@ included:
excluded:
.build

trailing_comma:
mandatory_comma: true

vertical_whitespace:
max_empty_lines: 2
14 changes: 7 additions & 7 deletions Sources/ScreamURITemplate/VariableValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,35 @@ public protocol VariableValue {
}

public protocol StringVariableValue: VariableValue {
func asStringVariableValue() -> String
func asString() -> String
}

public extension StringVariableValue {
func asTypedVariableValue() -> TypedVariableValue? {
.string(asStringVariableValue())
.string(asString())
}
}

extension [StringVariableValue]: VariableValue {
public func asTypedVariableValue() -> TypedVariableValue? {
.list(map { $0.asStringVariableValue() })
.list(map { $0.asString() })
}
}

extension KeyValuePairs<String, StringVariableValue>: VariableValue {
public func asTypedVariableValue() -> TypedVariableValue? {
.associativeArray(map { ($0, $1.asStringVariableValue()) })
.associativeArray(map { ($0, $1.asString()) })
}
}

extension [String: StringVariableValue]: VariableValue {
public func asTypedVariableValue() -> TypedVariableValue? {
.associativeArray(map { ($0, $1.asStringVariableValue()) }.sorted { $0.0 < $1.0 })
.associativeArray(map { ($0, $1.asString()) }.sorted { $0.0 < $1.0 })
}
}

public extension LosslessStringConvertible {
func asStringVariableValue() -> String {
func asString() -> String {
description
}
}
Expand All @@ -79,7 +79,7 @@ extension UInt8: StringVariableValue {}
extension Unicode.Scalar: StringVariableValue {}

extension UUID: StringVariableValue {
public func asStringVariableValue() -> String {
public func asString() -> String {
uuidString
}
}
8 changes: 5 additions & 3 deletions Sources/ScreamURITemplateExample/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ import Foundation
import ScreamURITemplate

let template = try URITemplate(string: "https://api.github.com/repos/{owner}/{repo}/collaborators/{username}")
let variables = ["owner": "SwiftScream",
"repo": "URITemplate",
"username": "alexdeem"]
let variables = [
"owner": "SwiftScream",
"repo": "URITemplate",
"username": "alexdeem",
]

let urlString = try template.process(variables: variables)

Expand Down
16 changes: 10 additions & 6 deletions Tests/ScreamURITemplateTests/Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ class Tests: XCTestCase {

func testStringStringDictionary() throws {
let template: URITemplate = "https://api.github.com/repos/{owner}/{repo}/collaborators/{username}"
let variables = ["owner": "SwiftScream",
"repo": "URITemplate",
"username": "alexdeem"]
let variables = [
"owner": "SwiftScream",
"repo": "URITemplate",
"username": "alexdeem",
]
let urlString = try template.process(variables: variables)
XCTAssertEqual(urlString, "https://api.github.com/repos/SwiftScream/URITemplate/collaborators/alexdeem")
}
Expand Down Expand Up @@ -177,9 +179,11 @@ class Tests: XCTestCase {

func testProcessPerformance() {
let template: URITemplate = "https://api.github.com/repos/{owner}/{repo}/collaborators/{username}"
let variables = ["owner": "SwiftScream",
"repo": "URITemplate",
"username": "alexdeem"]
let variables = [
"owner": "SwiftScream",
"repo": "URITemplate",
"username": "alexdeem",
]

measure {
for _ in 1...5000 {
Expand Down