Skip to content
Snippets Groups Projects
Select Git revision
  • 813cd688d87ae68b4f55dc52da27884be9af01f9
  • release default
  • master protected
  • hotfix/gtnNoToken
  • XX-4441
  • Jakub/rootless-CI
  • jonah/refactorProviders
  • Ace/Huawei
  • AceVentura/AccountBackup
  • hotfix/delete-error
  • waitingRoundsRewrite
  • dev
  • quantumSecure
  • hotfix/ratelimit
  • fullRateLimit
  • XX-3564/TlsCipherSuite
  • hotfix/notifications-db
  • hotfix/groupNotification
  • Project/LastMile
  • notls
  • url-repo-rename
  • v2.3.0
  • v2.2.0
  • v2.1.0
  • v2.0.0
  • v1.0.0
26 results

root.go

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
      )
    }