From b4317d42416cc8e38bce96bf71aa3b3608ae15c8 Mon Sep 17 00:00:00 2001 From: Mccc <> Date: Tue, 10 Dec 2024 18:14:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96Tests=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Package.swift | 5 +++++ Tests/Example.swift | 33 +++++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/Package.swift b/Package.swift index 26a7305..fbc445d 100644 --- a/Package.swift +++ b/Package.swift @@ -20,7 +20,12 @@ let package = Package( ], path: "SmartCodable/Classes" + ), + .testTarget( + name: "SmartCodableTests", + dependencies: ["SmartCodable"] ) + ], swiftLanguageVersions: [.v5] ) diff --git a/Tests/Example.swift b/Tests/Example.swift index e9d6022..af76910 100644 --- a/Tests/Example.swift +++ b/Tests/Example.swift @@ -17,18 +17,35 @@ class Tests: XCTestCase { func testBase() { + let dict: [String: Any] = [ + "name": "Mccc", + "age": 10, + "sex": 1 + ] + + guard let model = Smart.deserialize(from: dict) else { + XCTFail("反序列化失败") + return + } + XCTAssertEqual(model.name, "Mccc", "Smart 的 name 应该被正确处理为字符串 'Mccc'") + XCTAssertEqual(model.age, 10, "Smart 的 age 应该被正确处理为Int '10'") + XCTAssertEqual(model.sex, Smart.Sex.man, "Smart 的 sex 应该被正确的处理为 Sex枚举 ‘Sex.man’") + + print(model) + } - + } - - - - - // SmartCodable struct Smart: SmartCodable { var name: String? - - + var age: Int? + var sex: Sex? + + enum Sex: Int, SmartCaseDefaultable { + case man = 1 + case women = 0 + } +}