<commit_before>import XCTest
import TidyJSON
import Foundation

class ValueTests: XCTestCase {

    var allTests : [(String, () throws -> ())] {
        return [
            ("testNull", testNull),
            ("testTrue", testTrue),
            ("testFalse", testFalse),
            ("testNumber", testNumber),
            ("testString", testString),
            ("1DArrayGetter", testSingleDimensionalArraysGetter),
            ("2DArrayGetter", testTwoDimensionalArraysGetter),
            ("testObjectGetter", testObjectGetter)
        ]
    }
    
    func testNull() {
        let json : JSON = nil
        let json1 : JSON = [nil, nil]
        let json2 : JSON = ["key": nil]
        XCTAssertTrue(json.isNull)
        XCTAssertTrue(json1[0].isNull)
        XCTAssertTrue(json2["key"].isNull)
    }
    
    func testTrue() {
        let json : JSON = true
        let json1 : JSON = [true, true]
        let json2 : JSON = ["key" : true]
        XCTAssertTrue(json.bool!)
        XCTAssertTrue(json1[0].bool!)
        XCTAssertTrue(json1[1].bool!)
        
        XCTAssertTrue(json2["key"].bool!)
    }
    
    func testFalse() {
        let json : JSON = false 
        let json1 : JSON = [false, false]
        let json2 : JSON = ["key" : false]
        XCTAssertFalse(json.bool!)
        XCTAssertFalse(json1[0].bool!)
        XCTAssertFalse(json1[1].bool!)
        
        XCTAssertFalse(json2["key"].bool!)
    }
    
    func testNumber() {
        let json : JSON = 1
        let json1 : JSON = 1.0
        let json2 : JSON = 1.23e2
        let json3 : JSON = 66662882838882382838823828832823.0
        let json4 : JSON = 3.0e-2
        XCTAssertEqual(json.double!, 1.0)
        XCTAssertEqual(json.float!, 1.0)
        XCTAssertEqual(json.int!, 1)
        XCTAssertEqual(json1.double!, 1.0)
        XCTAssertEqual(json1.int!, 1)
        XCTAssertEqual(json2.float!, 1.23e2)
        XCTAssertEqual(json2.double!, 1.23e2)
        XCTAssertEqual(json3.double!, 66662882838882382838823828832823.0)
        XCTAssertEqual(json4.double!, 3.0e-2)
    }
    
    func testString() {
        let json : JSON = ""
        let json1 : JSON = "hello"
        let json2 : JSON = "he\r \n llo"
        let json3 : JSON = "hello \t \"world\" "
        
        XCTAssertEqual(json.string!, "")
        XCTAssertEqual(json1.string!, "hello")
        XCTAssertEqual(json2.string!, "he\r \n llo")
        XCTAssertEqual(json3.string!, "hello \t \"world\" ")
    }
    
    func testSingleDimensionalArraysGetter() {
        let json : JSON = ["1","2", "a", "B", "D"]
        XCTAssertEqual(json[0].string!, "1")
        XCTAssertEqual(json[1].string!, "2")
        XCTAssertEqual(json[2].string!, "a")
        XCTAssertEqual(json[3].string!, "B")
        XCTAssertEqual(json[4].string!, "D")
    }
    
    func testTwoDimensionalArraysGetter() {
        let json : JSON = ["1",[1,2,2.0], true]
        XCTAssertEqual(json[0].string!, "1")
        XCTAssertEqual(json[1][0].int!, 1)
        XCTAssertEqual(json[1][1].int!, 2)
        XCTAssertEqual(json[1][2].float!, 2.0)
        XCTAssertEqual(json[2].bool!, true)
    }
    
    func testObjectGetter() {
        let json : JSON = ["key":false, "key2":true, "key3":[1, "hello", 3, "world", ["key4":nil, "key5":12.03, "key6":12E-2, "key7": -12e-2]]]
        XCTAssertEqual(json["key"].bool!, false)
        XCTAssertEqual(json["key2"].bool!, true)
        XCTAssertNotNil(json["key3"].array)
        XCTAssertNotNil(json["key3"][4].object)
        XCTAssertEqual(json["key3"][4]["key4"].isNull, true)
        XCTAssertEqual(json["key3"][4]["key5"].float!, 12.03)
    }
}


class ParserTests: XCTestCase {

    var allTests : [(String, () throws -> ())] {
        return [
            ("testParseNull", testParseNull),
            ("testParseString", testParseString),
            ("testParseTrue", testParseTrue),
            ("testParseFalse", testParseFalse),
            ("testParseNumber", testParseNumber),
            ("testParseArray", testParseArray),
            ("testParseObject", testParseObject),
            ("testParseTestCases", testParseTestCases)
        ]
    }
    
    func testParseNull() {
        let json = try? JSON.parse("null")
        XCTAssertTrue(json!.isNull)
        
        let json1 = try? JSON.parse("nu")
        XCTAssertTrue(json1 == nil)
        
        let json2 = try? JSON.parse("nil")
        XCTAssertTrue(json2 == nil)
    }
    
