forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff-hunk-spec.js
More file actions
89 lines (70 loc) · 2.81 KB
/
Copy pathdiff-hunk-spec.js
File metadata and controls
89 lines (70 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/** @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("emits an event when created from a string on an empty object", function() {
let changeHandler = jasmine.createSpy()
diffHunk = new DiffHunk()
diffHunk.onDidChange(changeHandler)
diffHunk.fromString(HunkStr)
expect(changeHandler).toHaveBeenCalled()
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:`