forked from microsoft/vscode-pull-request-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.test.ts
More file actions
89 lines (81 loc) · 2.71 KB
/
Copy pathextension.test.ts
File metadata and controls
89 lines (81 loc) · 2.71 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
import * as assert from 'assert';
import { parseDiffHunk } from '../common/diffHunk';
describe('Extension Tests', function () {
describe('parseDiffHunk', () => {
it('should handle empty string', () => {
const diffHunk = parseDiffHunk('');
const itr = diffHunk.next();
assert.equal(itr.done, true);
});
it('should handle additions', () => {
const patch = [
`@@ -5,6 +5,9 @@ if (!defined $initial_reply_to && $prompting) {`,
` }`,
` `,
` if (!$smtp_server) {`,
`+ $smtp_server = $repo->config('sendemail.smtpserver');`,
`+}`,
`+if (!$smtp_server) {`,
` foreach (qw( /usr/sbin/sendmail /usr/lib/sendmail )) {`,
` if (-x $_) {`,
` $smtp_server = $_;`,
].join('\n');
const diffHunk = parseDiffHunk(patch);
const itr = diffHunk.next();
assert.notEqual(itr.value, undefined);
assert.equal(itr.value.oldLineNumber, 5);
assert.equal(itr.value.newLineNumber, 5);
assert.equal(itr.value.oldLength, 6);
assert.equal(itr.value.newLength, 9);
assert.equal(itr.value.positionInHunk, 0);
assert.equal(itr.value.diffLines.length, 10);
});
it('should handle deletions', () => {
const patch = [
`@@ -5,9 +5,6 @@ if (!defined $initial_reply_to && $prompting) {`,
` }`,
` `,
` if (!$smtp_server) {`,
`- $smtp_server = $repo->config('sendemail.smtpserver');`,
`-}`,
`-if (!$smtp_server) {`,
` foreach (qw( /usr/sbin/sendmail /usr/lib/sendmail )) {`,
` if (-x $_) {`,
` $smtp_server = $_;`,
].join('\n');
const diffHunk = parseDiffHunk(patch);
const itr = diffHunk.next();
assert.notEqual(itr.value, undefined);
assert.equal(itr.value.oldLineNumber, 5);
assert.equal(itr.value.newLineNumber, 5);
assert.equal(itr.value.oldLength, 9);
assert.equal(itr.value.newLength, 6);
assert.equal(itr.value.positionInHunk, 0);
assert.equal(itr.value.diffLines.length, 10);
});
it('should handle replacements', () => {
const patch = [
`@@ -5,9 +5,7 @@ if (!defined $initial_reply_to && $prompting) {`,
` }`,
` `,
` if (!$smtp_server) {`,
`- $smtp_server = $repo->config('sendemail.smtpserver');`,
`-}`,
`-if (!$smtp_server) {`,
`+if (fpt_server) {`,
` foreach (qw( /usr/sbin/sendmail /usr/lib/sendmail )) {`,
` if (-x $_) {`,
` $smtp_server = $_;`,
].join('\n');
const diffHunk = parseDiffHunk(patch);
const itr = diffHunk.next();
assert.notEqual(itr.value, undefined);
assert.equal(itr.value.oldLineNumber, 5);
assert.equal(itr.value.newLineNumber, 5);
assert.equal(itr.value.oldLength, 9);
assert.equal(itr.value.newLength, 7);
assert.equal(itr.value.positionInHunk, 0);
assert.equal(itr.value.diffLines.length, 11);
});
});
});