<commit_before>import UIKit
import XCTest

class Object: NSCoder {

  var property: String?

  required convenience init(coder decoder: NSCoder) {
    self.init()

    self.property = decoder.decodeObjectForKey("property") as? String
  }

  func encodeWithCoder(coder: NSCoder) {
    coder.encodeObject(self.property, forKey: "property")
  }

}

class Tests: XCTestCase {

  func testSavingObjectWithFilename() {
    let object = Object()
    object.property = "My Property"
    Storage.save(object: object, "RootObject.extension") { error in
      XCTAssertNil(error)
    }
  }

  func testSavingObjectWithPathAndFilename() {
    let object = Object()
    object.property = "My Property"

    Storage.save(object: object, "Folder/RootObject.extension") { error in
      XCTAssertNil(error)
    }
  }

  func testSavingObjectWithDeepPathAndFilename() {
    let object = Object()
    object.property = "My Property"

    Storage.save(object: object, "Folder/SubFolder/RootObject.extension") { error in
      XCTAssertNil(error)
    }
  }

  func testSaveSavingAndLoadingObject() {
    let initialObject = Object()
    initialObject.property = "My Property"

    Storage.save(object: initialObject, "Folder/SaveObject.extension") { error in
      XCTAssertNil(error)
    }

    let loadedObject = Storage.load("Folder/SaveObject.extension") as? Object
    if loadedObject != nil {
      XCTAssertEqual(initialObject.property!, loadedObject!.property!)
    }
  }

  func testSaveAndLoadContentsToFile() {
    let path = "Folder/test.txt"
    let expectedString = "My string"

    Storage.save(contents: expectedString, path) { error in
      XCTAssertNil(error)
    }

    let loadedString = Storage.load(contentsAtPath: path)
    XCTAssertEqual(expectedString, loadedString!)
  }

  func testSaveAndLoadDataToFile() {
    let path = "Folder/test.txt"
    let string = "My string"
    let expectedData = string.dataUsingEncoding(NSUTF8StringEncoding)!

    Storage.save(data: expectedData, path) { error in
      XCTAssertNil(error)
    }

    let loadedData = Storage.load(dataAtPath: path)
    XCTAssertEqual(expectedData, loadedData!)
  }
}<commit_msg>Add tests for saving and loading of JSON<commit_after>import UIKit
import XCTest

class Object: NSCoder {

  var property: String?

  required convenience init(coder decoder: NSCoder) {
    self.init()

    self.property = decoder.decodeObjectForKey("property") as? String
  }

  func encodeWithCoder(coder: NSCoder) {
    coder.encodeObject(self.property, forKey: "property")
  }

}

class Tests: XCTestCase {

  func testSavingObjectWithFilename() {
    let object = Object()
    object.property = "My Property"
    Storage.save(object: object, "RootObject.extension") { error in
      XCTAssertNil(error)
    }
  }

  func testSavingObjectWithPathAndFilename() {
    let object = Object()
    object.property = "My Property"

    Storage.save(object: object, "Folder/RootObject.extension") { error in
      XCTAssertNil(error)
    }
  }

  func testSavingObjectWithDeepPathAndFilename() {
    let object = Object()
    object.property = "My Property"

    Storage.save(object: object, "Folder/SubFolder/RootObject.extension") { error in
      XCTAssertNil(error)
    }
  }

  func testSaveSavingAndLoadingObject() {
    let initialObject = Object()
    initialObject.property = "My Property"

    Storage.save(object: initialObject, "Folder/SaveObject.extension") { error in
      XCTAssertNil(error)
    }

    let loadedObject = Storage.load("Folder/SaveObject.extension") as? Object
    if loadedObject != nil {
      XCTAssertEqual(initialObject.property!, loadedObject!.property!)
    }
  }

  func testSaveAndLoadContentsToFile() {
    let path = "Folder/test.txt"
    let expectedString = "My string"

    Storage.save(contents: expectedString, path) { error in
      XCTAssertNil(error)
    }

    let loadedString = Storage.load(contentsAtPath: path)
    XCTAssertEqual(expectedString, loadedString!)
  }

  func testSaveAndLoadDataToFile() {
    let path = "Folder/test.txt"
    let string = "My string"
    let expectedData = string.dataUsingEncoding(NSUTF8StringEncoding)!

    Storage.save(data: expectedData, path) { error in
      XCTAssertNil(error)
    }

    let loadedData = Storage.load(dataAtPath: path)
    XCTAssertEqual(expectedData, loadedData!)
  }

  func testSaveAndLoadJSONToFile() {
    let path = "Folder/test.json"
    let expectedObject = [
      "key": "value",
      "list": ["key": "value"]
    ]

    Storage.save(JSON: expectedObject, path) { error in
      XCTAssertNil(error)
    }

    let loadedObject = Storage.load(JSONAtPath: path) as? NSDictionary
    XCTAssertEqual(expectedObject, loadedObject!)
  }
}
{'fraction_non_alphanumeric': 0.10437925170068027, 'fraction_numerical': 0.00042517006802721087, 'mean_word_length': 3.585769980506823, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '4293287', 'n_tokens_mistral': 1465, 'n_tokens_neox': 1414, 'n_words': 313}