<commit_before>/** @babel */

import DiffHunk from '../lib/diff-hunk'

describe("DiffHunk", function() {
  it("roundtrips toString and fromString", function() {
    let hunk = HunkStr
    let diffHunk = DiffHunk.fromString(hunk)
    expect(diffHunk.toString()).toEqual(hunk)
  })

  it("stages all lines with ::stage() and unstages all lines with ::unstage()", function() {
    let diffHunk = DiffHunk.fromString(HunkStr)
    expect(diffHunk.getStageStatus()).toBe('unstaged')

    diffHunk.stage()
    expect(diffHunk.getStageStatus()).toBe('staged')
    expect(diffHunk.getLines()[3].isStaged()).toBe(true)
    expect(diffHunk.getLines()[4].isStaged()).toBe(true)
    expect(diffHunk.getLines()[5].isStaged()).toBe(true)

    diffHunk.unstage()
    expect(diffHunk.getStageStatus()).toBe('unstaged')
    expect(diffHunk.getLines()[3].isStaged()).toBe(false)
    expect(diffHunk.getLines()[4].isStaged()).toBe(false)
    expect(diffHunk.getLines()[5].isStaged()).toBe(false)
  })

  it("returns 'partial' from getStageStatus() when some of the lines are staged", function() {
    let diffHunk = DiffHunk.fromString(HunkStr)
    expect(diffHunk.getStageStatus()).toBe('unstaged')

    diffHunk.getLines()[3].stage()
    expect(diffHunk.getStageStatus()).toBe('partial')

    diffHunk.getLines()[3].unstage()
    expect(diffHunk.getStageStatus()).toBe('unstaged')
  })

  it("emits one change event when the hunk is staged", function() {
    let changeHandler = jasmine.createSpy()
    let diffHunk = DiffHunk.fromString(HunkStr)
    diffHunk.onDidChange(changeHandler)

    diffHunk.stage()
    expect(changeHandler.callCount).toBe(1)
  })

  it("emits a change event when a line is staged", function() {
    let changeHandler = jasmine.createSpy()
    let diffHunk = DiffHunk.fromString(HunkStr)
    diffHunk.onDidChange(changeHandler)

    diffHunk.getLines()[3].stage()
    expect(changeHandler).toHaveBeenCalled()
  })
})

HunkStr = `HUNK @@ -85,9 +85,6 @@ ScopeDescriptor = require './scope-descriptor'
  85 85   #
  86 86   # ## Config Schemas
  87 87   #
  88 --- - # We use [json schema](http://json-schema.org) which allows you to define your value's
  89 --- - # default, the type it should be, etc. A simple example:
  90 --- - #
  91 88   # \`\`\`coffee
  92 89   # # We want to provide an \`enableThing\`, and a \`thingVolume\`
  93 90   # config:`
<commit_msg>Specs for header and line events<commit_after>/** @babel */

import DiffHunk from '../lib/diff-hunk'

describe("DiffHunk", function() {
  let diffHunk
  beforeEach(function() {
    diffHunk = DiffHunk.fromString(HunkStr)
  })

  it("roundtrips toString and fromString", function() {
    expect(diffHunk.toString()).toEqual(HunkStr)
  })

  it("stages all lines with ::stage() and unstages all lines with ::unstage()", function() {
    expect(diffHunk.getStageStatus()).toBe('unstaged')

    diffHunk.stage()
    expect(diffHunk.getStageStatus()).toBe('staged')
    expect(diffHunk.getLines()[3].isStaged()).toBe(true)
    expect(diffHunk.getLines()[4].isStaged()).toBe(true)
    expect(diffHunk.getLines()[5].isStaged()).toBe(true)

    diffHunk.unstage()
    expect(diffHunk.getStageStatus()).toBe('unstaged')
    expect(diffHunk.getLines()[3].isStaged()).toBe(false)
    expect(diffHunk.getLines()[4].isStaged()).toBe(false)
    expect(diffHunk.getLines()[5].isStaged()).toBe(false)
  })

  it("returns 'partial' from getStageStatus() when some of the lines are staged", function() {
    expect(diffHunk.getStageStatus()).toBe('unstaged')

    diffHunk.getLines()[3].stage()
    expect(diffHunk.getStageStatus()).toBe('partial')

    diffHunk.getLines()[3].unstage()
    expect(diffHunk.getStageStatus()).toBe('unstaged')
  })

  it("emits one change event when the hunk is staged", function() {
    let changeHandler = jasmine.createSpy()
    diffHunk.onDidChange(changeHandler)

    diffHunk.stage()
    expect(changeHandler.callCount).toBe(1)
  })

  it("emits a change event when a line is staged", function() {
    let changeHandler = jasmine.createSpy()
    diffHunk.onDidChange(changeHandler)

    diffHunk.getLines()[3].stage()
    expect(changeHandler).toHaveBeenCalled()
  })

  it("emits events when the header and lines change", function() {
    let changeHandler = jasmine.createSpy()
    diffHunk.onDidChange(changeHandler)

    diffHunk.setHeader('@@ -85,9 +85,6 @@ someline ok yeah')
    expect(changeHandler).toHaveBeenCalled()

    changeHandler.reset()
    diffHunk.setLines([])
    expect(changeHandler).toHaveBeenCalled()
  })
})

HunkStr = `HUNK @@ -85,9 +85,6 @@ ScopeDescriptor = require './scope-descriptor'
  85 85   #
  86 86   # ## Config Schemas
  87 87   #
  88 --- - # We use [json schema](http://json-schema.org) which allows you to define your value's
  89 --- - # default, the type it should be, etc. A simple example:
  90 --- - #
  91 88   # \`\`\`coffee
  92 89   # # We want to provide an \`enableThing\`, and a \`thingVolume\`
  93 90   # config:`

{'fraction_non_alphanumeric': 0.15958089865001007, 'fraction_numerical': 0.019746121297602257, 'mean_word_length': 3.978936810431294, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6307309', 'n_tokens_mistral': 1743, 'n_tokens_neox': 1666, 'n_words': 335}