Skip to content

Commit

Permalink
add a test for serializeToFlatDictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
noppoMan committed Jul 11, 2017
1 parent d7e3e44 commit 65a012d
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion Tests/AWSSDKSwiftCoreTests/SerializableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,40 @@ typealias Serializable = DictionarySerializable & XMLNodeSerializable
class SerializableTests: XCTestCase {

struct B: Serializable {
public static var parsingHints: [AWSShapeProperty] = [
AWSShapeProperty(label: "a", required: true, type: .string),
AWSShapeProperty(label: "b", required: false, type: .list),
AWSShapeProperty(label: "c", required: true, type: .list)
]

let a = "1"
let b = [1, 2]
let c = ["key": "value"]
}

struct C: Serializable {
public static var parsingHints: [AWSShapeProperty] = [
AWSShapeProperty(label: "value", required: true, type: .string)
]

let value = "hello"
}

struct D: Serializable {
public static var parsingHints: [AWSShapeProperty] = [
AWSShapeProperty(label: "value", required: true, type: .string)
]

let value = "world"
}

struct A: Serializable {
public static var parsingHints: [AWSShapeProperty] = [
AWSShapeProperty(label: "structure", required: true, type: .structure),
AWSShapeProperty(label: "structures", required: false, type: .list),
AWSShapeProperty(label: "array", required: true, type: .list)
]

let structure = B()
let structures: [Serializable] = [C(), D()]
let array = ["foo", "bar"]
Expand All @@ -37,7 +57,8 @@ class SerializableTests: XCTestCase {
static var allTests : [(String, (SerializableTests) -> () throws -> Void)] {
return [
("testSerializeToXML", testSerializeToXML),
("testSerializeToDictionaryAndJSON", testSerializeToDictionaryAndJSON)
("testSerializeToDictionaryAndJSON", testSerializeToDictionaryAndJSON),
("testSerializeToFlatDictionary", testSerializeToFlatDictionary)
]
}

Expand All @@ -57,4 +78,13 @@ class SerializableTests: XCTestCase {
XCTAssertEqual(dict.count, jsonObect.count)
}

func testSerializeToFlatDictionary() {
let dict = try! A().serializeToFlatDictionary()
XCTAssertEqual(dict.count, 8)
XCTAssertEqual(dict["structure.a"] as? String, "1")
XCTAssertEqual(dict["structure.c.key"] as? String, "value")
XCTAssertEqual(dict["array.member.1"] as? String, "foo")
XCTAssertEqual(dict["array.member.2"] as? String, "bar")
}

}

0 comments on commit 65a012d

Please sign in to comment.