Skip to content

Inline snapshot testing output fails when URL request body expected contains carriage returns #771

Closed
@lukeredpath

Description

@lukeredpath

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions