This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.test.ts
66 lines (53 loc) · 2.1 KB
/
index.test.ts
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
import { deepEqual } from 'assert'
import { translateLinesGivenDiff, diffPositionToFilePosition } from '../src/index'
import { readFileSync } from 'fs'
const fixture = require('js-yaml').safeLoad(readFileSync(require.resolve('./index.fixture.yaml')))
describe('translateLinesGivenDiff', () => {
it('translates rows after applying a diff', () => {
const {diff, positions} = fixture.three_hunk_diff
const startPositions = positions.map(position => position.before)
const translations = translateLinesGivenDiff(startPositions, diff)
positions.forEach(position => {
const {before, after, invalidated} = position
deepEqual(translations.get(before), {
newPosition: after,
invalidated
})
})
})
it('handles lines added at the beginning and end of file', () => {
const {diff, positions} = fixture.added_lines_at_ends
const startPositions = positions.map(position => position.before)
const translations = translateLinesGivenDiff(startPositions, diff)
positions.forEach(position => {
const {before, after, invalidated} = position
deepEqual(translations.get(before), {
newPosition: after,
invalidated
})
})
})
it('handles lines deleted at the beginning and end of file', () => {
const {diff, positions} = fixture.removed_lines_at_ends
const startPositions = positions.map(position => position.before)
const translations = translateLinesGivenDiff(startPositions, diff)
positions.forEach(position => {
const {before, after, invalidated} = position
deepEqual(translations.get(before), {
newPosition: after,
invalidated
})
})
})
})
describe('diffPositionToFilePosition', () => {
it('returns a map of the diff to file positions', () => {
const {diff, positions} = fixture.mid_file_hunks
const diffPositions = positions.map(position => position.diff)
const diffToFilePosition = diffPositionToFilePosition(diffPositions, diff)
positions.forEach(position => {
const {diff, file} = position
deepEqual(diffToFilePosition.get(diff), file)
})
})
})