<commit_before>{$} = require 'atom-space-pen-views'
{values} = require 'underscore-plus'

describe "Bookmarks package", ->
  [workspaceElement, editorElement, editor, bookmarks] = []

  bookmarkedRangesForEditor = (editor) ->
    values(editor.decorationsStateForScreenRowRange(0, editor.getLastScreenRow()))
      .filter (decoration) -> decoration.properties.class is 'bookmarked'
      .map (decoration) -> decoration.screenRange

  beforeEach ->
    spyOn(window, 'setImmediate').andCallFake (fn) -> fn()
    workspaceElement = atom.views.getView(atom.workspace)

    waitsForPromise ->
      atom.workspace.open('sample.js')

    waitsForPromise ->
      atom.packages.activatePackage('bookmarks').then (p) -> bookmarks = p.mainModule

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

  describe "toggling bookmarks", ->
    describe "point marker bookmark", ->
      it "creates a marker when toggled", ->
        editor.setCursorBufferPosition([3, 10])
        expect(bookmarkedRangesForEditor(editor)).toEqual []
        atom.commands.dispatch editorElement, 'bookmarks:toggle-bookmark'
        expect(bookmarkedRangesForEditor(editor)).toEqual [[[3, 10], [3, 10]]]

      it "removes marker when toggled", ->
        editor.setCursorBufferPosition([3, 10])
        expect(bookmarkedRangesForEditor(editor).length).toBe 0

        atom.commands.dispatch editorElement, 'bookmarks:toggle-bookmark'
        expect(bookmarkedRangesForEditor(editor).length).toBe 1

        atom.commands.dispatch editorElement, 'bookmarks:toggle-bookmark'
        expect(bookmarkedRangesForEditor(editor).length).toBe 0

    describe "multiple point marker bookmark", ->
      it "creates multiple markers when toggled", ->
        editor.setCursorBufferPosition([3, 10])
        editor.addCursorAtBufferPosition([6, 11])
        expect(bookmarkedRangesForEditor(editor)).toEqual []
        atom.commands.dispatch editorElement, 'bookmarks:toggle-bookmark'
        expect(bookmarkedRangesForEditor(editor)).toEqual [[[3, 10], [3, 10]], [[6, 11], [6, 11]]]

      it "removes multiple markers when toggled", ->
        editor.setCursorBufferPosition([3, 10])
        editor.addCursorAtBufferPosition([6, 11])
        expect(bookmarkedRangesForEditor(editor).length).toBe 0

        atom.commands.dispatch editorElement, 'bookmarks:toggle-bookmark'
        expect(bookmarkedRangesForEditor(editor).length).toBe 2

        atom.commands.dispatch editorElement, 'bookmarks:toggle-bookmark'
        expect(bookmarkedRangesForEditor(editor).length).toBe 0
<commit_msg>Add a spec for simultaneous adding/deleting bookmarks with multiple cursor<commit_after>{$} = require 'atom-space-pen-views'
{values} = require 'underscore-plus'

