Skip to content
Snippets Groups Projects
Select Git revision
  • bfca8d844e5c36fe09712b3bea609e2a12b13644
  • main default protected
  • dev protected
  • hotfixes-oct-2022
  • refactor/avatar-cell
  • 1.1.5
  • 1.1.4
  • 1.1.3
  • 1.1
  • 1.0.8
  • 1.0.7
  • 1.0.6
12 results

ActionsView.swift

Blame
  • JSONDecoderTests.swift 1.84 KiB
    import CustomDump
    import XCTest
    @testable import XXClient
    
    final class JSONDecoderTests: XCTestCase {
      func testConvertingNumberToString() {
        assertConvertingNumberToString(
          input: #"{"number":1234567890,"text":"hello"}"#,
          key: "number",
          expectedOutput: #"{"number":"1234567890","text":"hello"}"#
        )
    
        assertConvertingNumberToString(
          input: #"{"text":"hello","number":1234567890}"#,
          key: "number",
          expectedOutput: #"{"text":"hello","number":"1234567890"}"#
        )
    
        assertConvertingNumberToString(
          input: #"{  "number"  :  1234567890  ,  "text"  :  "hello"  }"#,
          key: "number",
          expectedOutput: #"{  "number"  :  "1234567890"  ,  "text"  :  "hello"  }"#
        )
    
        assertConvertingNumberToString(
          input: #"{  "text"  :  "hello"  ,  "number"  :  1234567890  }"#,
          key: "number",
          expectedOutput: #"{  "text"  :  "hello"  ,  "number"  :  "1234567890"  }"#
        )
    
        assertConvertingNumberToString(
          input: """
          {
            "number": 1234567890,
            "text": "hello"
          }
          """,
          key: "number",
          expectedOutput: """
          {
            "number": "1234567890",
            "text": "hello"
          }
          """
        )
    
        assertConvertingNumberToString(
          input: """
          {
            "text": "hello",
            "number": 1234567890
          }
          """,
          key: "number",
          expectedOutput: """
          {
            "text": "hello",
            "number": "1234567890"
          }
          """
        )
      }
    }
    
    private func assertConvertingNumberToString(
      input: String,
      key: String,
      expectedOutput: String,
      file: StaticString = #file,
      line: UInt = #line
    ) {
      XCTAssertNoDifference(
        String(
          data: JSONDecoder().convertNumberToString(
            in: input.data(using: .utf8)!,
            at: key
          ),
          encoding: .utf8
        )!,
        expectedOutput,
        file: file,
        line: line
      )
    }