File tree 3 files changed +24
-3
lines changed
Tests/GeneratorEngineTests
3 files changed +24
-3
lines changed Original file line number Diff line number Diff line change 2
2
//
3
3
// This source file is part of the Swift open source project
4
4
//
5
- // Copyright (c) 2023 Apple Inc. and the Swift project authors
5
+ // Copyright (c) 2023-2024 Apple Inc. and the Swift project authors
6
6
// Licensed under Apache License v2.0 with Runtime Library Exception
7
7
//
8
8
// See https://swift.org/LICENSE.txt for license information
Original file line number Diff line number Diff line change 2
2
//
3
3
// This source file is part of the Swift open source project
4
4
//
5
- // Copyright (c) 2023 Apple Inc. and the Swift project authors
5
+ // Copyright (c) 2023-2024 Apple Inc. and the Swift project authors
6
6
// Licensed under Apache License v2.0 with Runtime Library Exception
7
7
//
8
8
// See https://swift.org/LICENSE.txt for license information
@@ -124,9 +124,15 @@ extension HashEncoder: SingleValueEncodingContainer {
124
124
}
125
125
126
126
func encode< T> ( _ value: T ) throws where T: Encodable {
127
+ if let leaf = value as? LeafCacheKey {
128
+ leaf. hash ( with: & self . hashFunction)
129
+ return
130
+ }
131
+
127
132
guard value is CacheKey else {
128
133
throw Error . noCacheKeyConformance ( T . self)
129
134
}
135
+
130
136
try String ( describing: T . self) . encode ( to: self )
131
137
try value. encode ( to: self )
132
138
}
Original file line number Diff line number Diff line change 2
2
//
3
3
// This source file is part of the Swift open source project
4
4
//
5
- // Copyright (c) 2023 Apple Inc. and the Swift project authors
5
+ // Copyright (c) 2023-2024 Apple Inc. and the Swift project authors
6
6
// Licensed under Apache License v2.0 with Runtime Library Exception
7
7
//
8
8
// See https://swift.org/LICENSE.txt for license information
@@ -98,6 +98,21 @@ struct Expression: CachingQuery {
98
98
}
99
99
100
100
final class EngineTests : XCTestCase {
101
+ func testFilePathHashing( ) throws {
102
+ let path = " /root "
103
+
104
+ let hashEncoder1 = HashEncoder < SHA256 > ( )
105
+ try hashEncoder1. encode ( FilePath ( path) )
106
+ let digest1 = hashEncoder1. finalize ( )
107
+
108
+ let hashEncoder2 = HashEncoder < SHA256 > ( )
109
+ try hashEncoder2. encode ( String ( reflecting: FilePath . self) )
110
+ try hashEncoder2. encode ( path)
111
+ let digest2 = hashEncoder2. finalize ( )
112
+
113
+ XCTAssertEqual ( digest1, digest2)
114
+ }
115
+
101
116
func testSimpleCaching( ) async throws {
102
117
let engine = Engine (
103
118
VirtualFileSystem ( ) ,
You can’t perform that action at this time.
0 commit comments