Skip to content

TestNSDictionary: Add encoding and decoding test for NSCoding #2322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions TestFoundation/TestNSDictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,13 @@ class TestNSDictionary : XCTestCase {
XCTAssertEqual(dictionary[3 as NSNumber] as? String, "k")
}

func test_NSCoding() {
let original: NSDictionary = ["foo": "bar"]
let encodedData = NSKeyedArchiver.archivedData(withRootObject: original)
let decoded = NSKeyedUnarchiver.unarchiveObject(with: encodedData) as! NSDictionary
XCTAssertEqual(original, decoded, "Archived then unarchived `NSDictionary` must be equal.")
}

static var allTests: [(String, (TestNSDictionary) -> () throws -> Void)] {
return [
("test_BasicConstruction", test_BasicConstruction),
Expand All @@ -270,6 +277,7 @@ class TestNSDictionary : XCTestCase {
("test_valueForKey", test_valueForKey),
("test_valueForKeyWithNestedDict", test_valueForKeyWithNestedDict),
("test_sharedKeySets", test_sharedKeySets),
("test_NSCoding", test_NSCoding),
]
}
}