<commit_before>/**
 * Copyright IBM Corporation 2015
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

import Foundation
import XCTest

@testable import Kitura

class TestContentType: XCTestCase {

    static var allTests: [(String, (TestContentType) -> () throws -> Void)] {
        return [
            ("test_initialize", test_initialize),
            ("test_filename", test_filename),
        ]
    }

    func test_initialize() {

        let pngType = ContentType.sharedInstance.getContentType(forExtension: "png")

        XCTAssertEqual(pngType, "image/png")
        XCTAssertNotEqual(pngType, "application/javascript")

        let htmlType = ContentType.sharedInstance.getContentType(forExtension: "html")

        XCTAssertEqual(htmlType, "text/html")
        XCTAssertNotEqual(pngType, "application/javascript")

        let jsType = ContentType.sharedInstance.getContentType(forExtension: "js")

        XCTAssertEqual(jsType, "application/javascript")


        //XCTAssertEqual(contentType, contentType)
    }

    func test_filename() {

        let contentType = ContentType.sharedInstance
    
        var result = contentType.getContentType(forFileName: "foo.png")
        XCTAssertEqual(result, "image/png")

        result = contentType.getContentType(forFileName: "a/foo.png")
        XCTAssertEqual(result, "image/png")

        result = contentType.getContentType(forFileName: "a/b/c/foo.png")
        XCTAssertEqual(result, "image/png")

        result = contentType.getContentType(forFileName: "test.html")
        XCTAssertEqual(result, "text/html")

        result = contentType.getContentType(forFileName: "a/b/c/test.html")
        XCTAssertEqual(result, "text/html")

        result = contentType.getContentType(forFileName: "test.with.periods.html")
        XCTAssertEqual(result, "text/html")
    }

}
<commit_msg>Added test for isContentType() (#913)<commit_after>/**
 * Copyright IBM Corporation 2015
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

import Foundation
import XCTest

@testable import Kitura

class TestContentType: XCTestCase {

    static var allTests: [(String, (TestContentType) -> () throws -> Void)] {
        return [
            ("testInitialize", testInitialize),
            ("testFilename", testFilename),
            ("testIsContentType", testIsContentType)
        ]
    }

    let contentType = ContentType.sharedInstance
    
    func testInitialize() {

        let pngType = contentType.getContentType(forExtension: "png")

        XCTAssertEqual(pngType, "image/png")
        XCTAssertNotEqual(pngType, "application/javascript")

        let htmlType = contentType.getContentType(forExtension: "html")

        XCTAssertEqual(htmlType, "text/html")
        XCTAssertNotEqual(pngType, "application/javascript")

        let jsType = contentType.getContentType(forExtension: "js")

        XCTAssertEqual(jsType, "application/javascript")

    }

    func testFilename() {
    
        var result = contentType.getContentType(forFileName: "foo.png")
        XCTAssertEqual(result, "image/png")

        result = contentType.getContentType(forFileName: "a/foo.png")
        XCTAssertEqual(result, "image/png")

        result = contentType.getContentType(forFileName: "a/b/c/foo.png")
        XCTAssertEqual(result, "image/png")

        result = contentType.getContentType(forFileName: "test.html")
        XCTAssertEqual(result, "text/html")

        result = contentType.getContentType(forFileName: "a/b/c/test.html")
        XCTAssertEqual(result, "text/html")

        result = contentType.getContentType(forFileName: "test.with.periods.html")
        XCTAssertEqual(result, "text/html")
    }

    func testIsContentType() {
        var result = contentType.isContentType("application/json", ofType: "json")
        XCTAssertTrue(result)

        result = contentType.isContentType("json", ofType: "json")
        XCTAssertTrue(result)
        
        result = contentType.isContentType("text/html", ofType: "json")
        XCTAssertFalse(result)
        
        result = contentType.isContentType("application/x-www-form-urlencoded", ofType: "urlencoded")
        XCTAssertTrue(result)

        result = contentType.isContentType("multipart/form-data", ofType: "multipart")
        XCTAssertTrue(result)
        
    }
    
}

{'fraction_non_alphanumeric': 0.10486750610787446, 'fraction_numerical': 0.0035707573764330014, 'mean_word_length': 3.2406374501992032, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 3, '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': '3385040', 'n_tokens_mistral': 1520, 'n_tokens_neox': 1468, 'n_words': 366}