-
Notifications
You must be signed in to change notification settings - Fork 55
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
Only unbox NSNumbers 0, 1 to Bool for objCType 'c' #181
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,10 @@ class JSONTests: XCTestCase { | |
XCTAssertEqual(JSONValue(rawValue: 3.1415 as NSNumber), .number(3.1415)) | ||
XCTAssertEqual(JSONValue(rawValue: false as NSNumber), .boolean(false)) | ||
XCTAssertEqual(JSONValue(rawValue: true as NSNumber), .boolean(true)) | ||
XCTAssertEqual(JSONValue(rawValue: false), .boolean(false)) | ||
XCTAssertEqual(JSONValue(rawValue: true), .boolean(true)) | ||
Comment on lines
+11
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure whether supporting passing unboxed Bool was intentional @1ec5, but the old implementation did allow it, so I kept the behavior and added tests to verify it. |
||
XCTAssertEqual(JSONValue(rawValue: 0 as NSNumber), .number(0)) | ||
XCTAssertEqual(JSONValue(rawValue: 1 as NSNumber), .number(1)) | ||
XCTAssertEqual(JSONValue(rawValue: ["Jason", 42, 3.1415, false, true, nil, [], [:]] as NSArray), | ||
.array(["Jason", 42, 3.1415, false, true, nil, [], [:]])) | ||
XCTAssertEqual(JSONValue(rawValue: [ | ||
|
@@ -245,5 +249,13 @@ class JSONTests: XCTestCase { | |
XCTAssertEqual(decodedValue?.rawValue as? NSDictionary, rawObject as NSDictionary) | ||
|
||
XCTAssertNoThrow(try JSONEncoder().encode(decodedValue)) | ||
|
||
// check decoding of 0/1 true/false to ensure unwanted conversions are avoided | ||
let rawString = "[0, 1, true, false]" | ||
// force-unwrap is safe since we control the input | ||
let serializedArrayFromString = rawString.data(using: .utf8)! | ||
XCTAssertNoThrow(decodedValue = try JSONDecoder().decode(JSONValue.self, from: serializedArrayFromString)) | ||
XCTAssertNotNil(decodedValue) | ||
XCTAssertEqual(.array([.number(0), .number(1), .boolean(true), .boolean(false)]), decodedValue) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is consistent with mapbox/mapbox-gl-native#6049 (comment). so I’m confident in this fix.