Skip to content

Commit

Permalink
start making tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmossas committed Aug 9, 2024
1 parent 42849d4 commit 020226d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public struct ObjectWithEveryType: ExampleClientModel {
self.uint32 <- map["uint32"]
self.int64 <- map["int64"]
self.uint64 <- map["uint64"]
self.`enum` <- map["enum"] // TODO
self.`enum` <- map["enum"] is String ? Enumerator(string: map["enum"] as String) : Enumerator.foo // TODO
self.object <- map["object"] // TODO
self.array <- map["array"] // TODO
self.record <- map["record"] // TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,39 @@ import XCTest

final class ObjectWithEveryTypeTests: XCTestCase {
let location = "../../../tests/test-files/ObjectWithEveryType.json"
let control = ObjectWithEveryType()
let control = ObjectWithEveryType(
string: "",
boolean: false,
timestamp: targetDate,
float32: 1.5,
float64: 1.5,
int8: 1,
uint8: 1,
int16: 10,
uint16: 10,
int32: 100,
uint32: 100,
int64: 1000,
uint64: 1000,
enum: Enumerator.baz,
object: NestedObject(id: "1", content: "hello world"),
array: [true, false, false],
record: Dictionary(dictionaryLiteral: ("A", true), ("B", false)),
discriminator: Discriminator.c(
DiscriminatorC(
id: "",
name: "",
date: targetDate
)
),
any: "hello world")

func testFromJson() throws {

let objectJson = try String(contentsOfFile: location, encoding: .utf8)
let result1 = ObjectWithEveryType(JSONString: objectJson) ?? ObjectWithEveryType()
let result2 = ObjectWithEveryType(JSONString: control.toJSONString() ?? "") ?? ObjectWithEveryType()
XCTAssertEqual(result1, control)
XCTAssertEqual(result2, control)
XCTAssertEqual(result1, result2)
}
}

0 comments on commit 020226d

Please sign in to comment.