Skip to content

Commit

Permalink
优化Tests脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
Mccc committed Dec 10, 2024
1 parent 3099b8a commit b4317d4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
5 changes: 5 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ let package = Package(

],
path: "SmartCodable/Classes"
),
.testTarget(
name: "SmartCodableTests",
dependencies: ["SmartCodable"]
)

],
swiftLanguageVersions: [.v5]
)
33 changes: 25 additions & 8 deletions Tests/Example.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit b4317d4

Please sign in to comment.