<commit_before>//
//  StructureTests.swift
//  SourceKitten
//
//  Created by <NAME> on 2015-01-03.
//  Copyright (c) 2015 SourceKitten. All rights reserved.
//

import Foundation
import SourceKittenFramework
import XCTest

class StructureTests: XCTestCase {

    func testPrintEmptyStructure() {
        let expected: NSDictionary = [
            "key.offset": 0,
            "key.length": 0,
            "key.diagnostic_stage": "source.diagnostic.stage.swift.parse"
        ]
        let structure = Structure(file: File(contents: ""))
        XCTAssertEqual(toNSDictionary(structure.dictionary), expected, "should generate expected structure")
    }

    func testGenerateSameStructureFileAndContents() {
        let fileContents = try! String(contentsOfFile: #file, encoding: .utf8)
        XCTAssertEqual(Structure(file: File(path: #file)!),
            Structure(file: File(contents: fileContents)),
            "should generate the same structure for a file as raw text")
    }

    func testEnum() {
        let structure = Structure(file: File(contents: "enum MyEnum { case First }"))
        let expectedStructure: NSDictionary = [
            "key.substructure": [
                [
                    "key.kind": "source.lang.swift.decl.enum",
                    "key.accessibility": "source.lang.swift.accessibility.internal",
                    "key.offset": 0,
                    "key.nameoffset": 5,
                    "key.namelength": 6,
                    "key.bodyoffset": 13,
                    "key.bodylength": 12,
                    "key.length": 26,
                    "key.substructure": [<commit_msg>Update testPrintEmptyStructure to Swift 3.1<commit_after>//
//  StructureTests.swift
//  SourceKitten
//
//  Created by <NAME> on 2015-01-03.
//  Copyright (c) 2015 SourceKitten. All rights reserved.
//

import Foundation
import SourceKittenFramework
import XCTest

class StructureTests: XCTestCase {

    func testPrintEmptyStructure() {
        #if swift(>=3.1)
            let expected: NSDictionary = [
                "key.offset": 0,
                "key.length": 0,
                "key.diagnostic_stage": "source.diagnostic.stage.swift.parse",
                "key.substructure": []
            ]
        #else
            let expected: NSDictionary = [
                "key.offset": 0,
                "key.length": 0,
                "key.diagnostic_stage": "source.diagnostic.stage.swift.parse"
            ]
        #endif
        let structure = Structure(file: File(contents: ""))
        XCTAssertEqual(toNSDictionary(structure.dictionary), expected, "should generate expected structure")
    }

    func testGenerateSameStructureFileAndContents() {
        let fileContents = try! String(contentsOfFile: #file, encoding: .utf8)
        XCTAssertEqual(Structure(file: File(path: #file)!),
            Structure(file: File(contents: fileContents)),
            "should generate the same structure for a file as raw text")
    }

    func testEnum() {
        let structure = Structure(file: File(contents: "enum MyEnum { case First }"))
        let expectedStructure: NSDictionary = [
            "key.substructure": [
                [
                    "key.kind": "source.lang.swift.decl.enum",
                    "key.accessibility": "source.lang.swift.accessibility.internal",
                    "key.offset": 0,
                    "key.nameoffset": 5,
                    "key.namelength": 6,
                    "key.bodyoffset": 13,
                    "key.bodylength": 12,
                    "key.length": 26,
                    "key.substructure": [
{'fraction_non_alphanumeric': 0.11501244124965442, 'fraction_numerical': 0.014929499585291679, 'mean_word_length': 1.9295546558704453, 'pattern_counts': {'":': 30, '<': 5, '<?xml version=': 0, '>': 6, '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': '2137006', 'n_tokens_mistral': 1053, 'n_tokens_neox': 951, 'n_words': 222}