    func testParseString() {
        
        let json = try? JSON.parse("\"hello\"")
        let json1 = try? JSON.parse("\"\\u0041pple\"")
        let json2 = try? JSON.parse("\"\\\\ line1 \\n tab \\t \\r \\/\"")
        XCTAssertEqual(json!.string!, "hello")
        XCTAssertEqual(json1!.string!, "Apple")
        XCTAssertEqual(json2!.string!, "\\ line1 \n tab \t \r /")
        
        let json3 = try? JSON.parse("hello\"")
        XCTAssertTrue(json3 == nil)
        
        let json4 = try? JSON.parse("\"hello")
        XCTAssertTrue(json4 == nil)
    }
    
    func testParseTrue() {
        let json = try? JSON.parse("true")
        
        XCTAssertEqual(json!.bool!, true)
        
        let json1 = try? JSON.parse("tru")
        XCTAssertTrue(json1 == nil)
    }
    
    func testParseFalse() {
        let json = try? JSON.parse("false")
        
        XCTAssertEqual(json!.bool!, false)
        
        let json1 = try? JSON.parse("fa")
        XCTAssertTrue(json1 == nil)
    }
    
    func testParseNumber() {
        let json = try? JSON.parse("-120003e-1")
        XCTAssertEqual(json!.double!, -120003e-1)
        
        let json1 = try? JSON.parse("2.3E12")
        XCTAssertEqual(json1!.double!, 2.3E12)
        
        let json2 = try? JSON.parse("7.450580596923828e-9")
        XCTAssertEqual(json2!.double!, 7.450580596923828e-9)
    }
    
    func testParseArray() {
        let json = try? JSON.parse("[]")
        XCTAssertNotNil(json!.array)
        XCTAssertEqual(json!.count, 0)
        
        let json1 = try? JSON.parse("[1,2,3")
        XCTAssertTrue(json1 == nil)
        
        let json2 = try? JSON.parse("]")
        XCTAssertTrue(json2 == nil)
        
        let json3 = try? JSON.parse("[1,2,hello]")
        XCTAssertTrue(json3 == nil)
        
        let json4 = try? JSON.parse("[\"hello]\", 12, false, true, null]")
        XCTAssertEqual(json4!.count, 5)
        
        let json5 = try? JSON.parse("[,]")
        XCTAssertTrue(json5 == nil)
    }<commit_msg>fix test case<commit_after>import XCTest
import TidyJSON
import Foundation

class ValueTests: XCTestCase {

    var allTests : [(String, () throws -> ())] {
        return [
            ("testNull", testNull),
            ("testTrue", testTrue),
            ("testFalse", testFalse),
            ("testNumber", testNumber),
            ("testString", testString),
            ("1DArrayGetter", testSingleDimensionalArraysGetter),
            ("2DArrayGetter", testTwoDimensionalArraysGetter),
            ("testObjectGetter", testObjectGetter)
        ]
    }
    
    func testNull() {
        let json : JSON = nil
        let json1 : JSON = [nil, nil]
        let json2 : JSON = ["key": nil]
        XCTAssertTrue(json.isNull)
        XCTAssertTrue(json1[0].isNull)
        XCTAssertTrue(json2["key"].isNull)
    }
    
    func testTrue() {
        let json : JSON = true
        let json1 : JSON = [true, true]
        let json2 : JSON = ["key" : true]
        XCTAssertTrue(json.bool!)
        XCTAssertTrue(json1[0].bool!)
        XCTAssertTrue(json1[1].bool!)
        
        XCTAssertTrue(json2["key"].bool!)
    }
    
    func testFalse() {
        let json : JSON = false 
        let json1 : JSON = [false, false]
        let json2 : JSON = ["key" : false]
        XCTAssertFalse(json.bool!)
        XCTAssertFalse(json1[0].bool!)
        XCTAssertFalse(json1[1].bool!)
        
        XCTAssertFalse(json2["key"].bool!)
    }
    
    func testNumber() {
        let json : JSON = 1
        let json1 : JSON = 1.0
        let json2 : JSON = 1.23e2
        let json3 : JSON = 66662882838882382838823828832823.0
        let json4 : JSON = 3.0e-2
        XCTAssertEqual(json.double!, 1.0)
        XCTAssertEqual(json.float!, 1.0)
        XCTAssertEqual(json.int!, 1)
        XCTAssertEqual(json1.double!, 1.0)
        XCTAssertEqual(json1.int!, 1)
        XCTAssertEqual(json2.float!, 1.23e2)
        XCTAssertEqual(json2.double!, 1.23e2)
        XCTAssertEqual(json3.double!, 66662882838882382838823828832823.0)
        XCTAssertEqual(json4.double!, 3.0e-2)
    }
    
    func testString() {
        let json : JSON = ""
        let json1 : JSON = "hello"
        let json2 : JSON = "he\r \n llo"
        let json3 : JSON = "hello \t \"world\" "
        
        XCTAssertEqual(json.string!, "")
        XCTAssertEqual(json1.string!, "hello")
        XCTAssertEqual(json2.string!, "he\r \n llo")
        XCTAssertEqual(json3.string!, "hello \t \"world\" ")
    }
    
