Skip to content

Commit 3d1fb54

Browse files
committed
Update errors and more tests
1 parent 73efb1f commit 3d1fb54

35 files changed

+1287
-927
lines changed

.swift-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6.1.0

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:6.0
1+
// swift-tools-version:6.1
22
import PackageDescription
33

44
let package = Package(

Sources/LeafKit/Character+Identities.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// swift-format-ignore
12
/// Various helper identities for convenience
23
extension Character {
34

@@ -6,7 +7,7 @@ extension Character {
67
var isValidInTagName: Bool {
78
self.isLowercaseLetter || self.isUppercaseLetter
89
}
9-
10+
1011
var isValidInParameter: Bool {
1112
self.isValidInTagName ||
1213
self.isValidOperator ||
@@ -45,9 +46,9 @@ extension Character {
4546
false
4647
}
4748
}
48-
49+
4950
// MARK: - General group-membership identities (Internal)
50-
51+
5152
var isHexadecimal: Bool {
5253
(.zero ... .nine).contains(self) ||
5354
(.A ... .F).contains(self) ||
@@ -70,7 +71,7 @@ extension Character {
7071
var isLowercaseLetter: Bool {
7172
(.a ... .z).contains(self)
7273
}
73-
74+
7475
// MARK: - General helpers
7576

7677
static let newLine: Self = "\n"

Sources/LeafKit/LeafAST.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import NIOCore
33
/// `LeafAST` represents a "compiled," grammatically valid Leaf template (which may or may not be fully resolvable or erroring)
44
public struct LeafAST: Hashable, Sendable {
55
// MARK: - Public
6-
6+
77
public func hash(into hasher: inout Hasher) {
88
hasher.combine(self.name)
99
}
@@ -23,7 +23,7 @@ public struct LeafAST: Hashable, Sendable {
2323

2424
self.updateRefs([:])
2525
}
26-
26+
2727
init(from: LeafAST, referencing externals: [String: LeafAST]) {
2828
self.name = from.name
2929
self.ast = from.ast
@@ -39,9 +39,9 @@ public struct LeafAST: Hashable, Sendable {
3939
private(set) var externalRefs = Set<String>()
4040
private(set) var unresolvedRefs = Set<String>()
4141
private(set) var flat: Bool
42-
42+
4343
// MARK: - Private Only
44-
44+
4545
private var rawAST: [Syntax]?
4646

4747
mutating private func updateRefs(_ externals: [String: LeafAST]) {
@@ -69,7 +69,7 @@ public struct LeafAST: Hashable, Sendable {
6969
pos = self.ast.index(after: pos)
7070
continue
7171
}
72-
72+
7373
// replace the original Syntax with the results of inlining, potentially 1...n
7474
let replacementSyntax = self.ast[pos].inlineRefs(providedExts, [:])
7575
self.ast.replaceSubrange(pos...pos, with: replacementSyntax)

Sources/LeafKit/LeafCache/DefaultLeafCache.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public actor DefaultLeafCache: LeafCache {
2020

2121
/// - Parameters:
2222
/// - document: The `LeafAST` to store
23-
/// - loop: `EventLoop` to return futures on
2423
/// - replace: If a document with the same name is already cached, whether to replace or not.
2524
/// - Returns: The document provided as an identity return
2625
public func insert(_ document: LeafAST, replace: Bool = false) async throws -> LeafAST {
@@ -32,7 +31,7 @@ public actor DefaultLeafCache: LeafCache {
3231
// return an error if replace is false and the document name is already in cache
3332
switch (self.cache.keys.contains(document.name), replace) {
3433
case (true, false):
35-
throw LeafError(.keyExists(document.name))
34+
throw LeafError.keyExists(document.name)
3635
default:
3736
self.cache[document.name] = document
3837
}
@@ -41,8 +40,7 @@ public actor DefaultLeafCache: LeafCache {
4140

4241
/// - Parameters:
4342
/// - documentName: Name of the `LeafAST` to try to return
44-
/// - loop: `EventLoop` to return futures on
45-
/// - Returns: `EventLoopFuture<LeafAST?>` holding the `LeafAST` or nil if no matching result
43+
/// - Returns: ``LeafAST` or nil if no matching result
4644
public func retrieve(documentName: String) async throws -> LeafAST? {
4745
guard self.isEnabled else {
4846
return nil
@@ -52,12 +50,11 @@ public actor DefaultLeafCache: LeafCache {
5250

5351
/// - Parameters:
5452
/// - documentName: Name of the `LeafAST` to try to purge from the cache
55-
/// - loop: `EventLoop` to return futures on
56-
/// - Returns: `EventLoopFuture<Bool?>` - If no document exists, returns nil. If removed,
53+
/// - Returns: If no document exists, returns nil. If removed,
5754
/// returns true. If cache can't remove because of dependencies (not yet possible), returns false.
5855
public func remove(_ documentName: String) async throws -> Bool? {
5956
guard self.isEnabled else {
60-
throw LeafError(.cachingDisabled)
57+
throw LeafError.cachingDisabled()
6158
}
6259

6360
guard self.cache[documentName] != nil else {
@@ -73,10 +70,10 @@ public actor DefaultLeafCache: LeafCache {
7370
/// Blocking file load behavior
7471
func retrieve(documentName: String) throws -> LeafAST? {
7572
guard self.isEnabled else {
76-
throw LeafError(.cachingDisabled)
73+
throw LeafError.cachingDisabled()
7774
}
7875
guard let result = self.cache[documentName] else {
79-
throw LeafError(.noValueForKey(documentName))
76+
throw LeafError.noValueForKey(documentName)
8077
}
8178
return result
8279
}

Sources/LeafKit/LeafCache/LeafCache.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import NIOCore
55
/// The stored `LeafAST`s may or may not be fully renderable templates, and generally speaking no
66
/// attempts should be made inside a `LeafCache` adherent to make any changes to the stored document.
77
///
8-
/// All definied access methods to a `LeafCache` adherent must guarantee `EventLoopFuture`-based
8+
/// All definied access methods to a `LeafCache` adherent must guarantee async-await-based
99
/// return values. For performance, an adherent may optionally provide additional, corresponding interfaces
1010
/// where returns are direct values and not future-based by adhering to `SynchronousLeafCache` and
1111
/// providing applicable option flags indicating which methods may be used. This should only used for

0 commit comments

Comments
 (0)