<commit_before>//
//  AutoCompleteSpec.swift
//  Ello
//
//  Created by Sean on 7/13/15.
//  Copyright (c) 2015 Ello. All rights reserved.
//

import Ello
import Quick
import Nimble

import Result

class AutoCompleteSpec: QuickSpec {
    override func spec() {
        describe("AutoComplete") {

            let subject = AutoComplete()

            describe("check(_:location)") {

                context("username") {
                    it("returns the correct character range and string") {
                        let str = "@sean"
                        let result = subject.check(str, location: 2)

                        expect(result?.type) == AutoCompleteType.Username
                        expect(result?.range) == str.startIndex..<str.startIndex.advancedBy(3)
                        expect(result?.text) == "@se"
                    }
                }

                context("username in long string") {
                    it("returns the correct character range and string") {
                        let str = "hi there @sean"
                        let result = subject.check(str, location: 12)

                        expect(result?.type) == AutoCompleteType.Username
                        expect(result?.range) == str.startIndex.advancedBy(9)..<str.startIndex.advancedBy(13)
                        expect(result?.text) == "@sea"
                    }
                }

                context("emoji") {
                    it("returns the correct character range and string") {<commit_msg>specs around empty / single space Autocomplete (detects the crash)<commit_after>//
//  AutoCompleteSpec.swift
//  Ello
//
//  Created by Sean on 7/13/15.
//  Copyright (c) 2015 Ello. All rights reserved.
//

import Ello
import Quick
import Nimble

import Result

class AutoCompleteSpec: QuickSpec {
    override func spec() {
        describe("AutoComplete") {

            let subject = AutoComplete()

            describe("check(_:location)") {

                context("empty") {
                    it("returns nil") {
                        let str = ""
                        let result = subject.check(str, location: 0)

                        expect(result).to(beNil())
                    }
                }

                context("single space") {
                    it("returns nil") {
                        let str = " "
                        let result = subject.check(str, location: 0)

                        expect(result).to(beNil())
                    }
                }

                context("username") {
                    it("returns the correct character range and string") {
                        let str = "@sean"
                        let result = subject.check(str, location: 2)

                        expect(result?.type) == AutoCompleteType.Username
                        expect(result?.range) == str.startIndex..<str.startIndex.advancedBy(3)
                        expect(result?.text) == "@se"
                    }
                }

                context("username in long string") {
                    it("returns the correct character range and string") {
                        let str = "hi there @sean"
                        let result = subject.check(str, location: 12)

                        expect(result?.type) == AutoCompleteType.Username
                        expect(result?.range) == str.startIndex.advancedBy(9)..<str.startIndex.advancedBy(13)
                        expect(result?.text) == "@sea"
                    }
                }

                context("emoji") {
                    it("returns the correct character range and string") {
{'fraction_non_alphanumeric': 0.10527754990429314, 'fraction_numerical': 0.009297238173366147, 'mean_word_length': 1.2734617775015538, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '4259431', 'n_tokens_mistral': 928, 'n_tokens_neox': 817, 'n_words': 213}