<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import UIKit
import XCTest

class WebServerTests: XCTestCase {

    let webServer = GCDWebServer()

    override func setUp() {
        super.setUp()
        webServer.addDefaultHandlerForMethod("GET", requestClass: GCDWebServerRequest.self) { (request) -> GCDWebServerResponse! in
            return GCDWebServerDataResponse(HTML: "<html><body><p>Hello World</p></body></html>")
        }
        webServer.startWithPort(17825, bonjourName: nil)
    }
    
    override func tearDown() {
        super.tearDown()
    }

    func testWebServerIsRunning() {
        XCTAssertTrue(webServer.running)
    }

    func testWebServerIsServingRequests() {
        let response = NSString(contentsOfURL: NSURL(string: "http://localhost:17825/")!, encoding: NSUTF8StringEncoding, error: nil)
        XCTAssertNotNil(response)
        XCTAssertTrue(response == "<html><body><p>Hello World</p></body></html>")
    }

}
<commit_msg>Bind the server to a random port.<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import UIKit
import XCTest

/// Minimal web server tests. This class can be used as a base class for tests that need a real web server.
/// Simply add additional handlers your test class' setUp() method.
class WebServerTests: XCTestCase {
    let webServer: GCDWebServer = GCDWebServer()
    var webServerBase: String!

    /// Setup a basic web server that binds to a random port and that has one default handler on /hello
    private func setupWebServer() {
        webServer.addHandlerForMethod("GET", path: "/hello", requestClass: GCDWebServerRequest.self) { (request) -> GCDWebServerResponse! in
            return GCDWebServerDataResponse(HTML: "<html><body><p>Hello World</p></body></html>")
        }
        if webServer.startWithPort(0, bonjourName: nil) == false {
            XCTFail("Can't start the GCDWebServer")
        }
        webServerBase = "http://localhost:\(webServer.port)"
    }

    override func setUp() {
        super.setUp()
        setupWebServer()
    }
    
    override func tearDown() {
        super.tearDown()
    }

    func testWebServerIsRunning() {
        XCTAssertTrue(webServer.running)
    }

    func testWebServerIsServingRequests() {
        let response = NSString(contentsOfURL: NSURL(string: "\(webServerBase)/hello")!, encoding: NSUTF8StringEncoding, error: nil)
        XCTAssertNotNil(response)
        XCTAssertTrue(response == "<html><body><p>Hello World</p></body></html>")
    }
}

{'fraction_non_alphanumeric': 0.11362032462949895, 'fraction_numerical': 0.007410021171489062, 'mean_word_length': 3.1447368421052633, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, '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': '7464246', 'n_tokens_mistral': 852, 'n_tokens_neox': 828, 'n_words': 241}