Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/git/src/test/git.test.ts
3320 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import 'mocha';
7
import { GitStatusParser, parseGitCommits, parseGitmodules, parseLsTree, parseLsFiles, parseGitRemotes } from '../git';
8
import * as assert from 'assert';
9
import { splitInChunks } from '../util';
10
11
suite('git', () => {
12
suite('GitStatusParser', () => {
13
test('empty parser', () => {
14
const parser = new GitStatusParser();
15
assert.deepStrictEqual(parser.status, []);
16
});
17
18
test('empty parser 2', () => {
19
const parser = new GitStatusParser();
20
parser.update('');
21
assert.deepStrictEqual(parser.status, []);
22
});
23
24
test('simple', () => {
25
const parser = new GitStatusParser();
26
parser.update('?? file.txt\0');
27
assert.deepStrictEqual(parser.status, [
28
{ path: 'file.txt', rename: undefined, x: '?', y: '?' }
29
]);
30
});
31
32
test('simple 2', () => {
33
const parser = new GitStatusParser();
34
parser.update('?? file.txt\0');
35
parser.update('?? file2.txt\0');
36
parser.update('?? file3.txt\0');
37
assert.deepStrictEqual(parser.status, [
38
{ path: 'file.txt', rename: undefined, x: '?', y: '?' },
39
{ path: 'file2.txt', rename: undefined, x: '?', y: '?' },
40
{ path: 'file3.txt', rename: undefined, x: '?', y: '?' }
41
]);
42
});
43
44
test('empty lines', () => {
45
const parser = new GitStatusParser();
46
parser.update('');
47
parser.update('?? file.txt\0');
48
parser.update('');
49
parser.update('');
50
parser.update('?? file2.txt\0');
51
parser.update('');
52
parser.update('?? file3.txt\0');
53
parser.update('');
54
assert.deepStrictEqual(parser.status, [
55
{ path: 'file.txt', rename: undefined, x: '?', y: '?' },
56
{ path: 'file2.txt', rename: undefined, x: '?', y: '?' },
57
{ path: 'file3.txt', rename: undefined, x: '?', y: '?' }
58
]);
59
});
60
61
test('combined', () => {
62
const parser = new GitStatusParser();
63
parser.update('?? file.txt\0?? file2.txt\0?? file3.txt\0');
64
assert.deepStrictEqual(parser.status, [
65
{ path: 'file.txt', rename: undefined, x: '?', y: '?' },
66
{ path: 'file2.txt', rename: undefined, x: '?', y: '?' },
67
{ path: 'file3.txt', rename: undefined, x: '?', y: '?' }
68
]);
69
});
70
71
test('split 1', () => {
72
const parser = new GitStatusParser();
73
parser.update('?? file.txt\0?? file2');
74
parser.update('.txt\0?? file3.txt\0');
75
assert.deepStrictEqual(parser.status, [
76
{ path: 'file.txt', rename: undefined, x: '?', y: '?' },
77
{ path: 'file2.txt', rename: undefined, x: '?', y: '?' },
78
{ path: 'file3.txt', rename: undefined, x: '?', y: '?' }
79
]);
80
});
81
82
test('split 2', () => {
83
const parser = new GitStatusParser();
84
parser.update('?? file.txt');
85
parser.update('\0?? file2.txt\0?? file3.txt\0');
86
assert.deepStrictEqual(parser.status, [
87
{ path: 'file.txt', rename: undefined, x: '?', y: '?' },
88
{ path: 'file2.txt', rename: undefined, x: '?', y: '?' },
89
{ path: 'file3.txt', rename: undefined, x: '?', y: '?' }
90
]);
91
});
92
93
test('split 3', () => {
94
const parser = new GitStatusParser();
95
parser.update('?? file.txt\0?? file2.txt\0?? file3.txt');
96
parser.update('\0');
97
assert.deepStrictEqual(parser.status, [
98
{ path: 'file.txt', rename: undefined, x: '?', y: '?' },
99
{ path: 'file2.txt', rename: undefined, x: '?', y: '?' },
100
{ path: 'file3.txt', rename: undefined, x: '?', y: '?' }
101
]);
102
});
103
104
test('rename', () => {
105
const parser = new GitStatusParser();
106
parser.update('R newfile.txt\0file.txt\0?? file2.txt\0?? file3.txt\0');
107
assert.deepStrictEqual(parser.status, [
108
{ path: 'file.txt', rename: 'newfile.txt', x: 'R', y: ' ' },
109
{ path: 'file2.txt', rename: undefined, x: '?', y: '?' },
110
{ path: 'file3.txt', rename: undefined, x: '?', y: '?' }
111
]);
112
});
113
114
test('rename split', () => {
115
const parser = new GitStatusParser();
116
parser.update('R newfile.txt\0fil');
117
parser.update('e.txt\0?? file2.txt\0?? file3.txt\0');
118
assert.deepStrictEqual(parser.status, [
119
{ path: 'file.txt', rename: 'newfile.txt', x: 'R', y: ' ' },
120
{ path: 'file2.txt', rename: undefined, x: '?', y: '?' },
121
{ path: 'file3.txt', rename: undefined, x: '?', y: '?' }
122
]);
123
});
124
125
test('rename split 3', () => {
126
const parser = new GitStatusParser();
127
parser.update('?? file2.txt\0R new');
128
parser.update('file.txt\0fil');
129
parser.update('e.txt\0?? file3.txt\0');
130
assert.deepStrictEqual(parser.status, [
131
{ path: 'file2.txt', rename: undefined, x: '?', y: '?' },
132
{ path: 'file.txt', rename: 'newfile.txt', x: 'R', y: ' ' },
133
{ path: 'file3.txt', rename: undefined, x: '?', y: '?' }
134
]);
135
});
136
});
137
138
suite('parseGitmodules', () => {
139
test('empty', () => {
140
assert.deepStrictEqual(parseGitmodules(''), []);
141
});
142
143
test('sample', () => {
144
const sample = `[submodule "deps/spdlog"]
145
path = deps/spdlog
146
url = https://github.com/gabime/spdlog.git
147
`;
148
149
assert.deepStrictEqual(parseGitmodules(sample), [
150
{ name: 'deps/spdlog', path: 'deps/spdlog', url: 'https://github.com/gabime/spdlog.git' }
151
]);
152
});
153
154
test('big', () => {
155
const sample = `[submodule "deps/spdlog"]
156
path = deps/spdlog
157
url = https://github.com/gabime/spdlog.git
158
[submodule "deps/spdlog2"]
159
path = deps/spdlog2
160
url = https://github.com/gabime/spdlog.git
161
[submodule "deps/spdlog3"]
162
path = deps/spdlog3
163
url = https://github.com/gabime/spdlog.git
164
[submodule "deps/spdlog4"]
165
path = deps/spdlog4
166
url = https://github.com/gabime/spdlog4.git
167
`;
168
169
assert.deepStrictEqual(parseGitmodules(sample), [
170
{ name: 'deps/spdlog', path: 'deps/spdlog', url: 'https://github.com/gabime/spdlog.git' },
171
{ name: 'deps/spdlog2', path: 'deps/spdlog2', url: 'https://github.com/gabime/spdlog.git' },
172
{ name: 'deps/spdlog3', path: 'deps/spdlog3', url: 'https://github.com/gabime/spdlog.git' },
173
{ name: 'deps/spdlog4', path: 'deps/spdlog4', url: 'https://github.com/gabime/spdlog4.git' }
174
]);
175
});
176
177
test('whitespace #74844', () => {
178
const sample = `[submodule "deps/spdlog"]
179
path = deps/spdlog
180
url = https://github.com/gabime/spdlog.git
181
`;
182
183
assert.deepStrictEqual(parseGitmodules(sample), [
184
{ name: 'deps/spdlog', path: 'deps/spdlog', url: 'https://github.com/gabime/spdlog.git' }
185
]);
186
});
187
188
test('whitespace again #108371', () => {
189
const sample = `[submodule "deps/spdlog"]
190
path= deps/spdlog
191
url=https://github.com/gabime/spdlog.git
192
`;
193
194
assert.deepStrictEqual(parseGitmodules(sample), [
195
{ name: 'deps/spdlog', path: 'deps/spdlog', url: 'https://github.com/gabime/spdlog.git' }
196
]);
197
});
198
});
199
200
suite('parseGitRemotes', () => {
201
test('empty', () => {
202
assert.deepStrictEqual(parseGitRemotes(''), []);
203
});
204
205
test('single remote', () => {
206
const sample = `[remote "origin"]
207
url = https://github.com/microsoft/vscode.git
208
fetch = +refs/heads/*:refs/remotes/origin/*
209
`;
210
211
assert.deepStrictEqual(parseGitRemotes(sample), [
212
{ name: 'origin', fetchUrl: 'https://github.com/microsoft/vscode.git', pushUrl: 'https://github.com/microsoft/vscode.git', isReadOnly: false }
213
]);
214
});
215
216
test('single remote (multiple urls)', () => {
217
const sample = `[remote "origin"]
218
url = https://github.com/microsoft/vscode.git
219
url = https://github.com/microsoft/vscode2.git
220
fetch = +refs/heads/*:refs/remotes/origin/*
221
`;
222
223
assert.deepStrictEqual(parseGitRemotes(sample), [
224
{ name: 'origin', fetchUrl: 'https://github.com/microsoft/vscode.git', pushUrl: 'https://github.com/microsoft/vscode.git', isReadOnly: false }
225
]);
226
});
227
228
test('multiple remotes', () => {
229
const sample = `[remote "origin"]
230
url = https://github.com/microsoft/vscode.git
231
pushurl = https://github.com/microsoft/vscode1.git
232
fetch = +refs/heads/*:refs/remotes/origin/*
233
[remote "remote2"]
234
url = https://github.com/microsoft/vscode2.git
235
fetch = +refs/heads/*:refs/remotes/origin/*
236
`;
237
238
assert.deepStrictEqual(parseGitRemotes(sample), [
239
{ name: 'origin', fetchUrl: 'https://github.com/microsoft/vscode.git', pushUrl: 'https://github.com/microsoft/vscode1.git', isReadOnly: false },
240
{ name: 'remote2', fetchUrl: 'https://github.com/microsoft/vscode2.git', pushUrl: 'https://github.com/microsoft/vscode2.git', isReadOnly: false }
241
]);
242
});
243
244
test('remotes (white space)', () => {
245
const sample = ` [remote "origin"]
246
url = https://github.com/microsoft/vscode.git
247
pushurl=https://github.com/microsoft/vscode1.git
248
fetch = +refs/heads/*:refs/remotes/origin/*
249
[ remote"remote2"]
250
url = https://github.com/microsoft/vscode2.git
251
fetch = +refs/heads/*:refs/remotes/origin/*
252
`;
253
254
assert.deepStrictEqual(parseGitRemotes(sample), [
255
{ name: 'origin', fetchUrl: 'https://github.com/microsoft/vscode.git', pushUrl: 'https://github.com/microsoft/vscode1.git', isReadOnly: false },
256
{ name: 'remote2', fetchUrl: 'https://github.com/microsoft/vscode2.git', pushUrl: 'https://github.com/microsoft/vscode2.git', isReadOnly: false }
257
]);
258
});
259
260
test('remotes (invalid section)', () => {
261
const sample = `[remote "origin"
262
url = https://github.com/microsoft/vscode.git
263
pushurl = https://github.com/microsoft/vscode1.git
264
fetch = +refs/heads/*:refs/remotes/origin/*
265
`;
266
267
assert.deepStrictEqual(parseGitRemotes(sample), []);
268
});
269
});
270
271
suite('parseGitCommit', () => {
272
test('single parent commit', function () {
273
const GIT_OUTPUT_SINGLE_PARENT =
274
'52c293a05038d865604c2284aa8698bd087915a1\n' +
275
'John Doe\n' +
276
'[email protected]\n' +
277
'1580811030\n' +
278
'1580811031\n' +
279
'8e5a374372b8393906c7e380dbb09349c5385554\n' +
280
'main,branch\n' +
281
'This is a commit message.\x00';
282
283
assert.deepStrictEqual(parseGitCommits(GIT_OUTPUT_SINGLE_PARENT), [{
284
hash: '52c293a05038d865604c2284aa8698bd087915a1',
285
message: 'This is a commit message.',
286
parents: ['8e5a374372b8393906c7e380dbb09349c5385554'],
287
authorDate: new Date(1580811030000),
288
authorName: 'John Doe',
289
authorEmail: '[email protected]',
290
commitDate: new Date(1580811031000),
291
refNames: ['main', 'branch'],
292
shortStat: undefined
293
}]);
294
});
295
296
test('multiple parent commits', function () {
297
const GIT_OUTPUT_MULTIPLE_PARENTS =
298
'52c293a05038d865604c2284aa8698bd087915a1\n' +
299
'John Doe\n' +
300
'[email protected]\n' +
301
'1580811030\n' +
302
'1580811031\n' +
303
'8e5a374372b8393906c7e380dbb09349c5385554 df27d8c75b129ab9b178b386077da2822101b217\n' +
304
'main\n' +
305
'This is a commit message.\x00';
306
307
assert.deepStrictEqual(parseGitCommits(GIT_OUTPUT_MULTIPLE_PARENTS), [{
308
hash: '52c293a05038d865604c2284aa8698bd087915a1',
309
message: 'This is a commit message.',
310
parents: ['8e5a374372b8393906c7e380dbb09349c5385554', 'df27d8c75b129ab9b178b386077da2822101b217'],
311
authorDate: new Date(1580811030000),
312
authorName: 'John Doe',
313
authorEmail: '[email protected]',
314
commitDate: new Date(1580811031000),
315
refNames: ['main'],
316
shortStat: undefined
317
}]);
318
});
319
320
test('no parent commits', function () {
321
const GIT_OUTPUT_NO_PARENTS =
322
'52c293a05038d865604c2284aa8698bd087915a1\n' +
323
'John Doe\n' +
324
'[email protected]\n' +
325
'1580811030\n' +
326
'1580811031\n' +
327
'\n' +
328
'main\n' +
329
'This is a commit message.\x00';
330
331
assert.deepStrictEqual(parseGitCommits(GIT_OUTPUT_NO_PARENTS), [{
332
hash: '52c293a05038d865604c2284aa8698bd087915a1',
333
message: 'This is a commit message.',
334
parents: [],
335
authorDate: new Date(1580811030000),
336
authorName: 'John Doe',
337
authorEmail: '[email protected]',
338
commitDate: new Date(1580811031000),
339
refNames: ['main'],
340
shortStat: undefined
341
}]);
342
});
343
344
test('commit with shortstat', function () {
345
const GIT_OUTPUT_SINGLE_PARENT =
346
'52c293a05038d865604c2284aa8698bd087915a1\n' +
347
'John Doe\n' +
348
'[email protected]\n' +
349
'1580811030\n' +
350
'1580811031\n' +
351
'8e5a374372b8393906c7e380dbb09349c5385554\n' +
352
'main,branch\n' +
353
'This is a commit message.\x00\n' +
354
' 1 file changed, 2 insertions(+), 3 deletion(-)';
355
356
assert.deepStrictEqual(parseGitCommits(GIT_OUTPUT_SINGLE_PARENT), [{
357
hash: '52c293a05038d865604c2284aa8698bd087915a1',
358
message: 'This is a commit message.',
359
parents: ['8e5a374372b8393906c7e380dbb09349c5385554'],
360
authorDate: new Date(1580811030000),
361
authorName: 'John Doe',
362
authorEmail: '[email protected]',
363
commitDate: new Date(1580811031000),
364
refNames: ['main', 'branch'],
365
shortStat: {
366
deletions: 3,
367
files: 1,
368
insertions: 2
369
}
370
}]);
371
});
372
373
test('commit with shortstat (no insertions)', function () {
374
const GIT_OUTPUT_SINGLE_PARENT =
375
'52c293a05038d865604c2284aa8698bd087915a1\n' +
376
'John Doe\n' +
377
'[email protected]\n' +
378
'1580811030\n' +
379
'1580811031\n' +
380
'8e5a374372b8393906c7e380dbb09349c5385554\n' +
381
'main,branch\n' +
382
'This is a commit message.\x00\n' +
383
' 1 file changed, 3 deletion(-)';
384
385
assert.deepStrictEqual(parseGitCommits(GIT_OUTPUT_SINGLE_PARENT), [{
386
hash: '52c293a05038d865604c2284aa8698bd087915a1',
387
message: 'This is a commit message.',
388
parents: ['8e5a374372b8393906c7e380dbb09349c5385554'],
389
authorDate: new Date(1580811030000),
390
authorName: 'John Doe',
391
authorEmail: '[email protected]',
392
commitDate: new Date(1580811031000),
393
refNames: ['main', 'branch'],
394
shortStat: {
395
deletions: 3,
396
files: 1,
397
insertions: 0
398
}
399
}]);
400
});
401
402
test('commit with shortstat (no deletions)', function () {
403
const GIT_OUTPUT_SINGLE_PARENT =
404
'52c293a05038d865604c2284aa8698bd087915a1\n' +
405
'John Doe\n' +
406
'[email protected]\n' +
407
'1580811030\n' +
408
'1580811031\n' +
409
'8e5a374372b8393906c7e380dbb09349c5385554\n' +
410
'main,branch\n' +
411
'This is a commit message.\x00\n' +
412
' 1 file changed, 2 insertions(+)';
413
414
assert.deepStrictEqual(parseGitCommits(GIT_OUTPUT_SINGLE_PARENT), [{
415
hash: '52c293a05038d865604c2284aa8698bd087915a1',
416
message: 'This is a commit message.',
417
parents: ['8e5a374372b8393906c7e380dbb09349c5385554'],
418
authorDate: new Date(1580811030000),
419
authorName: 'John Doe',
420
authorEmail: '[email protected]',
421
commitDate: new Date(1580811031000),
422
refNames: ['main', 'branch'],
423
shortStat: {
424
deletions: 0,
425
files: 1,
426
insertions: 2
427
}
428
}]);
429
});
430
431
test('commit list', function () {
432
const GIT_OUTPUT_SINGLE_PARENT =
433
'52c293a05038d865604c2284aa8698bd087915a1\n' +
434
'John Doe\n' +
435
'[email protected]\n' +
436
'1580811030\n' +
437
'1580811031\n' +
438
'8e5a374372b8393906c7e380dbb09349c5385554\n' +
439
'main,branch\n' +
440
'This is a commit message.\x00\n' +
441
'52c293a05038d865604c2284aa8698bd087915a2\n' +
442
'Jane Doe\n' +
443
'[email protected]\n' +
444
'1580811032\n' +
445
'1580811033\n' +
446
'8e5a374372b8393906c7e380dbb09349c5385555\n' +
447
'main,branch\n' +
448
'This is another commit message.\x00';
449
450
assert.deepStrictEqual(parseGitCommits(GIT_OUTPUT_SINGLE_PARENT), [
451
{
452
hash: '52c293a05038d865604c2284aa8698bd087915a1',
453
message: 'This is a commit message.',
454
parents: ['8e5a374372b8393906c7e380dbb09349c5385554'],
455
authorDate: new Date(1580811030000),
456
authorName: 'John Doe',
457
authorEmail: '[email protected]',
458
commitDate: new Date(1580811031000),
459
refNames: ['main', 'branch'],
460
shortStat: undefined,
461
},
462
{
463
hash: '52c293a05038d865604c2284aa8698bd087915a2',
464
message: 'This is another commit message.',
465
parents: ['8e5a374372b8393906c7e380dbb09349c5385555'],
466
authorDate: new Date(1580811032000),
467
authorName: 'Jane Doe',
468
authorEmail: '[email protected]',
469
commitDate: new Date(1580811033000),
470
refNames: ['main', 'branch'],
471
shortStat: undefined,
472
},
473
]);
474
});
475
476
test('commit list with shortstat', function () {
477
const GIT_OUTPUT_SINGLE_PARENT = '52c293a05038d865604c2284aa8698bd087915a1\n' +
478
'John Doe\n' +
479
'[email protected]\n' +
480
'1580811030\n' +
481
'1580811031\n' +
482
'8e5a374372b8393906c7e380dbb09349c5385554\n' +
483
'main,branch\n' +
484
'This is a commit message.\x00\n' +
485
' 5 file changed, 12 insertions(+), 13 deletion(-)\n' +
486
'52c293a05038d865604c2284aa8698bd087915a2\n' +
487
'Jane Doe\n' +
488
'[email protected]\n' +
489
'1580811032\n' +
490
'1580811033\n' +
491
'8e5a374372b8393906c7e380dbb09349c5385555\n' +
492
'main,branch\n' +
493
'This is another commit message.\x00\n' +
494
' 6 file changed, 22 insertions(+), 23 deletion(-)';
495
496
assert.deepStrictEqual(parseGitCommits(GIT_OUTPUT_SINGLE_PARENT), [{
497
hash: '52c293a05038d865604c2284aa8698bd087915a1',
498
message: 'This is a commit message.',
499
parents: ['8e5a374372b8393906c7e380dbb09349c5385554'],
500
authorDate: new Date(1580811030000),
501
authorName: 'John Doe',
502
authorEmail: '[email protected]',
503
commitDate: new Date(1580811031000),
504
refNames: ['main', 'branch'],
505
shortStat: {
506
deletions: 13,
507
files: 5,
508
insertions: 12
509
}
510
},
511
{
512
hash: '52c293a05038d865604c2284aa8698bd087915a2',
513
message: 'This is another commit message.',
514
parents: ['8e5a374372b8393906c7e380dbb09349c5385555'],
515
authorDate: new Date(1580811032000),
516
authorName: 'Jane Doe',
517
authorEmail: '[email protected]',
518
commitDate: new Date(1580811033000),
519
refNames: ['main', 'branch'],
520
shortStat: {
521
deletions: 23,
522
files: 6,
523
insertions: 22
524
}
525
}]);
526
});
527
});
528
529
suite('parseLsTree', function () {
530
test('sample', function () {
531
const input = `040000 tree 0274a81f8ee9ca3669295dc40f510bd2021d0043 - .vscode
532
100644 blob 1d487c1817262e4f20efbfa1d04c18f51b0046f6 491570 Screen Shot 2018-06-01 at 14.48.05.png
533
100644 blob 686c16e4f019b734655a2576ce8b98749a9ffdb9 764420 Screen Shot 2018-06-07 at 20.04.59.png
534
100644 blob 257cc5642cb1a054f08cc83f2d943e56fd3ebe99 4 boom.txt
535
100644 blob 86dc360dd25f13fa50ffdc8259e9653921f4f2b7 11 boomcaboom.txt
536
100644 blob a68b14060589b16d7ac75f67b905c918c03c06eb 24 file.js
537
100644 blob f7bcfb05af46850d780f88c069edcd57481d822d 201 file.md
538
100644 blob ab8b86114a051f6490f1ec5e3141b9a632fb46b5 8 hello.js
539
100644 blob 257cc5642cb1a054f08cc83f2d943e56fd3ebe99 4 what.js
540
100644 blob be859e3f412fa86513cd8bebe8189d1ea1a3e46d 24 what.txt
541
100644 blob 56ec42c9dc6fcf4534788f0fe34b36e09f37d085 261186 what.txt2`;
542
543
const output = parseLsTree(input);
544
545
assert.deepStrictEqual(output, [
546
{ mode: '040000', type: 'tree', object: '0274a81f8ee9ca3669295dc40f510bd2021d0043', size: '-', file: '.vscode' },
547
{ mode: '100644', type: 'blob', object: '1d487c1817262e4f20efbfa1d04c18f51b0046f6', size: '491570', file: 'Screen Shot 2018-06-01 at 14.48.05.png' },
548
{ mode: '100644', type: 'blob', object: '686c16e4f019b734655a2576ce8b98749a9ffdb9', size: '764420', file: 'Screen Shot 2018-06-07 at 20.04.59.png' },
549
{ mode: '100644', type: 'blob', object: '257cc5642cb1a054f08cc83f2d943e56fd3ebe99', size: '4', file: 'boom.txt' },
550
{ mode: '100644', type: 'blob', object: '86dc360dd25f13fa50ffdc8259e9653921f4f2b7', size: '11', file: 'boomcaboom.txt' },
551
{ mode: '100644', type: 'blob', object: 'a68b14060589b16d7ac75f67b905c918c03c06eb', size: '24', file: 'file.js' },
552
{ mode: '100644', type: 'blob', object: 'f7bcfb05af46850d780f88c069edcd57481d822d', size: '201', file: 'file.md' },
553
{ mode: '100644', type: 'blob', object: 'ab8b86114a051f6490f1ec5e3141b9a632fb46b5', size: '8', file: 'hello.js' },
554
{ mode: '100644', type: 'blob', object: '257cc5642cb1a054f08cc83f2d943e56fd3ebe99', size: '4', file: 'what.js' },
555
{ mode: '100644', type: 'blob', object: 'be859e3f412fa86513cd8bebe8189d1ea1a3e46d', size: '24', file: 'what.txt' },
556
{ mode: '100644', type: 'blob', object: '56ec42c9dc6fcf4534788f0fe34b36e09f37d085', size: '261186', file: 'what.txt2' }
557
]);
558
});
559
});
560
561
suite('parseLsFiles', function () {
562
test('sample', function () {
563
const input = `100644 7a73a41bfdf76d6f793007240d80983a52f15f97 0 .vscode/settings.json
564
100644 1d487c1817262e4f20efbfa1d04c18f51b0046f6 0 Screen Shot 2018-06-01 at 14.48.05.png
565
100644 686c16e4f019b734655a2576ce8b98749a9ffdb9 0 Screen Shot 2018-06-07 at 20.04.59.png
566
100644 257cc5642cb1a054f08cc83f2d943e56fd3ebe99 0 boom.txt
567
100644 86dc360dd25f13fa50ffdc8259e9653921f4f2b7 0 boomcaboom.txt
568
100644 a68b14060589b16d7ac75f67b905c918c03c06eb 0 file.js
569
100644 f7bcfb05af46850d780f88c069edcd57481d822d 0 file.md
570
100644 ab8b86114a051f6490f1ec5e3141b9a632fb46b5 0 hello.js
571
100644 257cc5642cb1a054f08cc83f2d943e56fd3ebe99 0 what.js
572
100644 be859e3f412fa86513cd8bebe8189d1ea1a3e46d 0 what.txt
573
100644 56ec42c9dc6fcf4534788f0fe34b36e09f37d085 0 what.txt2`;
574
575
const output = parseLsFiles(input);
576
577
assert.deepStrictEqual(output, [
578
{ mode: '100644', object: '7a73a41bfdf76d6f793007240d80983a52f15f97', stage: '0', file: '.vscode/settings.json' },
579
{ mode: '100644', object: '1d487c1817262e4f20efbfa1d04c18f51b0046f6', stage: '0', file: 'Screen Shot 2018-06-01 at 14.48.05.png' },
580
{ mode: '100644', object: '686c16e4f019b734655a2576ce8b98749a9ffdb9', stage: '0', file: 'Screen Shot 2018-06-07 at 20.04.59.png' },
581
{ mode: '100644', object: '257cc5642cb1a054f08cc83f2d943e56fd3ebe99', stage: '0', file: 'boom.txt' },
582
{ mode: '100644', object: '86dc360dd25f13fa50ffdc8259e9653921f4f2b7', stage: '0', file: 'boomcaboom.txt' },
583
{ mode: '100644', object: 'a68b14060589b16d7ac75f67b905c918c03c06eb', stage: '0', file: 'file.js' },
584
{ mode: '100644', object: 'f7bcfb05af46850d780f88c069edcd57481d822d', stage: '0', file: 'file.md' },
585
{ mode: '100644', object: 'ab8b86114a051f6490f1ec5e3141b9a632fb46b5', stage: '0', file: 'hello.js' },
586
{ mode: '100644', object: '257cc5642cb1a054f08cc83f2d943e56fd3ebe99', stage: '0', file: 'what.js' },
587
{ mode: '100644', object: 'be859e3f412fa86513cd8bebe8189d1ea1a3e46d', stage: '0', file: 'what.txt' },
588
{ mode: '100644', object: '56ec42c9dc6fcf4534788f0fe34b36e09f37d085', stage: '0', file: 'what.txt2' },
589
]);
590
});
591
});
592
593
suite('splitInChunks', () => {
594
test('unit tests', function () {
595
assert.deepStrictEqual(
596
[...splitInChunks(['hello', 'there', 'cool', 'stuff'], 6)],
597
[['hello'], ['there'], ['cool'], ['stuff']]
598
);
599
600
assert.deepStrictEqual(
601
[...splitInChunks(['hello', 'there', 'cool', 'stuff'], 10)],
602
[['hello', 'there'], ['cool', 'stuff']]
603
);
604
605
assert.deepStrictEqual(
606
[...splitInChunks(['hello', 'there', 'cool', 'stuff'], 12)],
607
[['hello', 'there'], ['cool', 'stuff']]
608
);
609
610
assert.deepStrictEqual(
611
[...splitInChunks(['hello', 'there', 'cool', 'stuff'], 14)],
612
[['hello', 'there', 'cool'], ['stuff']]
613
);
614
615
assert.deepStrictEqual(
616
[...splitInChunks(['hello', 'there', 'cool', 'stuff'], 2000)],
617
[['hello', 'there', 'cool', 'stuff']]
618
);
619
620
assert.deepStrictEqual(
621
[...splitInChunks(['0', '01', '012', '0', '01', '012', '0', '01', '012'], 1)],
622
[['0'], ['01'], ['012'], ['0'], ['01'], ['012'], ['0'], ['01'], ['012']]
623
);
624
625
assert.deepStrictEqual(
626
[...splitInChunks(['0', '01', '012', '0', '01', '012', '0', '01', '012'], 2)],
627
[['0'], ['01'], ['012'], ['0'], ['01'], ['012'], ['0'], ['01'], ['012']]
628
);
629
630
assert.deepStrictEqual(
631
[...splitInChunks(['0', '01', '012', '0', '01', '012', '0', '01', '012'], 3)],
632
[['0', '01'], ['012'], ['0', '01'], ['012'], ['0', '01'], ['012']]
633
);
634
635
assert.deepStrictEqual(
636
[...splitInChunks(['0', '01', '012', '0', '01', '012', '0', '01', '012'], 4)],
637
[['0', '01'], ['012', '0'], ['01'], ['012', '0'], ['01'], ['012']]
638
);
639
640
assert.deepStrictEqual(
641
[...splitInChunks(['0', '01', '012', '0', '01', '012', '0', '01', '012'], 5)],
642
[['0', '01'], ['012', '0'], ['01', '012'], ['0', '01'], ['012']]
643
);
644
645
assert.deepStrictEqual(
646
[...splitInChunks(['0', '01', '012', '0', '01', '012', '0', '01', '012'], 6)],
647
[['0', '01', '012'], ['0', '01', '012'], ['0', '01', '012']]
648
);
649
650
assert.deepStrictEqual(
651
[...splitInChunks(['0', '01', '012', '0', '01', '012', '0', '01', '012'], 7)],
652
[['0', '01', '012', '0'], ['01', '012', '0'], ['01', '012']]
653
);
654
655
assert.deepStrictEqual(
656
[...splitInChunks(['0', '01', '012', '0', '01', '012', '0', '01', '012'], 8)],
657
[['0', '01', '012', '0'], ['01', '012', '0', '01'], ['012']]
658
);
659
660
assert.deepStrictEqual(
661
[...splitInChunks(['0', '01', '012', '0', '01', '012', '0', '01', '012'], 9)],
662
[['0', '01', '012', '0', '01'], ['012', '0', '01', '012']]
663
);
664
});
665
});
666
});
667
668