@@ -353,101 +353,100 @@ let tests = {
353
353
}
354
354
} ,
355
355
356
- "concurrent edits are applied in order of calls, with exhaustive fault injection" : async ( {
357
- addCleanup,
358
- } ) => {
359
- let coinFlips ;
360
- let rng = new ExhaustiveRNG ( ) ;
361
- function maybeInjectFaultWithExhaustiveRNG ( ) {
362
- let shouldCrash = rng . nextCoinFlip ( ) ;
363
- coinFlips . push ( shouldCrash ) ;
364
- if ( shouldCrash ) {
365
- throw new qljs . ProcessCrashed ( "(injected fault)" ) ;
356
+ "concurrent edits are applied in order of calls, with exhaustive fault injection" :
357
+ async ( { addCleanup } ) => {
358
+ let coinFlips ;
359
+ let rng = new ExhaustiveRNG ( ) ;
360
+ function maybeInjectFaultWithExhaustiveRNG ( ) {
361
+ let shouldCrash = rng . nextCoinFlip ( ) ;
362
+ coinFlips . push ( shouldCrash ) ;
363
+ if ( shouldCrash ) {
364
+ throw new qljs . ProcessCrashed ( "(injected fault)" ) ;
365
+ }
366
366
}
367
- }
368
367
369
- let oldMaybeInjectFault = qljs . maybeInjectFault ;
370
- addCleanup ( ( ) => {
371
- qljs . maybeInjectFault = oldMaybeInjectFault ;
372
- } ) ;
368
+ let oldMaybeInjectFault = qljs . maybeInjectFault ;
369
+ addCleanup ( ( ) => {
370
+ qljs . maybeInjectFault = oldMaybeInjectFault ;
371
+ } ) ;
373
372
374
- while ( ! rng . isDone ( ) ) {
375
- coinFlips = [ ] ;
376
- let diagnosticCollection = new FakeDiagnosticCollection ( ) ;
377
- let linters = new extension . DocumentLinterCollection (
378
- diagnosticCollection
379
- ) ;
373
+ while ( ! rng . isDone ( ) ) {
374
+ coinFlips = [ ] ;
375
+ let diagnosticCollection = new FakeDiagnosticCollection ( ) ;
376
+ let linters = new extension . DocumentLinterCollection (
377
+ diagnosticCollection
378
+ ) ;
380
379
381
- try {
382
- let document = new MockDocument ( "hello.js" , "const x;" ) ;
383
- let linter = linters . getLinter ( document ) ;
384
- let shouldOpenEditorBeforeChanges = rng . nextCoinFlip ( ) ;
385
- if ( shouldOpenEditorBeforeChanges ) {
386
- await linter . editorChangedVisibilityAsync ( ) ;
387
- }
380
+ try {
381
+ let document = new MockDocument ( "hello.js" , "const x;" ) ;
382
+ let linter = linters . getLinter ( document ) ;
383
+ let shouldOpenEditorBeforeChanges = rng . nextCoinFlip ( ) ;
384
+ if ( shouldOpenEditorBeforeChanges ) {
385
+ await linter . editorChangedVisibilityAsync ( ) ;
386
+ }
388
387
389
- qljs . maybeInjectFault = maybeInjectFaultWithExhaustiveRNG ;
390
- let promises = [ ] ;
391
- for ( let charactersToType of [ "const " , "x;" ] ) {
392
- let changes = [
393
- {
394
- range : new vscode . Range (
395
- new vscode . Position ( 0 , document . _text . length ) ,
396
- new vscode . Position ( 0 , document . _text . length )
397
- ) ,
398
- rangeOffset : 0 ,
399
- rangeLength : 0 ,
400
- text : charactersToType ,
401
- } ,
402
- ] ;
403
- document . _text += charactersToType ;
404
- promises . push ( linter . textChangedAsync ( changes ) ) ;
405
- }
388
+ qljs . maybeInjectFault = maybeInjectFaultWithExhaustiveRNG ;
389
+ let promises = [ ] ;
390
+ for ( let charactersToType of [ "const " , "x;" ] ) {
391
+ let changes = [
392
+ {
393
+ range : new vscode . Range (
394
+ new vscode . Position ( 0 , document . _text . length ) ,
395
+ new vscode . Position ( 0 , document . _text . length )
396
+ ) ,
397
+ rangeOffset : 0 ,
398
+ rangeLength : 0 ,
399
+ text : charactersToType ,
400
+ } ,
401
+ ] ;
402
+ document . _text += charactersToType ;
403
+ promises . push ( linter . textChangedAsync ( changes ) ) ;
404
+ }
406
405
407
- let textChangedResults = await Promise . allSettled ( promises ) ;
408
- let firstChangeFailed = textChangedResults [ 0 ] . status !== "fulfilled" ;
409
- let lastChangeFailed = textChangedResults [ 1 ] . status !== "fulfilled" ;
406
+ let textChangedResults = await Promise . allSettled ( promises ) ;
407
+ let firstChangeFailed = textChangedResults [ 0 ] . status !== "fulfilled" ;
408
+ let lastChangeFailed = textChangedResults [ 1 ] . status !== "fulfilled" ;
410
409
411
- let diags = normalizeDiagnostics (
412
- diagnosticCollection . get ( document . uri )
413
- ) ;
414
- if ( firstChangeFailed && lastChangeFailed ) {
415
- // No changes were applied. The linted document was "const x;".
416
- assert . deepStrictEqual (
417
- diags . map ( ( diag ) => diag . message ) ,
418
- [ ]
419
- ) ;
420
- } else if ( ! firstChangeFailed && lastChangeFailed ) {
421
- // Partial changes were applied. The linted document was either
422
- // "const x;const " (if the first change finished before the second
423
- // change started) or "const x; const x;" (if the second change failed
424
- // before the first change started).
425
- let messages = diags . map ( ( diag ) => diag . message ) ;
426
- assert . strictEqual ( messages . length , 1 , messages ) ;
427
- assert . ok (
428
- messages [ 0 ] === "let with no bindings" ||
429
- messages [ 0 ] === "const with no bindings" ||
430
- messages [ 0 ] === "var with no bindings" ||
431
- messages [ 0 ] === "redeclaration of variable: x" ,
432
- messages
433
- ) ;
434
- } else {
435
- // Because the last call to textChangedAsync succeeded, all changes
436
- // were applied. The linted document was "const x;const x;".
437
- assert . deepStrictEqual (
438
- diags . map ( ( diag ) => diag . message ) ,
439
- [ "redeclaration of variable: x" ]
410
+ let diags = normalizeDiagnostics (
411
+ diagnosticCollection . get ( document . uri )
440
412
) ;
413
+ if ( firstChangeFailed && lastChangeFailed ) {
414
+ // No changes were applied. The linted document was "const x;".
415
+ assert . deepStrictEqual (
416
+ diags . map ( ( diag ) => diag . message ) ,
417
+ [ ]
418
+ ) ;
419
+ } else if ( ! firstChangeFailed && lastChangeFailed ) {
420
+ // Partial changes were applied. The linted document was either
421
+ // "const x;const " (if the first change finished before the second
422
+ // change started) or "const x; const x;" (if the second change failed
423
+ // before the first change started).
424
+ let messages = diags . map ( ( diag ) => diag . message ) ;
425
+ assert . strictEqual ( messages . length , 1 , messages ) ;
426
+ assert . ok (
427
+ messages [ 0 ] === "let with no bindings" ||
428
+ messages [ 0 ] === "const with no bindings" ||
429
+ messages [ 0 ] === "var with no bindings" ||
430
+ messages [ 0 ] === "redeclaration of variable: x" ,
431
+ messages
432
+ ) ;
433
+ } else {
434
+ // Because the last call to textChangedAsync succeeded, all changes
435
+ // were applied. The linted document was "const x;const x;".
436
+ assert . deepStrictEqual (
437
+ diags . map ( ( diag ) => diag . message ) ,
438
+ [ "redeclaration of variable: x" ]
439
+ ) ;
440
+ }
441
+ } finally {
442
+ await linters . disposeAsync ( ) ;
441
443
}
442
- } finally {
443
- await linters . disposeAsync ( ) ;
444
- }
445
444
446
- console . log ( `coinFlips: ${ coinFlips } ` ) ;
447
- rng . lap ( ) ;
448
- qljs . maybeInjectFault = oldMaybeInjectFault ;
449
- }
450
- } ,
445
+ console . log ( `coinFlips: ${ coinFlips } ` ) ;
446
+ rng . lap ( ) ;
447
+ qljs . maybeInjectFault = oldMaybeInjectFault ;
448
+ }
449
+ } ,
451
450
452
451
"ExhaustiveRNG: exhaust with no calls" : ( ) => {
453
452
let rng = new ExhaustiveRNG ( ) ;
@@ -480,39 +479,41 @@ let tests = {
480
479
) ;
481
480
} ,
482
481
483
- "ExhaustiveRNG: coin flip and maybe another coin flip (if true) per lap" : ( ) => {
484
- let rng = new ExhaustiveRNG ( ) ;
482
+ "ExhaustiveRNG: coin flip and maybe another coin flip (if true) per lap" :
483
+ ( ) => {
484
+ let rng = new ExhaustiveRNG ( ) ;
485
485
486
- assert . strictEqual ( rng . nextCoinFlip ( ) , false ) ;
487
- rng . lap ( ) ;
486
+ assert . strictEqual ( rng . nextCoinFlip ( ) , false ) ;
487
+ rng . lap ( ) ;
488
488
489
- assert . strictEqual ( rng . nextCoinFlip ( ) , true ) ;
490
- assert . strictEqual ( rng . nextCoinFlip ( ) , false ) ;
491
- rng . lap ( ) ;
489
+ assert . strictEqual ( rng . nextCoinFlip ( ) , true ) ;
490
+ assert . strictEqual ( rng . nextCoinFlip ( ) , false ) ;
491
+ rng . lap ( ) ;
492
492
493
- assert . strictEqual ( rng . nextCoinFlip ( ) , true ) ;
494
- assert . strictEqual ( rng . nextCoinFlip ( ) , true ) ;
495
- rng . lap ( ) ;
493
+ assert . strictEqual ( rng . nextCoinFlip ( ) , true ) ;
494
+ assert . strictEqual ( rng . nextCoinFlip ( ) , true ) ;
495
+ rng . lap ( ) ;
496
496
497
- assert . ok ( rng . isDone ( ) ) ;
498
- } ,
497
+ assert . ok ( rng . isDone ( ) ) ;
498
+ } ,
499
499
500
- "ExhaustiveRNG: coin flip and maybe another coin flip (if false) per lap" : ( ) => {
501
- let rng = new ExhaustiveRNG ( ) ;
500
+ "ExhaustiveRNG: coin flip and maybe another coin flip (if false) per lap" :
501
+ ( ) => {
502
+ let rng = new ExhaustiveRNG ( ) ;
502
503
503
- assert . strictEqual ( rng . nextCoinFlip ( ) , false ) ;
504
- assert . strictEqual ( rng . nextCoinFlip ( ) , false ) ;
505
- rng . lap ( ) ;
504
+ assert . strictEqual ( rng . nextCoinFlip ( ) , false ) ;
505
+ assert . strictEqual ( rng . nextCoinFlip ( ) , false ) ;
506
+ rng . lap ( ) ;
506
507
507
- assert . strictEqual ( rng . nextCoinFlip ( ) , false ) ;
508
- assert . strictEqual ( rng . nextCoinFlip ( ) , true ) ;
509
- rng . lap ( ) ;
508
+ assert . strictEqual ( rng . nextCoinFlip ( ) , false ) ;
509
+ assert . strictEqual ( rng . nextCoinFlip ( ) , true ) ;
510
+ rng . lap ( ) ;
510
511
511
- assert . strictEqual ( rng . nextCoinFlip ( ) , true ) ;
512
- rng . lap ( ) ;
512
+ assert . strictEqual ( rng . nextCoinFlip ( ) , true ) ;
513
+ rng . lap ( ) ;
513
514
514
- assert . ok ( rng . isDone ( ) ) ;
515
- } ,
515
+ assert . ok ( rng . isDone ( ) ) ;
516
+ } ,
516
517
517
518
"ExhaustiveRNG: exhaust with three nextCoinFlip calls per lap" : ( ) => {
518
519
let expectedOutcomesPerLap = [
0 commit comments