Inline snapshot testing output fails when URL request body expected contains carriage returns
lukeredpath opened this issue · comments
Describe the bug
I'm converting our assertion helper that tests our API client routes generate the correct URL requests over to the new inline snapshot tool. It works well except for one test that uses my swift-url-routing-multipart
extension to create a multipart request body. This intentionally contains \r\n
line breaks, but these get converted to \n
when written into the source file using the .raw
strategy, causing the test to fail when re-run.
func testCarriageReturnInlineSnapshot() {
let string = "This is a line\r\nAnd this is a line\r\n"
var request = URLRequest(url: URL(string: "https://www.example.com")!)
request.httpMethod = "POST"
request.httpBody = string.data(using: .utf8)!
assertInlineSnapshot(of: request, as: .raw) {
"""
POST https://www.example.com
This is a line
And this is a line
"""
}
}
Expected behavior
I'd expect the original line breaks to be preserved.
Environment
- swift-snapshot-testing 1.13.0
- Xcode 14.3
- OS: iOS 16
Strange! The \r
is definitely preserved in the syntax we're writing, so this is probably an issue of Xcode's line ending settings. Either way carriage returns are probably an important thing to verify, so I've opened #772 to address.
I've tested out the above fix and it has resolved my issue.