<commit_before>path = require 'path'
{Range, Point} = require 'atom'
HighlightSelected = require '../lib/highlight-selected'
sinon = require 'sinon'

# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.

describe "HighlightSelected", ->
  [activationPromise, workspaceElement, minimap, clock,
   editor, editorElement, highlightSelected, minimapHS, minimapModule] = []

  hasMinimap = atom.packages.getAvailablePackageNames()
    .indexOf('minimap') isnt -1 and atom.packages.getAvailablePackageNames()
    .indexOf('minimap-highlight-selected') isnt -1

  beforeEach ->
    clock = sinon.useFakeTimers()

    workspaceElement = atom.views.getView(atom.workspace)
    atom.project.setPaths([path.join(__dirname, 'fixtures')])

    waitsForPromise ->
      atom.packages.activatePackage('highlight-selected').then ({mainModule}) ->
        highlightSelected = mainModule

    if hasMinimap
      waitsForPromise ->
        atom.packages.activatePackage('minimap').then ({mainModule}) ->
          minimapModule = mainModule
      waitsForPromise ->
        atom.packages.activatePackage('minimap-highlight-selected')
          .then ({mainModule}) ->
            minimapHS = mainModule

    waitsForPromise ->
      atom.workspace.open('sample.coffee').then(
        (editor) -> editor
        ,
        (error) -> throw(error.stack)
      )

    runs ->
      jasmine.attachToDOM(workspaceElement)
      editor = atom.workspace.getActiveTextEditor()
      editorElement = atom.views.getView(editor)

  afterEach ->
    clock.restore()
    highlightSelected.deactivate()
    minimapHS?.deactivate()
    minimapModule?.deactivate()

  describe "updates debounce when config is changed", ->
    beforeEach ->
      spyOn(highlightSelected.areaView, 'createDebounce')
      atom.config.set('highlight-selected.timeout', 500)

    it 'calls createDebouce', ->
      expect(highlightSelected.areaView.createDebounce).toHaveBeenCalled()

  describe "when a whole word is selected", ->
    beforeEach ->
      range = new Range(new Point(8, 2), new Point(8, 8))
      editor.setSelectedBufferRange(range)
      clock.tick(20000)

    it "adds the decoration to all words", ->
      expect(editorElement.shadowRoot
        .querySelectorAll('.highlight-selected .region')
        ).toHaveLength(4)
<commit_msg>See if this fixes the build?<commit_after>path = require 'path'
{Range, Point} = require 'atom'
HighlightSelected = require '../lib/highlight-selected'
sinon = require 'sinon'

# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.

describe "HighlightSelected", ->
  [activationPromise, workspaceElement, minimap, clock,
   editor, editorElement, highlightSelected, minimapHS, minimapModule] = []

  hasMinimap = atom.packages.getAvailablePackageNames()
    .indexOf('minimap') isnt -1 and atom.packages.getAvailablePackageNames()
    .indexOf('minimap-highlight-selected') isnt -1

  beforeEach ->
    clock = sinon.useFakeTimers()

    workspaceElement = atom.views.getView(atom.workspace)
    atom.project.setPaths([path.join(__dirname, 'fixtures')])

    waitsForPromise ->
      atom.packages.activatePackage('highlight-selected').then ({mainModule}) ->
        highlightSelected = mainModule

    if hasMinimap
      waitsForPromise ->
        atom.packages.activatePackage('minimap').then ({mainModule}) ->
          minimapModule = mainModule
      waitsForPromise ->
        atom.packages.activatePackage('minimap-highlight-selected')
          .then ({mainModule}) ->
            minimapHS = mainModule

    waitsForPromise ->
      atom.workspace.open('sample.coffee').then(
        (editor) -> editor
        ,
        (error) -> throw(error.stack)
      )

    runs ->
      jasmine.attachToDOM(workspaceElement)
      editor = atom.workspace.getActiveTextEditor()
      editorElement = atom.views.getView(editor)

  afterEach ->
    clock.restore()

  describe "updates debounce when config is changed", ->
    beforeEach ->
      spyOn(highlightSelected.areaView, 'createDebounce')
      atom.config.set('highlight-selected.timeout', 500)

    it 'calls createDebouce', ->
      expect(highlightSelected.areaView.createDebounce).toHaveBeenCalled()

  describe "when a whole word is selected", ->
    beforeEach ->
      range = new Range(new Point(8, 2), new Point(8, 8))
      editor.setSelectedBufferRange(range)
      clock.tick(20000)

    it "adds the decoration to all words", ->
      expect(editorElement.shadowRoot
        .querySelectorAll('.highlight-selected .region')
        ).toHaveLength(4)

{'fraction_non_alphanumeric': 0.1212784588441331, 'fraction_numerical': 0.006567425569176883, 'mean_word_length': 3.294172932330827, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 41, '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': '2959196', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1308, 'n_words': 260}