<commit_before>import Foundation
import XCTest
@testable import Theo

#if os(Linux)
    import Dispatch
#endif

class Theo_001_BoltClientTests: XCTestCase {
    
    let configuration: BoltConfig = ConfigLoader.loadBoltConfig()
    
    
    override func setUp() {
        super.setUp()
        continueAfterFailure = false
    }

    private func makeClient() throws -> BoltClient {
        let client = try BoltClient(hostname: configuration.hostname,
                                    port: configuration.port,
                                    username: configuration.username,
                                    password: <PASSWORD>,
                                    encrypted: configuration.encrypted)
        try client.connect()
        
        return client
    }
    
    func testSucceedingTransaction() throws {
        let client = try makeClient()
        let exp = self.expectation(description: "testSucceedingTransaction")
        
        try client.executeAsTransaction() { (tx, completionBlock) in
            try client.executeCypher("CREATE (n:TheoTestNode { foo: \"bar\"})")
            try client.executeCypher("MATCH (n:TheoTestNode { foo: \"bar\"}) RETURN n")
            try client.executeCypher("MATCH (n:TheoTestNode { foo: \"bar\"}) DETACH DELETE n")
            try completionBlock()
            exp.fulfill()
        }
        
        self.waitForExpectations(timeout: 10, handler: { error in
            XCTAssertNil(error, "\(error ?? "Error undefined")")
        })
    }
    
    func testFailingTransaction() throws {
        let client = try makeClient()
        let exp = self.expectation(description: "testFailingTransaction")

        try client.executeAsTransaction() { (tx, completionBlock) in
            do {
                try client.executeCypher("CREATE (n:TheoTestNode { foo: \"bar\"})")
                try client.executeCypher("MATCH (n:TheoTestNode { foo: \"bar\"}) RETURN n")
                try client.executeCypher("MAXXXTCH (n:TheoTestNode { foo: \"bar\"}) DETACH DELETE n")
            }

            try completionBlock()
            
            XCTAssertFalse(tx.succeed)
            exp.fulfill()<commit_msg>Bolt driver now has executeCypher throw an error on syntax error<commit_after>import Foundation
import XCTest
@testable import Theo

#if os(Linux)
    import Dispatch
#endif

class Theo_001_BoltClientTests: XCTestCase {
    
    let configuration: BoltConfig = ConfigLoader.loadBoltConfig()
    
    
    override func setUp() {
        super.setUp()
        continueAfterFailure = false
    }

    private func makeClient() throws -> BoltClient {
        let client = try BoltClient(hostname: configuration.hostname,
                                    port: configuration.port,
                                    username: configuration.username,
                                    password: <PASSWORD>,
                                    encrypted: configuration.encrypted)
        try client.connect()
        
        return client
    }
    
    func testSucceedingTransaction() throws {
        let client = try makeClient()
        let exp = self.expectation(description: "testSucceedingTransaction")
        
        try client.executeAsTransaction() { (tx, completionBlock) in
            try client.executeCypher("CREATE (n:TheoTestNode { foo: \"bar\"})")
            try client.executeCypher("MATCH (n:TheoTestNode { foo: \"bar\"}) RETURN n")
            try client.executeCypher("MATCH (n:TheoTestNode { foo: \"bar\"}) DETACH DELETE n")
            try completionBlock()
            exp.fulfill()
        }
        
        self.waitForExpectations(timeout: 10, handler: { error in
            XCTAssertNil(error, "\(error ?? "Error undefined")")
        })
    }
    
    func testFailingTransaction() throws {
        let client = try makeClient()
        let exp = self.expectation(description: "testFailingTransaction")

        try client.executeAsTransaction() { (tx, completionBlock) in
            do {
                try client.executeCypher("CREATE (n:TheoTestNode { foo: \"bar\"})")
                try client.executeCypher("MATCH (n:TheoTestNode { foo: \"bar\"}) RETURN n")
                try client.executeCypher("MAXXXTCH (n:TheoTestNode { foo: \"bar\"}) DETACH DELETE n")
            } catch {
                tx.markAsFailed()
            }

            try completionBlock()
            
            XCTAssertFalse(tx.succeed)
            exp.fulfill()
{'fraction_non_alphanumeric': 0.09827624804119095, 'fraction_numerical': 0.0022386389075442132, 'mean_word_length': 1.9240837696335078, 'pattern_counts': {'":': 0, '<': 5, '<?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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '816510', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1171, 'n_words': 283}