describe "Bookmarks package", ->
  [workspaceElement, editorElement, editor, bookmarks] = []

  bookmarkedRangesForEditor = (editor) ->
    values(editor.decorationsStateForScreenRowRange(0, editor.getLastScreenRow()))
      .filter (decoration) -> decoration.properties.class is 'bookmarked'
      .map (decoration) -> decoration.screenRange

  beforeEach ->
    spyOn(window, 'setImmediate').andCallFake (fn) -> fn()
    workspaceElement = atom.views.getView(atom.workspace)

    waitsForPromise ->
      atom.workspace.open('sample.js')

    waitsForPromise ->
      atom.packages.activatePackage('bookmarks').then (p) -> bookmarks = p.mainModule

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

  describe "toggling bookmarks", ->
    describe "point marker bookmark", ->
      it "creates a marker when toggled", ->
        editor.setCursorBufferPosition([3, 10])
        expect(bookmarkedRangesForEditor(editor)).toEqual []
        atom.commands.dispatch editorElement, 'bookmarks:toggle-bookmark'
        expect(bookmarkedRangesForEditor(editor)).toEqual [[[3, 10], [3, 10]]]

      it "removes marker when toggled", ->
        editor.setCursorBufferPosition([3, 10])
        expect(bookmarkedRangesForEditor(editor).length).toBe 0

        atom.commands.dispatch editorElement, 'bookmarks:toggle-bookmark'
        expect(bookmarkedRangesForEditor(editor).length).toBe 1

        atom.commands.dispatch editorElement, 'bookmarks:toggle-bookmark'
        expect(bookmarkedRangesForEditor(editor).length).toBe 0

    describe "multiple point marker bookmark", ->
      it "creates multiple markers when toggled", ->
        editor.setCursorBufferPosition([3, 10])
        editor.addCursorAtBufferPosition([6, 11])
        expect(bookmarkedRangesForEditor(editor)).toEqual []
        atom.commands.dispatch editorElement, 'bookmarks:toggle-bookmark'
        expect(bookmarkedRangesForEditor(editor)).toEqual [[[3, 10], [3, 10]], [[6, 11], [6, 11]]]

      it "removes multiple markers when toggled", ->
        editor.setCursorBufferPosition([3, 10])
        editor.addCursorAtBufferPosition([6, 11])
        expect(bookmarkedRangesForEditor(editor).length).toBe 0
        atom.commands.dispatch editorElement, 'bookmarks:toggle-bookmark'
        expect(bookmarkedRangesForEditor(editor).length).toBe 2
        atom.commands.dispatch editorElement, 'bookmarks:toggle-bookmark'
        expect(bookmarkedRangesForEditor(editor).length).toBe 0

      it "adds and removes multiple markers at the same time", ->
        editor.setCursorBufferPosition([3, 10])
        expect(bookmarkedRangesForEditor(editor).length).toBe 0
        atom.commands.dispatch editorElement, 'bookmarks:toggle-bookmark'
        expect(bookmarkedRangesForEditor(editor)).toEqual [[[3, 10], [3, 10]]]

        editor.addCursorAtBufferPosition([6, 11])
        atom.commands.dispatch editorElement, 'bookmarks:toggle-bookmark'
        expect(bookmarkedRangesForEditor(editor)).toEqual [[[6, 11], [6, 11]]]

        editor.addCursorAtBufferPosition([8, 8])
        editor.addCursorAtBufferPosition([11, 8])
        atom.commands.dispatch editorElement, 'bookmarks:toggle-bookmark'
        expect(bookmarkedRangesForEditor(editor)).toEqual [[[3, 10], [3, 10]], [[8, 8], [8, 8]], [[11, 8], [11, 8]]]

        # reset cursors, and try multiple cursors on same line but different ranges
        editor.setCursorBufferPosition([8, 40])
        atom.commands.dispatch editorElement, 'bookmarks:toggle-bookmark'
        expect(bookmarkedRangesForEditor(editor)).toEqual [[[3, 10], [3, 10]], [[11, 8], [11, 8]]]

        editor.addCursorAtBufferPosition([3, 0])
        editor.addCursorAtBufferPosition([11, 0])
        atom.commands.dispatch editorElement, 'bookmarks:toggle-bookmark'
        expect(bookmarkedRangesForEditor(editor)).toEqual [[[8, 40], [8, 40]]]

        editor.setCursorBufferPosition([8, 0])
        atom.commands.dispatch editorElement, 'bookmarks:toggle-bookmark'
        expect(bookmarkedRangesForEditor(editor).length).toBe 0

{'fraction_non_alphanumeric': 0.12541065562062562, 'fraction_numerical': 0.022139694329381517, 'mean_word_length': 3.8625, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 38, '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': '795500', 'n_tokens_mistral': 2147, 'n_tokens_neox': 1988, 'n_words': 386}