<commit_before>/** @babel */

import EventTransactor from '../lib/event-transactor'

describe('EventTransactor', function () {
  let emitter, transactor

  beforeEach(function () {
    emitter = {
      emit: jasmine.createSpy('emit')
    }
    transactor = new EventTransactor(emitter)
  })

  it('emits one event when didChange is called', function () {
    transactor.didChange()
    expect(emitter.emit).toHaveBeenCalledWith('did-change')
    expect(emitter.emit.callCount).toBe(1)
  })

  it('emits one event when didChange is called multiple times in an transaction', function () {
    transactor.transact(() => {
      transactor.didChange()
      transactor.didChange()
      transactor.didChange()
    })
    expect(emitter.emit).toHaveBeenCalledWith('did-change')
    expect(emitter.emit.callCount).toBe(1)
  })

  it('emits one event when transactions are nested', function () {
    transactor.transact(() => {
      transactor.transact(() => {
        transactor.didChange()
        transactor.didChange()
        transactor.didChange()
      })
      transactor.transact(() => {
        transactor.didChange()
        transactor.didChange()
        transactor.didChange()
      })
    })
    expect(emitter.emit).toHaveBeenCalledWith('did-change')
    expect(emitter.emit.callCount).toBe(1)
  })

  it('does not emit when an empty transaction is executed', function () {
    transactor.transact(() => {})
    expect(emitter.emit).not.toHaveBeenCalled()
  })
})<commit_msg>Test transactor events<commit_after>/** @babel */

import EventTransactor from '../lib/event-transactor'

describe('EventTransactor', function () {
  let emitter, transactor

  beforeEach(function () {
    emitter = {
      emit: jasmine.createSpy('emit')
    }
    transactor = new EventTransactor(emitter)
  })

  it('emits one event when didChange is called', function () {
    transactor.didChange()
    expect(emitter.emit.callCount).toBe(1)
    let args = emitter.emit.mostRecentCall.args
    expect(args[0]).toBe('did-change')
  })

  it('emits one event when didChange is called multiple times in an transaction', function () {
    transactor.transact(() => {
      transactor.didChange({line: 1})
      transactor.didChange({line: 2})
      transactor.didChange({line: 3})
    })

    expect(emitter.emit.callCount).toBe(1)
    let args = emitter.emit.mostRecentCall.args
    let eventObj = args[1]
    expect(args[0]).toBe('did-change')
    expect(eventObj.events).toHaveLength(3)
    expect(eventObj.events[0].line).toBe(1)
    expect(eventObj.events[2].line).toBe(3)
  })

  it('emits one event when transactions are nested', function () {
    transactor.transact(() => {
      transactor.transact(() => {
        transactor.didChange()
        transactor.didChange()
        transactor.didChange()
      })
      transactor.transact(() => {
        transactor.didChange()
        transactor.didChange()
        transactor.didChange()
      })
    })
    expect(emitter.emit.callCount).toBe(1)
    let args = emitter.emit.mostRecentCall.args
    expect(args[0]).toBe('did-change')
  })

  it('does not emit when an empty transaction is executed', function () {
    transactor.transact(() => {})
    expect(emitter.emit).not.toHaveBeenCalled()
  })
})
{'fraction_non_alphanumeric': 0.1450569756698491, 'fraction_numerical': 0.00554357868801971, 'mean_word_length': 3.25130890052356, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '2109229', 'n_tokens_mistral': 1010, 'n_tokens_neox': 973, 'n_words': 178}