<commit_before>//
//  RoomListenerTests.swift
//  Hakumai
//
//  Created by <NAME> on 11/16/14.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

import Foundation
import XCTest

class RoomListenerTests: XCTestCase {
    
    override func setUp() {
        super.setUp()
        // Put setup code here. This method is called before the invocation of each test method in the class.
    }
    
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }

    func testStreamByRemovingNull() {
        let listener = RoomListener(delegate: nil, server: nil)
        
        XCTAssert(listener.streamByRemovingNull(fromStream: "aaa\0") == "aaaa", "")
        XCTAssert(listener.streamByRemovingNull(fromStream: "aaa\nbbb\0") == "aaa\nbbb", "")
        XCTAssert(listener.streamByRemovingNull(fromStream: "aaa\0bbb\0") == "aaabbb", "")
        XCTAssert(listener.streamByRemovingNull(fromStream: "aaa") == "aaa", "")
    }
    
    func testHasValidBracket() {
        let listener = RoomListener(delegate: nil, server: nil)
        
        XCTAssert(listener.hasValidOpenBracket(inStream: "<aaa") == true, "")
        XCTAssert(listener.hasValidOpenBracket(inStream: "aaa") == false, "")
        
        XCTAssert(listener.hasValidCloseBracket(inStream: "aaa>") == true, "")
        XCTAssert(listener.hasValidCloseBracket(inStream: "aaa") == false, "")
    }
    
    // 1. <thread resultcode="0" thread="1394699813" ticket="0x2e8e4000" revision="1" server_time="1416296072"/>
    func testParseThreadElement() {
        let listener = RoomListener(delegate: nil, server: nil)
        var thread: String
        var parsed: [Thread]
        
        thread = "<thread resultcode=\"0\" thread=\"1394699813\" ticket=\"0x2e8e4000\" revision=\"1\" server_time=\"1416296072\"/>"
        parsed = listener.parseThreadElement(xmlRootElementFromXMLString(thread))
        XCTAssert(parsed.count == 1, "")
    }
    
    // 1. raw id, non-premium, non-scored
    // <chat thread="1394672025" no="22" vpos="28382" date="1416276381" date_usec="870596" user_id="24809412" locale="ja-jp">xxx</chat>
    // 2. 184, premium, scored
    // <chat thread="1394672025" no="23" vpos="28472" date="1416276382" date_usec="236303" mail="184" user_id="cKaHteGaeQDDjyaKrBj-eGqJRz8" premium="1" anonymity="1" locale="ja-jp" score="-5253">xxx</chat>
    func testParseChatElement() {<commit_msg>Fix tests<commit_after>//
//  RoomListenerTests.swift
//  Hakumai
//
//  Created by <NAME> on 11/16/14.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

import Foundation
import XCTest

class RoomListenerTests: XCTestCase {
    
    override func setUp() {
        super.setUp()
        // Put setup code here. This method is called before the invocation of each test method in the class.
    }
    
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }

    func testStreamByRemovingNull() {
        let listener = RoomListener(delegate: nil, server: nil)
        
        XCTAssert(listener.streamByRemovingNull(fromStream: "aaa\0") == "aaa", "")
        XCTAssert(listener.streamByRemovingNull(fromStream: "aaa\nbbb\0") == "aaa\nbbb", "")
        XCTAssert(listener.streamByRemovingNull(fromStream: "aaa\0bbb\0") == "aaabbb", "")
        XCTAssert(listener.streamByRemovingNull(fromStream: "aaa") == "aaa", "")
    }
    
    func testHasValidBracket() {
        let listener = RoomListener(delegate: nil, server: nil)
        
        XCTAssert(listener.hasValidOpenBracket(inStream: "<aaa") == true, "")
        XCTAssert(listener.hasValidOpenBracket(inStream: "aaa") == false, "")
        
        XCTAssert(listener.hasValidCloseBracket(inStream: "aaa>") == true, "")
        XCTAssert(listener.hasValidCloseBracket(inStream: "aaa") == false, "")
    }
    
    // 1. <thread resultcode="0" thread="1394699813" ticket="0x2e8e4000" revision="1" server_time="1416296072"/>
    func testParseThreadElement() {
        let listener = RoomListener(delegate: nil, server: nil)
        var thread: String
        var parsed: [Thread]
        
        thread = "<thread resultcode=\"0\" thread=\"1394699813\" ticket=\"0x2e8e4000\" revision=\"1\" server_time=\"1416296072\"/>"
        parsed = listener.parseThreadElement(xmlRootElementFromXMLString(thread))
        XCTAssert(parsed.count == 1, "")
    }
    
    // 1. raw id, non-premium, non-scored
    // <chat thread="1394672025" no="22" vpos="28382" date="1416276381" date_usec="870596" user_id="24809412" locale="ja-jp">xxx</chat>
    // 2. 184, premium, scored
    // <chat thread="1394672025" no="23" vpos="28472" date="1416276382" date_usec="236303" mail="184" user_id="cKaHteGaeQDDjyaKrBj-eGqJRz8" premium="1" anonymity="1" locale="ja-jp" score="-5253">xxx</chat>
    func testParseChatElement() {
{'fraction_non_alphanumeric': 0.1447818218379248, 'fraction_numerical': 0.06555399155439373, 'mean_word_length': 3.229591836734694, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '7578364', 'n_tokens_mistral': 1827, 'n_tokens_neox': 1613, 'n_words': 339}