ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / src / vs / workbench / services / textfile / test / common / textFileService.io.test.ts 644 строк · изменён 14 нояб., 04:52
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
import assert from 'assert' ;
import { ITextFileService, snapshotToString, TextFileOperationError, TextFileOperationResult, stringToSnapshot } from '../../common/textfiles.js' ;
import { URI } from '../../../../../base/common/uri.js' ;
import { join, basename } from '../../../../../base/common/path.js' ;
import { UTF16le, UTF8_with_bom, UTF16be, UTF8 , UTF16le_BOM, UTF16be_BOM, UTF8_BOM } from '../../common/encoding.js' ;
import { bufferToStream, VSBuffer
createTextModel
ITextSnapshot DefaultEndOfLine
isWindows
createTextBufferFactoryFromStream
DisposableStore
service ITextFileService
testDir
fsPath
fsPath size
fsPath VSBuffer Buffer
fsPath encoding
fsPath encoding VSBuffer Buffer
fsPath UTF16be UTF16le UTF8_with_bom
params Params
service ITextFileService
testDir
exists stat readFile detectEncodingByBOM params
disposables
result params
service result service
testDir result testDir
params
disposables
resource testDir
service resource
res resource fsPath
assert res byteLength
resource testDir
service resource value
res resource fsPath
assert res
assert res byteLength length
resource testDir
service resource value
res resource fsPath
assert res
assert res byteLength length
resource testDir
service resource
assert resource fsPath
detectedEncoding resource fsPath
assert detectedEncoding UTF16le
res resource fsPath
assert res byteLength UTF16le_BOM length
resource testDir
service resource value
assert resource fsPath
detectedEncoding resource fsPath
assert detectedEncoding UTF16le
res resource fsPath
assert res byteLength length UTF16le_BOM length
resource testDir
service resource
assert resource fsPath
detectedEncoding resource fsPath
assert detectedEncoding UTF16be
res resource fsPath
assert res byteLength UTF16le_BOM length
resource testDir
service resource value
assert resource fsPath
detectedEncoding resource fsPath
assert detectedEncoding UTF16be
res resource fsPath
assert res byteLength length UTF16be_BOM length
resource testDir
service resource
assert resource fsPath
detectedEncoding resource fsPath
assert detectedEncoding UTF8_with_bom
res resource fsPath
assert res byteLength length
resource testDir
service resource value
assert resource fsPath
detectedEncoding resource fsPath
assert detectedEncoding UTF8_with_bom
res resource fsPath
assert res byteLength length length
text preserveBOM ITextSnapshot
textModel disposables text
snapshot textModel preserveBOM
snapshot
resource testDir
service resource value
assert resource fsPath
detectedEncoding resource fsPath
assert detectedEncoding UTF8_with_bom
res resource fsPath
assert res byteLength length
resource testDir
service resource value
assert resource fsPath
detectedEncoding resource fsPath
assert detectedEncoding UTF8_with_bom
res resource fsPath
assert res byteLength length length
testDir UTF16be
testDir UTF16be
testDir UTF16be
testDir UTF16be
resource encoding content ITextSnapshot expectedContent
service resource content encoding
detectedEncoding resource fsPath
assert detectedEncoding encoding
resolved service resource
assert resolved encoding encoding
textBuffer disposables resolved value isWindows DefaultEndOfLine DefaultEndOfLine textBuffer
assert textBuffer expectedContent
filePath testDir
contents filePath
eol contents
filePath eol
testDir
testDir
testDir
testDir
resource encoding expected
resolved service resource encoding
textBuffer disposables resolved value isWindows DefaultEndOfLine DefaultEndOfLine textBuffer
content textBuffer
assert content expected
service resource content encoding
resolved service resource encoding
textBuffer2 disposables resolved value DefaultEndOfLine textBuffer
assert textBuffer2 content
service resource content encoding
resolved service resource encoding
textBuffer3 disposables resolved value DefaultEndOfLine textBuffer
assert textBuffer3 content
resource testDir
content resource fsPath
service resource content
resolved service resource
assert resolved value content
resource testDir
content resource fsPath
service resource content
resolved service resource
assert resolved value content
resource testDir
resolved service resource
assert resolved encoding UTF16le
testDir UTF16le
resource testDir
resolved service resource
assert resolved encoding UTF16le
testDir UTF16le
resource testDir
detectedEncoding resource fsPath
assert detectedEncoding
content resource fsPath
service resource content encoding UTF8_with_bom
detectedEncoding resource fsPath
assert detectedEncoding UTF8_with_bom
service resource content encoding UTF8_with_bom
detectedEncoding resource fsPath
assert detectedEncoding UTF8_with_bom
service resource content encoding
detectedEncoding resource fsPath
assert detectedEncoding
service resource content encoding
detectedEncoding resource fsPath
assert detectedEncoding
resource testDir
detectedEncoding resource fsPath
assert detectedEncoding
model disposables resource fsPath
service resource model encoding UTF8_with_bom
detectedEncoding resource fsPath
assert detectedEncoding UTF8_with_bom
service resource model encoding UTF8_with_bom
detectedEncoding resource fsPath
assert detectedEncoding UTF8_with_bom
service resource model encoding
detectedEncoding resource fsPath
assert detectedEncoding
service resource model encoding
detectedEncoding resource fsPath
assert detectedEncoding
resource testDir
detectedEncoding resource fsPath
assert detectedEncoding UTF8_with_bom
service resource encoding detectedEncoding
detectedEncoding resource fsPath
assert detectedEncoding UTF8_with_bom
resource testDir
service resource encoding UTF8_with_bom
detectedEncoding resource fsPath
assert detectedEncoding UTF8_with_bom
resource testDir
service resource encoding UTF8_with_bom
detectedEncoding resource fsPath
assert detectedEncoding UTF8_with_bom
resource testDir
resource
resource testDir
resource
resource
result service resource
assert result name resource fsPath
assert result size resource fsPath size
content resource fsPath
textBuffer disposables result value DefaultEndOfLine textBuffer
assert
textBuffer
content
resource testDir
resource
resource testDir
resource
resource
result service resource
assert result name resource fsPath
assert result size resource fsPath size
assert result value resource fsPath
resource testDir
encoding
result service resource encoding
assert result encoding encoding
assert result value
resource testDir
encoding
result service resource encoding
assert result encoding encoding
assert result value
resource testDir
encoding
result service resource encoding
assert result encoding encoding
assert result value
resource testDir
encoding
result service resource encoding
assert result encoding encoding
assert result value
resource testDir
result service resource encoding
assert result encoding
resource testDir
result service resource
assert result value
resource testDir
result service resource encoding
assert result encoding
resource testDir
result service resource encoding
assert result encoding
assert result value
encoding needle
resource testDir
result service resource encoding
assert result encoding encoding
textBuffer disposables result value DefaultEndOfLine textBuffer
contents textBuffer
assert contents needle
assert contents needle
rawFile params resource fsPath
rawFileVSBuffer VSBuffer
rawFile
rawFileVSBuffer rawFile
rawFileVSBuffer VSBuffer rawFile
factory service resource rawFileVSBuffer encoding
textBuffer2 disposables factory DefaultEndOfLine textBuffer
contents textBuffer2
assert contents needle
assert contents needle
resource testDir
result service resource
assert result encoding
resource testDir
result service resource
assert result encoding
resource testDir
result service resource autoGuessEncoding
assert result encoding
resource testDir
result service resource autoGuessEncoding candidateGuessEncodings
assert result encoding
resource testDir
result service resource autoGuessEncoding candidateGuessEncodings
assert result encoding
resource testDir
error TextFileOperationError
service resource acceptTextOnly
err
error err
assert error
assert error textFileOperationResult TextFileOperationResult
result service testDir acceptTextOnly
assert result name
resource testDir
error TextFileOperationError
service resource acceptTextOnly
err
error err
assert error
assert error textFileOperationResult TextFileOperationResult
result service testDir acceptTextOnly
assert result name
}
from
'../../../../../base/common/buffer.js'
;
import
{
}
from
'../../../../../editor/test/common/testTextModel.js'
;
import
{
,
}
from
'../../../../../editor/common/model.js'
;
import
{
}
from
'../../../../../base/common/platform.js'
;
import
{
}
from
'../../../../../editor/common/model/textModel.js'
;
import
{
}
from
'../../../../../base/common/lifecycle.js'
;
export
interface
Params
{
setup
(
)
:
Promise
<
{
:
;
:
string
;
}
>
;
teardown
(
)
:
Promise
<
void
>
;
exists
(
:
string
)
:
Promise
<
boolean
>
;
stat
(
:
string
)
:
Promise
<
{
:
number
}
>
;
readFile
(
:
string
)
:
Promise
<
|
>
;
readFile
(
:
string
,
:
string
)
:
Promise
<
string
>
;
readFile
(
:
string
,
?
:
string
)
:
Promise
<
|
|
string
>
;
detectEncodingByBOM
(
:
string
)
:
Promise
<
typeof
|
typeof
|
typeof
|
null
>
;
}
export
default
function
createSuite
(
:
)
{
let
:
;
let
=
''
;
const
{
,
,
,
}
=
;
const
=
new
DisposableStore
(
)
;
setup
(
async
(
)
=>
{
const
=
await
.
setup
(
)
;
=
.
;
=
.
;
}
)
;
teardown
(
async
(
)
=>
{
await
.
teardown
(
)
;
.
clear
(
)
;
}
)
;
test
(
'create - no encoding - content empty'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'small_new.txt'
)
)
;
await
.
create
(
[
{
}
]
)
;
const
=
await
readFile
(
.
)
;
.
strictEqual
(
.
,
0
)
;
}
)
;
test
(
'create - no encoding - content provided (string)'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'small_new.txt'
)
)
;
await
.
create
(
[
{
,
:
'Hello World'
}
]
)
;
const
=
await
readFile
(
.
)
;
.
strictEqual
(
.
toString
(
)
,
'Hello World'
)
;
.
strictEqual
(
.
,
'Hello World'
.
)
;
}
)
;
test
(
'create - no encoding - content provided (snapshot)'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'small_new.txt'
)
)
;
await
.
create
(
[
{
,
:
stringToSnapshot
(
'Hello World'
)
}
]
)
;
const
=
await
readFile
(
.
)
;
.
strictEqual
(
.
toString
(
)
,
'Hello World'
)
;
.
strictEqual
(
.
,
'Hello World'
.
)
;
}
)
;
test
(
'create - UTF 16 LE - no content'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'small_new.utf16le'
)
)
;
await
.
create
(
[
{
}
]
)
;
.
strictEqual
(
await
exists
(
.
)
,
true
)
;
const
=
await
detectEncodingByBOM
(
.
)
;
.
strictEqual
(
,
)
;
const
=
await
readFile
(
.
)
;
.
strictEqual
(
.
,
.
)
;
}
)
;
test
(
'create - UTF 16 LE - content provided'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'small_new.utf16le'
)
)
;
await
.
create
(
[
{
,
:
'Hello World'
}
]
)
;
.
strictEqual
(
await
exists
(
.
)
,
true
)
;
const
=
await
detectEncodingByBOM
(
.
)
;
.
strictEqual
(
,
)
;
const
=
await
readFile
(
.
)
;
.
strictEqual
(
.
,
'Hello World'
.
*
2
+
.
)
;
}
)
;
test
(
'create - UTF 16 BE - no content'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'small_new.utf16be'
)
)
;
await
.
create
(
[
{
}
]
)
;
.
strictEqual
(
await
exists
(
.
)
,
true
)
;
const
=
await
detectEncodingByBOM
(
.
)
;
.
strictEqual
(
,
)
;
const
=
await
readFile
(
.
)
;
.
strictEqual
(
.
,
.
)
;
}
)
;
test
(
'create - UTF 16 BE - content provided'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'small_new.utf16be'
)
)
;
await
.
create
(
[
{
,
:
'Hello World'
}
]
)
;
.
strictEqual
(
await
exists
(
.
)
,
true
)
;
const
=
await
detectEncodingByBOM
(
.
)
;
.
strictEqual
(
,
)
;
const
=
await
readFile
(
.
)
;
.
strictEqual
(
.
,
'Hello World'
.
*
2
+
.
)
;
}
)
;
test
(
'create - UTF 8 BOM - no content'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'small_new.utf8bom'
)
)
;
await
.
create
(
[
{
}
]
)
;
.
strictEqual
(
await
exists
(
.
)
,
true
)
;
const
=
await
detectEncodingByBOM
(
.
)
;
.
strictEqual
(
,
)
;
const
=
await
readFile
(
.
)
;
.
strictEqual
(
.
,
UTF8_BOM
.
)
;
}
)
;
test
(
'create - UTF 8 BOM - content provided'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'small_new.utf8bom'
)
)
;
await
.
create
(
[
{
,
:
'Hello World'
}
]
)
;
.
strictEqual
(
await
exists
(
.
)
,
true
)
;
const
=
await
detectEncodingByBOM
(
.
)
;
.
strictEqual
(
,
)
;
const
=
await
readFile
(
.
)
;
.
strictEqual
(
.
,
'Hello World'
.
+
UTF8_BOM
.
)
;
}
)
;
function
createTextModelSnapshot
(
:
string
,
?
:
boolean
)
:
{
const
=
.
add
(
createTextModel
(
)
)
;
const
=
.
createSnapshot
(
)
;
return
;
}
test
(
'create - UTF 8 BOM - empty content - snapshot'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'small_new.utf8bom'
)
)
;
await
.
create
(
[
{
,
:
createTextModelSnapshot
(
''
)
}
]
)
;
.
strictEqual
(
await
exists
(
.
)
,
true
)
;
const
=
await
detectEncodingByBOM
(
.
)
;
.
strictEqual
(
,
)
;
const
=
await
readFile
(
.
)
;
.
strictEqual
(
.
,
UTF8_BOM
.
)
;
}
)
;
test
(
'create - UTF 8 BOM - content provided - snapshot'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'small_new.utf8bom'
)
)
;
await
.
create
(
[
{
,
:
createTextModelSnapshot
(
'Hello World'
)
}
]
)
;
.
strictEqual
(
await
exists
(
.
)
,
true
)
;
const
=
await
detectEncodingByBOM
(
.
)
;
.
strictEqual
(
,
)
;
const
=
await
readFile
(
.
)
;
.
strictEqual
(
.
,
'Hello World'
.
+
UTF8_BOM
.
)
;
}
)
;
test
(
'write - use encoding (UTF 16 BE) - small content as string'
,
async
(
)
=>
{
await
testEncoding
(
URI
.
file
(
join
(
,
'small.txt'
)
)
,
,
'Hello\nWorld'
,
'Hello\nWorld'
)
;
}
)
;
test
(
'write - use encoding (UTF 16 BE) - small content as snapshot'
,
async
(
)
=>
{
await
testEncoding
(
URI
.
file
(
join
(
,
'small.txt'
)
)
,
,
createTextModelSnapshot
(
'Hello\nWorld'
)
,
'Hello\nWorld'
)
;
}
)
;
test
(
'write - use encoding (UTF 16 BE) - large content as string'
,
async
(
)
=>
{
await
testEncoding
(
URI
.
file
(
join
(
,
'lorem.txt'
)
)
,
,
'Hello\nWorld'
,
'Hello\nWorld'
)
;
}
)
;
test
(
'write - use encoding (UTF 16 BE) - large content as snapshot'
,
async
(
)
=>
{
await
testEncoding
(
URI
.
file
(
join
(
,
'lorem.txt'
)
)
,
,
createTextModelSnapshot
(
'Hello\nWorld'
)
,
'Hello\nWorld'
)
;
}
)
;
async
function
testEncoding
(
:
URI
,
:
string
,
:
string
|
,
:
string
)
{
await
.
write
(
,
,
{
}
)
;
const
=
await
detectEncodingByBOM
(
.
)
;
.
strictEqual
(
,
)
;
const
=
await
.
readStream
(
)
;
.
strictEqual
(
.
,
)
;
const
=
.
add
(
.
.
create
(
?
.
CRLF
:
.
LF
)
.
)
;
.
strictEqual
(
snapshotToString
(
.
createSnapshot
(
false
)
)
,
)
;
}
test
(
'write - use encoding (cp1252)'
,
async
(
)
=>
{
const
=
join
(
,
'some_cp1252.txt'
)
;
const
=
await
readFile
(
,
'utf8'
)
;
const
=
/ \r \n /
.
test
(
)
?
'\r\n'
:
'\n'
;
await
testEncodingKeepsData
(
URI
.
file
(
)
,
'cp1252'
,
[
'ObjectCount = LoadObjects("Öffentlicher Ordner");'
,
''
,
'Private = "Persönliche Information"'
,
''
]
.
join
(
)
)
;
}
)
;
test
(
'write - use encoding (shiftjis)'
,
async
(
)
=>
{
await
testEncodingKeepsData
(
URI
.
file
(
join
(
,
'some_shiftjis.txt'
)
)
,
'shiftjis'
,
'中文abc'
)
;
}
)
;
test
(
'write - use encoding (gbk)'
,
async
(
)
=>
{
await
testEncodingKeepsData
(
URI
.
file
(
join
(
,
'some_gbk.txt'
)
)
,
'gbk'
,
'中国abc'
)
;
}
)
;
test
(
'write - use encoding (cyrillic)'
,
async
(
)
=>
{
await
testEncodingKeepsData
(
URI
.
file
(
join
(
,
'some_cyrillic.txt'
)
)
,
'cp866'
,
'АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюя'
)
;
}
)
;
test
(
'write - use encoding (big5)'
,
async
(
)
=>
{
await
testEncodingKeepsData
(
URI
.
file
(
join
(
,
'some_big5.txt'
)
)
,
'cp950'
,
'中文abc'
)
;
}
)
;
async
function
testEncodingKeepsData
(
:
URI
,
:
string
,
:
string
)
{
let
=
await
.
readStream
(
,
{
}
)
;
const
=
.
add
(
.
.
create
(
?
.
CRLF
:
.
LF
)
.
)
;
const
=
snapshotToString
(
.
createSnapshot
(
false
)
)
;
.
strictEqual
(
,
)
;
await
.
write
(
,
,
{
}
)
;
=
await
.
readStream
(
,
{
}
)
;
const
=
.
add
(
.
.
create
(
.
CRLF
)
.
)
;
.
strictEqual
(
snapshotToString
(
.
createSnapshot
(
false
)
)
,
)
;
await
.
write
(
,
createTextModelSnapshot
(
)
,
{
}
)
;
=
await
.
readStream
(
,
{
}
)
;
const
=
.
add
(
.
.
create
(
.
CRLF
)
.
)
;
.
strictEqual
(
snapshotToString
(
.
createSnapshot
(
false
)
)
,
)
;
}
test
(
'write - no encoding - content as string'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'small.txt'
)
)
;
const
=
(
await
readFile
(
.
)
)
.
toString
(
)
;
await
.
write
(
,
)
;
const
=
await
.
readStream
(
)
;
.
strictEqual
(
.
.
getFirstLineText
(
999999
)
,
)
;
}
)
;
test
(
'write - no encoding - content as snapshot'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'small.txt'
)
)
;
const
=
(
await
readFile
(
.
)
)
.
toString
(
)
;
await
.
write
(
,
createTextModelSnapshot
(
)
)
;
const
=
await
.
readStream
(
)
;
.
strictEqual
(
.
.
getFirstLineText
(
999999
)
,
)
;
}
)
;
test
(
'write - encoding preserved (UTF 16 LE) - content as string'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'some_utf16le.css'
)
)
;
const
=
await
.
readStream
(
)
;
.
strictEqual
(
.
,
)
;
await
testEncoding
(
URI
.
file
(
join
(
,
'some_utf16le.css'
)
)
,
,
'Hello\nWorld'
,
'Hello\nWorld'
)
;
}
)
;
test
(
'write - encoding preserved (UTF 16 LE) - content as snapshot'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'some_utf16le.css'
)
)
;
const
=
await
.
readStream
(
)
;
.
strictEqual
(
.
,
)
;
await
testEncoding
(
URI
.
file
(
join
(
,
'some_utf16le.css'
)
)
,
,
createTextModelSnapshot
(
'Hello\nWorld'
)
,
'Hello\nWorld'
)
;
}
)
;
test
(
'write - UTF8 variations - content as string'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'index.html'
)
)
;
let
=
await
detectEncodingByBOM
(
.
)
;
.
strictEqual
(
,
null
)
;
const
=
(
await
readFile
(
.
)
)
.
toString
(
)
+
'updates'
;
await
.
write
(
,
,
{
:
}
)
;
=
await
detectEncodingByBOM
(
.
)
;
.
strictEqual
(
,
)
;
await
.
write
(
,
,
{
:
}
)
;
=
await
detectEncodingByBOM
(
.
)
;
.
strictEqual
(
,
)
;
await
.
write
(
,
,
{
:
UTF8
}
)
;
=
await
detectEncodingByBOM
(
.
)
;
.
strictEqual
(
,
null
)
;
await
.
write
(
,
,
{
:
UTF8
}
)
;
=
await
detectEncodingByBOM
(
.
)
;
.
strictEqual
(
,
null
)
;
}
)
;
test
(
'write - UTF8 variations - content as snapshot'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'index.html'
)
)
;
let
=
await
detectEncodingByBOM
(
.
)
;
.
strictEqual
(
,
null
)
;
const
=
.
add
(
createTextModel
(
(
await
readFile
(
.
)
)
.
toString
(
)
+
'updates'
)
)
;
await
.
write
(
,
.
createSnapshot
(
)
,
{
:
}
)
;
=
await
detectEncodingByBOM
(
.
)
;
.
strictEqual
(
,
)
;
await
.
write
(
,
.
createSnapshot
(
)
,
{
:
}
)
;
=
await
detectEncodingByBOM
(
.
)
;
.
strictEqual
(
,
)
;
await
.
write
(
,
.
createSnapshot
(
)
,
{
:
UTF8
}
)
;
=
await
detectEncodingByBOM
(
.
)
;
.
strictEqual
(
,
null
)
;
await
.
write
(
,
.
createSnapshot
(
)
,
{
:
UTF8
}
)
;
=
await
detectEncodingByBOM
(
.
)
;
.
strictEqual
(
,
null
)
;
}
)
;
test
(
'write - preserve UTF8 BOM - content as string'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'some_utf8_bom.txt'
)
)
;
let
=
await
detectEncodingByBOM
(
.
)
;
.
strictEqual
(
,
)
;
await
.
write
(
,
'Hello World'
,
{
:
}
)
;
=
await
detectEncodingByBOM
(
.
)
;
.
strictEqual
(
,
)
;
}
)
;
test
(
'write - ensure BOM in empty file - content as string'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'small.txt'
)
)
;
await
.
write
(
,
''
,
{
:
}
)
;
const
=
await
detectEncodingByBOM
(
.
)
;
.
strictEqual
(
,
)
;
}
)
;
test
(
'write - ensure BOM in empty file - content as snapshot'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'small.txt'
)
)
;
await
.
write
(
,
createTextModelSnapshot
(
''
)
,
{
:
}
)
;
const
=
await
detectEncodingByBOM
(
.
)
;
.
strictEqual
(
,
)
;
}
)
;
test
(
'readStream - small text'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'small.txt'
)
)
;
await
testReadStream
(
)
;
}
)
;
test
(
'readStream - large text'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'lorem.txt'
)
)
;
await
testReadStream
(
)
;
}
)
;
async
function
testReadStream
(
:
URI
)
:
Promise
<
void
>
{
const
=
await
.
readStream
(
)
;
.
strictEqual
(
.
,
basename
(
.
)
)
;
.
strictEqual
(
.
,
(
await
stat
(
.
)
)
.
)
;
const
=
(
await
readFile
(
.
)
)
.
toString
(
)
;
const
=
.
add
(
.
.
create
(
.
LF
)
.
)
;
.
strictEqual
(
snapshotToString
(
.
createSnapshot
(
false
)
)
,
snapshotToString
(
createTextModelSnapshot
(
,
false
)
)
)
;
}
test
(
'read - small text'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'small.txt'
)
)
;
await
testRead
(
)
;
}
)
;
test
(
'read - large text'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'lorem.txt'
)
)
;
await
testRead
(
)
;
}
)
;
async
function
testRead
(
:
URI
)
:
Promise
<
void
>
{
const
=
await
.
read
(
)
;
.
strictEqual
(
.
,
basename
(
.
)
)
;
.
strictEqual
(
.
,
(
await
stat
(
.
)
)
.
)
;
.
strictEqual
(
.
,
(
await
readFile
(
.
)
)
.
toString
(
)
)
;
}
test
(
'readStream - encoding picked up (CP1252)'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'some_small_cp1252.txt'
)
)
;
const
=
'windows1252'
;
const
=
await
.
readStream
(
,
{
}
)
;
.
strictEqual
(
.
,
)
;
.
strictEqual
(
.
.
getFirstLineText
(
999999
)
,
'Private = "Persönlicheß Information"'
)
;
}
)
;
test
(
'read - encoding picked up (CP1252)'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'some_small_cp1252.txt'
)
)
;
const
=
'windows1252'
;
const
=
await
.
read
(
,
{
}
)
;
.
strictEqual
(
.
,
)
;
.
strictEqual
(
.
,
'Private = "Persönlicheß Information"'
)
;
}
)
;
test
(
'read - encoding picked up (binary)'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'some_small_cp1252.txt'
)
)
;
const
=
'binary'
;
const
=
await
.
read
(
,
{
}
)
;
.
strictEqual
(
.
,
)
;
.
strictEqual
(
.
,
'Private = "Persönlicheß Information"'
)
;
}
)
;
test
(
'read - encoding picked up (base64)'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'some_small_cp1252.txt'
)
)
;
const
=
'base64'
;
const
=
await
.
read
(
,
{
}
)
;
.
strictEqual
(
.
,
)
;
.
strictEqual
(
.
,
btoa
(
'Private = "Persönlicheß Information"'
)
)
;
}
)
;
test
(
'readStream - user overrides BOM'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'some_utf16le.css'
)
)
;
const
=
await
.
readStream
(
,
{
:
'windows1252'
}
)
;
.
strictEqual
(
.
,
'windows1252'
)
;
}
)
;
test
(
'readStream - BOM removed'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'some_utf8_bom.txt'
)
)
;
const
=
await
.
readStream
(
)
;
.
strictEqual
(
.
.
getFirstLineText
(
999999
)
,
'This is some UTF 8 with BOM file.'
)
;
}
)
;
test
(
'readStream - invalid encoding'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'index.html'
)
)
;
const
=
await
.
readStream
(
,
{
:
'superduper'
}
)
;
.
strictEqual
(
.
,
'utf8'
)
;
}
)
;
test
(
'readStream - encoding override'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'some.utf16le'
)
)
;
const
=
await
.
readStream
(
,
{
:
'windows1252'
}
)
;
.
strictEqual
(
.
,
'utf16le'
)
;
.
strictEqual
(
.
.
getFirstLineText
(
999999
)
,
'This is some UTF 16 with BOM file.'
)
;
}
)
;
test
(
'readStream - large Big5'
,
async
(
)
=>
{
await
testLargeEncoding
(
'big5'
,
'中文abc'
)
;
}
)
;
test
(
'readStream - large CP1252'
,
async
(
)
=>
{
await
testLargeEncoding
(
'cp1252'
,
'öäüß'
)
;
}
)
;
test
(
'readStream - large Cyrillic'
,
async
(
)
=>
{
await
testLargeEncoding
(
'cp866'
,
'АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюя'
)
;
}
)
;
test
(
'readStream - large GBK'
,
async
(
)
=>
{
await
testLargeEncoding
(
'gbk'
,
'中国abc'
)
;
}
)
;
test
(
'readStream - large ShiftJIS'
,
async
(
)
=>
{
await
testLargeEncoding
(
'shiftjis'
,
'中文abc'
)
;
}
)
;
test
(
'readStream - large UTF8 BOM'
,
async
(
)
=>
{
await
testLargeEncoding
(
'utf8bom'
,
'öäüß'
)
;
}
)
;
test
(
'readStream - large UTF16 LE'
,
async
(
)
=>
{
await
testLargeEncoding
(
'utf16le'
,
'öäüß'
)
;
}
)
;
test
(
'readStream - large UTF16 BE'
,
async
(
)
=>
{
await
testLargeEncoding
(
'utf16be'
,
'öäüß'
)
;
}
)
;
async
function
testLargeEncoding
(
:
string
,
:
string
)
:
Promise
<
void
>
{
const
=
URI
.
file
(
join
(
,
` lorem_ ${ encoding} .txt `
)
)
;
const
=
await
.
readStream
(
,
{
}
)
;
.
strictEqual
(
.
,
)
;
const
=
.
add
(
.
.
create
(
.
LF
)
.
)
;
let
=
snapshotToString
(
.
createSnapshot
(
false
)
)
;
.
strictEqual
(
.
indexOf
(
)
,
0
)
;
.
ok
(
.
indexOf
(
,
10
)
>
0
)
;
const
=
await
.
readFile
(
.
)
;
let
:
;
if
(
instanceof
VSBuffer
)
{
=
;
}
else
{
=
.
wrap
(
)
;
}
const
=
await
createTextBufferFactoryFromStream
(
await
.
getDecodedStream
(
,
bufferToStream
(
)
,
{
}
)
)
;
const
=
.
add
(
.
create
(
.
LF
)
.
)
;
=
snapshotToString
(
.
createSnapshot
(
false
)
)
;
.
strictEqual
(
.
indexOf
(
)
,
0
)
;
.
ok
(
.
indexOf
(
,
10
)
>
0
)
;
}
test
(
'readStream - UTF16 LE (no BOM)'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'utf16_le_nobom.txt'
)
)
;
const
=
await
.
readStream
(
)
;
.
strictEqual
(
.
,
'utf16le'
)
;
}
)
;
test
(
'readStream - UTF16 BE (no BOM)'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'utf16_be_nobom.txt'
)
)
;
const
=
await
.
readStream
(
)
;
.
strictEqual
(
.
,
'utf16be'
)
;
}
)
;
test
(
'readStream - autoguessEncoding'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'some_cp1252.txt'
)
)
;
const
=
await
.
readStream
(
,
{
:
true
}
)
;
.
strictEqual
(
.
,
'windows1252'
)
;
}
)
;
test
(
'readStream - autoguessEncoding (candidateGuessEncodings)'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'some.shiftjis.1.txt'
)
)
;
const
=
await
.
readStream
(
,
{
:
true
,
:
[
'utf-8'
,
'shiftjis'
,
'euc-jp'
]
}
)
;
.
strictEqual
(
.
,
'shiftjis'
)
;
}
)
;
test
(
'readStream - autoguessEncoding (candidateGuessEncodings is Empty)'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'some_cp1252.txt'
)
)
;
const
=
await
.
readStream
(
,
{
:
true
,
:
[
]
}
)
;
.
strictEqual
(
.
,
'windows1252'
)
;
}
)
;
test
(
'readStream - FILE_IS_BINARY'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'binary.txt'
)
)
;
let
:
|
undefined
=
undefined
;
try
{
await
.
readStream
(
,
{
:
true
}
)
;
}
catch
(
)
{
=
;
}
.
ok
(
)
;
.
strictEqual
(
.
,
.
FILE_IS_BINARY
)
;
const
=
await
.
readStream
(
URI
.
file
(
join
(
,
'small.txt'
)
)
,
{
:
true
}
)
;
.
strictEqual
(
.
,
'small.txt'
)
;
}
)
;
test
(
'read - FILE_IS_BINARY'
,
async
(
)
=>
{
const
=
URI
.
file
(
join
(
,
'binary.txt'
)
)
;
let
:
|
undefined
=
undefined
;
try
{
await
.
read
(
,
{
:
true
}
)
;
}
catch
(
)
{
=
;
}
.
ok
(
)
;
.
strictEqual
(
.
,
.
FILE_IS_BINARY
)
;
const
=
await
.
read
(
URI
.
file
(
join
(
,
'small.txt'
)
)
,
{
:
true
}
)
;
.
strictEqual
(
.
,
'small.txt'
)
;
}
)
;
}