<commit_before>//
//  TKJSONSanitizerTest.swift
//  TripKitTests
//
//  Created by <NAME> on 03.11.17.
//  Copyright © 2017 SkedGo. All rights reserved.
//

import XCTest

@testable import TripKit

class TKJSONSanitizerTest: XCTestCase {

  private struct TestStruct: Codable {
    let color: API.RGBColor
    let url: String
    let derp: Int?
    let number: Double
  }
  
  func testMadeUpExample() {
    let nonJson: [[String: Any]] = [[
      "color": #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0),
      "url": URL(string: "https://api.tripgo.com")!,
      "derp": NSNull(),
      "number": NSNumber(value: true),
    ]]

    guard let sanitized = TKJSONSanitizer.sanitize(nonJson) else { XCTFail(); return }
    let decoded = try? JSONDecoder().decode([TestStruct].self, withJSONObject: sanitized)
    XCTAssertNotNil(decoded)
  }
  
  func testModeInfo() {
    let nonJson: [String: Any] = [
      "color": #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0),
      "alt": "Test",
    ]
    
    guard let sanitized = TKJSONSanitizer.sanitize(nonJson) else { XCTFail(); return }
    let decoded = try? JSONDecoder().decode(ModeInfo.self, withJSONObject: sanitized)
    XCTAssertNotNil(decoded)<commit_msg>Fix sanitizer test for Swift 4.1<commit_after>//
//  TKJSONSanitizerTest.swift
//  TripKitTests
//
//  Created by <NAME> on 03.11.17.
//  Copyright © 2017 SkedGo. All rights reserved.
//

import XCTest

@testable import TripKit

class TKJSONSanitizerTest: XCTestCase {

  private struct TestStruct: Codable {
    let color: API.RGBColor
    let url: String
    let derp: Int?
    let number: Double
  }
  
  func testMadeUpExample() {
    let nonJson: [[String: Any]] = [[
      "color": #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0),
      "url": URL(string: "https://api.tripgo.com")!,
      "derp": NSNull(),
      "number": NSNumber(value: 1),
    ]]

    guard let sanitized = TKJSONSanitizer.sanitize(nonJson) else { XCTFail(); return }
    let decoded = try? JSONDecoder().decode([TestStruct].self, withJSONObject: sanitized)
    XCTAssertNotNil(decoded)
  }
  
  func testModeInfo() {
    let nonJson: [String: Any] = [
      "color": #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0),
      "alt": "Test",
    ]
    
    guard let sanitized = TKJSONSanitizer.sanitize(nonJson) else { XCTFail(); return }
    let decoded = try? JSONDecoder().decode(ModeInfo.self, withJSONObject: sanitized)
    XCTAssertNotNil(decoded)
{'fraction_non_alphanumeric': 0.14302981466559225, 'fraction_numerical': 0.02215954875100725, 'mean_word_length': 3.1871838111298483, 'pattern_counts': {'":': 12, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7574752', 'n_tokens_mistral': 939, 'n_tokens_neox': 867, 'n_words': 218}