forked from CoreOffice/XMLCoder
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a bug when decoding a key with one character only (CoreOffice#96)
I found an issue with the `convertFromCapitalized` key decoding strategy which threw an error when the key had just one characted. * Fix a bug when decoding a key with one character only * Add KeyDecodingStrategyTest
- Loading branch information
Showing
3 changed files
with
36 additions
and
3 deletions.
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// KeyDecodingStrategyTest.swift | ||
// XMLCoder | ||
// | ||
// Created by Max Desiatov on 02/05/2019. | ||
// | ||
|
||
import XCTest | ||
@testable import XMLCoder | ||
|
||
private let capitalized = """ | ||
<si><T>blah</T></si> | ||
""".data(using: .utf8)! | ||
|
||
private struct Item: Codable, Equatable { | ||
public let text: String | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case text = "t" | ||
} | ||
} | ||
|
||
final class KeyDecodingStrategyTest: XCTestCase { | ||
func testCapitalized() throws { | ||
let decoder = XMLDecoder() | ||
decoder.keyDecodingStrategy = .convertFromCapitalized | ||
let result = try decoder.decode(Item.self, from: capitalized) | ||
XCTAssertEqual(result.text, "blah") | ||
} | ||
} |
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