@@ -197,6 +197,56 @@ final class HashComputationTests: XCTestCase {
197197 XCTAssertEqual ( HashAlgorithm . crc32. rawValue, " crc32 " )
198198 }
199199
200+ // MARK: - Error Tests
201+
202+ func testHashComputationError_AlgorithmNotSupported( ) {
203+ let error = HashComputationError . algorithmNotSupported ( " test-algorithm " )
204+
205+ XCTAssertEqual ( error. errorDescription, " Hash algorithm 'test-algorithm' is not supported on this platform " )
206+ }
207+
208+ func testHashComputationError_ComputationFailed( ) {
209+ let error = HashComputationError . computationFailed ( " test error message " )
210+
211+ XCTAssertEqual ( error. errorDescription, " Hash computation failed: test error message " )
212+ }
213+
214+ // MARK: - Data Extension Tests
215+
216+ func testDataExtension_SHA256( ) {
217+ let data = " Test Data " . data ( using: . utf8) !
218+ let hash = data. sha256
219+
220+ // SHA256 produces 32 bytes
221+ XCTAssertEqual ( hash. count, 32 )
222+ XCTAssertFalse ( hash. isEmpty)
223+ }
224+
225+ func testDataExtension_SHA256Hex( ) {
226+ let data = " Test Data " . data ( using: . utf8) !
227+ let hex = data. sha256Hex
228+
229+ // SHA256 hex should be 64 characters (32 bytes * 2)
230+ XCTAssertEqual ( hex. count, 64 )
231+ XCTAssertFalse ( hex. isEmpty)
232+
233+ // Should match manual computation
234+ let manualHex = try ! HashComputation . computeHashHex ( data: data, algorithm: . sha256)
235+ XCTAssertEqual ( hex, manualHex)
236+ }
237+
238+ func testDataExtension_EmptyDataFallback( ) {
239+ // Test that extensions handle errors gracefully
240+ let data = Data ( )
241+
242+ let hash = data. sha256
243+ let hex = data. sha256Hex
244+
245+ // Should not crash, should return empty/default values
246+ XCTAssertEqual ( hash. count, 32 ) // SHA256 of empty data
247+ XCTAssertEqual ( hex. count, 64 )
248+ }
249+
200250 // MARK: - Performance Tests
201251
202252 func testPerformance_SHA256( ) {
0 commit comments