forked from CoreOffice/XMLCoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add prettyPrintIndentation property on XMLEncoder (CoreOffice#186)
New property can take `XMLEncoder.PrettyPrintIndentation` values such as `.tabs(1)` or `.spaces(2)`. Resolve CoreOffice#183.
- Loading branch information
1 parent
388ba82
commit 0d1c1b9
Showing
31 changed files
with
256 additions
and
121 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
{ | ||
"label": "swift test", | ||
"type": "shell", | ||
"command": "swift test" | ||
"command": "swift test --parallel" | ||
} | ||
] | ||
} |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,78 @@ | ||
// Copyright (c) 2020 XMLCoder contributors | ||
// | ||
// This software is released under the MIT License. | ||
// https://opensource.org/licenses/MIT | ||
|
||
import XCTest | ||
import XMLCoder | ||
|
||
private struct TopContainer: Encodable { | ||
let nested: NestedContainer | ||
} | ||
|
||
private struct NestedContainer: Encodable { | ||
let values: [String] | ||
} | ||
|
||
final class PrettyPrintTest: XCTestCase { | ||
private let testContainer = TopContainer(nested: NestedContainer(values: ["foor", "bar"])) | ||
|
||
func testDefaultIndentation() throws { | ||
let encoder = XMLEncoder() | ||
encoder.outputFormatting = [.prettyPrinted] | ||
|
||
let encoded = try encoder.encode(testContainer) | ||
|
||
XCTAssertEqual( | ||
String(data: encoded, encoding: .utf8)!, | ||
""" | ||
<TopContainer> | ||
<nested> | ||
<values>foor</values> | ||
<values>bar</values> | ||
</nested> | ||
</TopContainer> | ||
""" | ||
) | ||
} | ||
|
||
func testSpaces() throws { | ||
let encoder = XMLEncoder() | ||
encoder.outputFormatting = [.prettyPrinted] | ||
encoder.prettyPrintIndentation = .spaces(3) | ||
|
||
let encoded = try encoder.encode(testContainer) | ||
|
||
XCTAssertEqual( | ||
String(data: encoded, encoding: .utf8)!, | ||
""" | ||
<TopContainer> | ||
<nested> | ||
<values>foor</values> | ||
<values>bar</values> | ||
</nested> | ||
</TopContainer> | ||
""" | ||
) | ||
} | ||
|
||
func testTabs() throws { | ||
let encoder = XMLEncoder() | ||
encoder.outputFormatting = [.prettyPrinted] | ||
encoder.prettyPrintIndentation = .tabs(2) | ||
|
||
let encoded = try encoder.encode(testContainer) | ||
|
||
XCTAssertEqual( | ||
String(data: encoded, encoding: .utf8)!, | ||
""" | ||
<TopContainer> | ||
\t\t<nested> | ||
\t\t\t\t<values>foor</values> | ||
\t\t\t\t<values>bar</values> | ||
\t\t</nested> | ||
</TopContainer> | ||
""" | ||
) | ||
} | ||
} |
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
Oops, something went wrong.