Skip to content

Commit

Permalink
Merge branch 'master' of github.com:nickoneill/Storage
Browse files Browse the repository at this point in the history
  • Loading branch information
nickoneill committed May 19, 2016
2 parents deedd20 + 760d3e7 commit f879d2b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Pantry/Storable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public enum StorageExpiry {
/**
Default storable types

Default types are `Bool`, `String`, `Int`, `Float`, `Double`
Default types are `Bool`, `String`, `Int`, `Float`, `Double`, `NSDate`
*/
public protocol StorableDefaultType {
}
Expand All @@ -101,6 +101,7 @@ extension String: StorableDefaultType { }
extension Int: StorableDefaultType { }
extension Float: StorableDefaultType { }
extension Double: StorableDefaultType { }
extension NSDate: StorableDefaultType { }

// MARK: Enums with Raw Values

Expand Down
16 changes: 16 additions & 0 deletions PantryTests/MemoryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ class MemoryTests: XCTestCase {
let string: String = "Hello"
let int: Int = 4
let float: Float = 10.2
let double: Double = 12.7
let date: NSDate = NSDate(timeIntervalSince1970: 1459355217)

Pantry.pack(string, key: "ourTestString")
Pantry.pack(int, key: "ourTestInt")
Pantry.pack(float, key: "ourTestFloat")
Pantry.pack(double,key: "ourTestDouble")
Pantry.pack(date, key: "ourTestDate")

if let unpackedString: String = Pantry.unpack("ourTestString") {
XCTAssert(unpackedString == "Hello", "default string was incorrect")
Expand All @@ -45,6 +49,18 @@ class MemoryTests: XCTestCase {
} else {
XCTFail("no default float could be unpacked")
}
if let unpackedDouble: Double = Pantry.unpack("ourTestDouble") {
XCTAssert(unpackedDouble == 12.7 , "default double was incorrect")
}
else {
XCTFail("no default double could be unpacked")
}
if let unpackedDate: NSDate = Pantry.unpack("ourTestDate") {
XCTAssert(unpackedDate.timeIntervalSince1970 == 1459355217 , "default date was incorrect")
}
else {
XCTFail("no default double could be unpacked")
}
}

// nested storable types
Expand Down
10 changes: 9 additions & 1 deletion PantryTests/PantryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ class PantryTests: XCTestCase {
let int: Int = 4
let float: Float = 10.2
let double: Double = 20.6

let date: NSDate = NSDate(timeIntervalSince1970: 1459355217)

Pantry.pack(string, key: "ourTestString")
Pantry.pack(int, key: "ourTestInt")
Pantry.pack(float, key: "ourTestFloat")
Pantry.pack(double, key: "ourTestDouble")
Pantry.pack(date, key: "ourTestDate")

if let unpackedString: String = Pantry.unpack("ourTestString") {
XCTAssert(unpackedString == "Hello", "default string was incorrect")
Expand All @@ -64,6 +66,12 @@ class PantryTests: XCTestCase {
} else {
XCTFail("no default double could be unpacked")
}
if let unpackedDate: NSDate = Pantry.unpack("ourTestDate") {
XCTAssert(unpackedDate.timeIntervalSince1970 == 1459355217 , "default date was incorrect")
}
else {
XCTFail("no default double could be unpacked")
}
}

func testDefaultArray() {
Expand Down

0 comments on commit f879d2b

Please sign in to comment.