    func testSingleDimensionalArraysGetter() {
        let json : JSON = ["1","2", "a", "B", "D"]
        XCTAssertEqual(json[0].string!, "1")
        XCTAssertEqual(json[1].string!, "2")
        XCTAssertEqual(json[2].string!, "a")
        XCTAssertEqual(json[3].string!, "B")
        XCTAssertEqual(json[4].string!, "D")
    }
    
    func testTwoDimensionalArraysGetter() {
        let json : JSON = ["1",[1,2,2.0], true]
        XCTAssertEqual(json[0].string!, "1")
        XCTAssertEqual(json[1][0].int!, 1)
        XCTAssertEqual(json[1][1].int!, 2)
        XCTAssertEqual(json[1][2].float!, 2.0)
        XCTAssertEqual(json[2].bool!, true)
    }
    
    func testObjectGetter() {
        let json : JSON = ["key":false, "key2":true, "key3":[1, "hello", 3, "world", ["key4":nil, "key5":12.03, "key6":12E-2, "key7": -12e-2]]]
        XCTAssertEqual(json["key"].bool!, false)
        XCTAssertEqual(json["key2"].bool!, true)
        XCTAssertNotNil(json["key3"].array)
        XCTAssertNotNil(json["key3"][4].object)
        XCTAssertEqual(json["key3"][4]["key4"].isNull, true)
        XCTAssertEqual(json["key3"][4]["key5"].float!, 12.03)
    }
}


class ParserTests: XCTestCase {

    var allTests : [(String, () throws -> ())] {
        return [
            ("testParseNull", testParseNull),
            ("testParseString", testParseString),
            ("testParseTrue", testParseTrue),
            ("testParseFalse", testParseFalse),
            ("testParseNumber", testParseNumber),
            ("testParseArray", testParseArray),
            ("testParseObject", testParseObject),
            ("testParseTestCases", testParseTestCases)
        ]
    }
    
    func testParseNull() {
        let json = try? JSON.parse("null")
        XCTAssertTrue(json!.isNull)
        
        let json1 = try? JSON.parse("nu")
        XCTAssertTrue(json1 == nil)
        
        let json2 = try? JSON.parse("nil")
        XCTAssertTrue(json2 == nil)
    }
    
    func testParseString() {
        
        let json = try? JSON.parse("\"hello\"")
        let json1 = try? JSON.parse("\"\\u0041pple\"")
        let json2 = try? JSON.parse("\"\\\\ line1 \\n tab \\t \\r \\/\"")
        XCTAssertEqual(json!.string!, "hello")
        XCTAssertEqual(json1!.string!, "Apple")
        XCTAssertEqual(json2!.string!, "\\ line1 \n tab \t \r /")
        
        let json3 = try? JSON.parse("hello\"")
        XCTAssertTrue(json3 == nil)
        
        let json4 = try? JSON.parse("\"hello")
        XCTAssertTrue(json4 == nil)
    }
    
    func testParseTrue() {
        let json = try? JSON.parse("true")
        
        XCTAssertEqual(json!.bool!, true)
        
        let json1 = try? JSON.parse("tru")
        XCTAssertTrue(json1 == nil)
    }
    
    func testParseFalse() {
        let json = try? JSON.parse("false")
        
        XCTAssertEqual(json!.bool!, false)
        
        let json1 = try? JSON.parse("fa")
        XCTAssertTrue(json1 == nil)
    }
    
    func testParseNumber() {
        let json = try? JSON.parse("-120003e-1 ")
        XCTAssertEqual(json!.double!, -120003e-1)
        
        let json1 = try? JSON.parse("2.3E12 ")
        XCTAssertEqual(json1!.double!, 2.3E12)
        
        let json2 = try? JSON.parse("7.450580596923828e-9 ")
        XCTAssertEqual(json2!.double!, 7.450580596923828e-9)
    }
    
    func testParseArray() {
        let json = try? JSON.parse("[]")
        XCTAssertNotNil(json!.array)
        XCTAssertEqual(json!.count, 0)
        
        let json1 = try? JSON.parse("[1,2,3")
        XCTAssertTrue(json1 == nil)
        
        let json2 = try? JSON.parse("]")
        XCTAssertTrue(json2 == nil)
        
        let json3 = try? JSON.parse("[1,2,hello]")
        XCTAssertTrue(json3 == nil)
        
        let json4 = try? JSON.parse("[\"hello]\", 12, false, true, null]")
        XCTAssertEqual(json4!.count, 5)
        
        let json5 = try? JSON.parse("[,]")
        XCTAssertTrue(json5 == nil)
    }
{'fraction_non_alphanumeric': 0.1517518756284322, 'fraction_numerical': 0.04516977337767809, 'mean_word_length': 2.0698005698005697, 'pattern_counts': {'":': 16, '<': 3, '<?xml version=': 0, '>': 7, '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': '6017971', 'n_tokens_mistral': 4599, 'n_tokens_neox': 4315, 'n_words': 798}