This repository has been archived by the owner on Aug 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed crash when serializing an invalid dictionary
- Loading branch information
1 parent
2682560
commit 26b8fe2
Showing
3 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// DictionaryExtensionTests.swift | ||
// EosioSwiftTests | ||
|
||
// Created by Paul Kim on 10/22/19 | ||
// Copyright (c) 2017-2019 block.one and its contributors. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
|
||
class DictionaryExtensionTests: XCTestCase { | ||
|
||
func testJsonStringWithValidDictionaryReturnsCorrectJsonString() { | ||
let dict: [String: Any?] = ["string": "string", | ||
"integer": 1, | ||
"nil": nil, | ||
"array": ["a", "b", "c"], | ||
"dict": ["key": "value"]] | ||
let expectedJsonString = "{\"array\":[\"a\",\"b\",\"c\"],\"dict\":{\"key\":\"value\"},\"integer\":1,\"nil\":null,\"string\":\"string\"}" | ||
|
||
guard let resultingJsonString = dict.jsonString else { | ||
return XCTFail("jsonString on valid dictionary returns nil.") | ||
} | ||
XCTAssertEqual(resultingJsonString, expectedJsonString) | ||
} | ||
|
||
func testJsonStringWithInvalidDictionaryReturnsNil() { | ||
let dict: [String: Any?] = ["string": "string", | ||
"integer": 1, | ||
"nil": nil, | ||
"array": ["a", "b", "c"], | ||
"dict": ["key": "value"], | ||
"enum": Calendar.Identifier.gregorian] | ||
|
||
let resultingJsonString = dict.jsonString | ||
XCTAssertNil(resultingJsonString, "jsonString on invalid dictionary returns non-nil.") | ||
} | ||
|
||
} |