Initial implementation

This commit is contained in:
Mattt Zmuda 2025-02-11 09:27:37 -08:00
commit be1e9583f8
No known key found for this signature in database

View file

@ -0,0 +1,51 @@
import Testing
import class Foundation.JSONDecoder
import class Foundation.JSONEncoder
import struct Foundation.UUID
@testable import MCP
@Suite("ID Tests")
struct IDTests {
@Test("String ID initialization and encoding")
func testStringID() throws {
let id: ID = "test-id"
#expect(id.description == "test-id")
let encoder = JSONEncoder()
let decoder = JSONDecoder()
let data = try encoder.encode(id)
let decoded = try decoder.decode(ID.self, from: data)
#expect(decoded == id)
}
@Test("Number ID initialization and encoding")
func testNumberID() throws {
let id: ID = 42
#expect(id.description == "42")
let encoder = JSONEncoder()
let decoder = JSONDecoder()
let data = try encoder.encode(id)
let decoded = try decoder.decode(ID.self, from: data)
#expect(decoded == id)
}
@Test("Random ID generation")
func testRandomID() throws {
let id1 = ID.random
let id2 = ID.random
#expect(id1 != id2, "Random IDs should be unique")
if case .string(let str) = id1 {
#expect(!str.isEmpty)
// Verify it's a valid UUID string
#expect(UUID(uuidString: str) != nil)
} else {
#expect(Bool(false), "Random ID should be string type")
}
}
}