<commit_before>//
//  OgraTests.swift
//  OgraTests
//
//  Created by <NAME> on 27/07/2015.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import XCTest
import Argo
import Ogra

class OgraTests: XCTestCase {
	private func toJSON(jsonString: String) -> JSON {
		let jsonData = jsonString.dataUsingEncoding(NSUTF8StringEncoding)!
		let jsonObject: AnyObject = try! NSJSONSerialization.JSONObjectWithData(jsonData, options:NSJSONReadingOptions())
		return JSON.parse(jsonObject)
	}
	
	func testNullPet() {
		let jsonIn = toJSON("{ \"id\":123, \"name\":\"John\", \"email\":\"<EMAIL>\", \"pet\":null, \"nicknames\":[\"Johnny\"], \"accounts\":{\"gmail\":\"john\"} }")
		let user = User.decode(jsonIn).value!
		let jsonOut = user.encode()
		
		XCTAssertEqual(jsonIn, jsonOut)
	}
	
	func testWithPet() {
		let jsonIn = toJSON("{ \"id\":123, \"name\":\"John\", \"email\":\"<EMAIL>\", \"pet\":{\"name\":\"Rex\"}, \"nicknames\":[\"Johnny\"], \"accounts\":{\"gmail\":\"john\"} }")
		let user = User.decode(jsonIn).value!
		let jsonOut = user.encode()
		
		XCTAssertEqual(jsonIn, jsonOut)
	}

	func testPassingToJSONSerialization() {
		let json = toJSON("{ \"id\":123, \"name\":\"John\", \"email\":\"<EMAIL>\", \"pet\":{\"name\":\"Rex\"}, \"nicknames\":[\"Johnny\"], \"accounts\":{\"gmail\":\"john\"} }")
		let user = User.decode(json).value!

		let jsonObject = user.encode().JSONObject()
		let data = try! NSJSONSerialization.dataWithJSONObject(jsonObject, options: NSJSONWritingOptions.PrettyPrinted)
		let string = NSString(data:data, encoding:NSUTF8StringEncoding)!
		// a bit tricky to test this because changes to Foundation will result in different ordering of the output.
		// for now, we just dump it out. if there were problems converting to JSON (eg. dataWithJSONObject returning
		// a nil) then we would have trapped by now
		print(string)
	}
}<commit_msg>Add tests for null collections.<commit_after>//
//  OgraTests.swift
//  OgraTests
//
//  Created by <NAME> on 27/07/2015.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import XCTest
import Argo
import Ogra

class OgraTests: XCTestCase {
	private func toJSON(jsonString: String) -> JSON {
		let jsonData = jsonString.dataUsingEncoding(NSUTF8StringEncoding)!
		let jsonObject: AnyObject = try! NSJSONSerialization.JSONObjectWithData(jsonData, options:NSJSONReadingOptions())
		return JSON.parse(jsonObject)
	}
	
	func testNullPet() {
		let jsonIn = toJSON("{ \"id\":123, \"name\":\"John\", \"email\":\"<EMAIL>\", \"pet\":null, \"nicknames\":[\"Johnny\"], \"accounts\":{\"gmail\":\"john\"} }")
		let user = User.decode(jsonIn).value!
		let jsonOut = user.encode()
		
		XCTAssertEqual(jsonIn, jsonOut)
	}
	
	func testNullNicknames() {
		let jsonIn = toJSON("{ \"id\":123, \"name\":\"John\", \"email\":\"<EMAIL>\", \"pet\":null, \"nicknames\":null, \"accounts\":{\"gmail\":\"john\"} }")
		let user = User.decode(jsonIn).value!
		let jsonOut = user.encode()
		
		XCTAssertEqual(jsonIn, jsonOut)
	}
	
	func testNullAccounts() {
		let jsonIn = toJSON("{ \"id\":123, \"name\":\"John\", \"email\":\"<EMAIL>\", \"pet\":null, \"nicknames\":[\"Johnny\"], \"accounts\":null }")
		let user = User.decode(jsonIn).value!
		let jsonOut = user.encode()
		
		XCTAssertEqual(jsonIn, jsonOut)
	}
	
	func testWithPet() {
		let jsonIn = toJSON("{ \"id\":123, \"name\":\"John\", \"email\":\"<EMAIL>\", \"pet\":{\"name\":\"Rex\"}, \"nicknames\":[\"Johnny\"], \"accounts\":{\"gmail\":\"john\"} }")
		let user = User.decode(jsonIn).value!
		let jsonOut = user.encode()
		
		XCTAssertEqual(jsonIn, jsonOut)
	}

	func testPassingToJSONSerialization() {
		let json = toJSON("{ \"id\":123, \"name\":\"John\", \"email\":\"<EMAIL>\", \"pet\":{\"name\":\"Rex\"}, \"nicknames\":[\"Johnny\"], \"accounts\":{\"gmail\":\"john\"} }")
		let user = User.decode(json).value!

		let jsonObject = user.encode().JSONObject()
		let data = try! NSJSONSerialization.dataWithJSONObject(jsonObject, options: NSJSONWritingOptions.PrettyPrinted)
		let string = NSString(data:data, encoding:NSUTF8StringEncoding)!
		// a bit tricky to test this because changes to Foundation will result in different ordering of the output.
		// for now, we just dump it out. if there were problems converting to JSON (eg. dataWithJSONObject returning
		// a nil) then we would have trapped by now
		print(string)
	}
}
{'fraction_non_alphanumeric': 0.20514007872192638, 'fraction_numerical': 0.012039824033341051, 'mean_word_length': 3.9655172413793105, 'pattern_counts': {'":': 59, '<': 15, '<?xml version=': 0, '>': 17, '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': '4479084', 'n_tokens_mistral': 1560, 'n_tokens_neox': 1420, 'n_words': 342}