6
6
import * as dom from 'vs/base/browser/dom' ;
7
7
import { HoverWidget } from 'vs/base/browser/ui/hover/hoverWidget' ;
8
8
import { mapFindFirst } from 'vs/base/common/arraysFind' ;
9
+ import { assertNever } from 'vs/base/common/assert' ;
9
10
import { CancellationTokenSource } from 'vs/base/common/cancellation' ;
10
11
import { IMarkdownString , MarkdownString } from 'vs/base/common/htmlContent' ;
11
12
import { KeyChord , KeyCode , KeyMod } from 'vs/base/common/keyCodes' ;
@@ -31,7 +32,7 @@ import { ILogService } from 'vs/platform/log/common/log';
31
32
import { testingCoverageMissingBranch } from 'vs/workbench/contrib/testing/browser/icons' ;
32
33
import { FileCoverage } from 'vs/workbench/contrib/testing/common/testCoverage' ;
33
34
import { ITestCoverageService } from 'vs/workbench/contrib/testing/common/testCoverageService' ;
34
- import { CoverageDetails , DetailType , IStatementCoverage } from 'vs/workbench/contrib/testing/common/testTypes' ;
35
+ import { CoverageDetails , DetailType , IDeclarationCoverage , IStatementCoverage } from 'vs/workbench/contrib/testing/common/testTypes' ;
35
36
import { TestingContextKeys } from 'vs/workbench/contrib/testing/common/testingContextKeys' ;
36
37
37
38
const MAX_HOVERED_LINES = 30 ;
@@ -452,32 +453,42 @@ export class CoverageDetailsModel {
452
453
/** Gets the markdown description for the given detail */
453
454
public describe ( detail : CoverageDetailsWithBranch , model : ITextModel ) : IMarkdownString | undefined {
454
455
if ( detail . type === DetailType . Declaration ) {
455
- return new MarkdownString ( ) . appendMarkdown ( localize ( 'coverage.declExecutedCount' , '`{0}` was executed {1} time(s).' , detail . name , detail . count ) ) ;
456
+ return namedDetailLabel ( detail . name , detail ) ;
456
457
} else if ( detail . type === DetailType . Statement ) {
457
458
const text = wrapName ( model . getValueInRange ( tidyLocation ( detail . location ) ) . trim ( ) || `<empty statement>` ) ;
458
- const str = new MarkdownString ( ) ;
459
459
if ( detail . branches ?. length ) {
460
460
const covered = detail . branches . filter ( b => ! ! b . count ) . length ;
461
- str . appendMarkdown ( localize ( 'coverage.branches' , '{0} of {1} of branches in {2} were covered.' , covered , detail . branches . length , text ) ) ;
461
+ return new MarkdownString ( ) . appendMarkdown ( localize ( 'coverage.branches' , '{0} of {1} of branches in {2} were covered.' , covered , detail . branches . length , text ) ) ;
462
462
} else {
463
- str . appendMarkdown ( localize ( 'coverage.codeExecutedCount' , '{0} was executed {1} time(s).' , text , detail . count ) ) ;
463
+ return namedDetailLabel ( text , detail ) ;
464
464
}
465
- return str ;
466
465
} else if ( detail . type === DetailType . Branch ) {
467
466
const text = wrapName ( model . getValueInRange ( tidyLocation ( detail . detail . location ) ) . trim ( ) || `<empty statement>` ) ;
468
467
const { count, label } = detail . detail . branches ! [ detail . branch ] ;
469
468
const label2 = label ? wrapInBackticks ( label ) : `#${ detail . branch + 1 } ` ;
470
- if ( count === 0 ) {
469
+ if ( ! count ) {
471
470
return new MarkdownString ( ) . appendMarkdown ( localize ( 'coverage.branchNotCovered' , 'Branch {0} in {1} was not covered.' , label2 , text ) ) ;
471
+ } else if ( count === true ) {
472
+ return new MarkdownString ( ) . appendMarkdown ( localize ( 'coverage.branchCoveredYes' , 'Branch {0} in {1} was executed.' , label2 , text ) ) ;
472
473
} else {
473
474
return new MarkdownString ( ) . appendMarkdown ( localize ( 'coverage.branchCovered' , 'Branch {0} in {1} was executed {2} time(s).' , label2 , text , count ) ) ;
474
475
}
475
476
}
476
477
477
- return undefined ;
478
+ assertNever ( detail ) ;
478
479
}
479
480
}
480
481
482
+ function namedDetailLabel ( name : string , detail : IStatementCoverage | IDeclarationCoverage ) {
483
+ return new MarkdownString ( ) . appendMarkdown (
484
+ ! detail . count // 0 or false
485
+ ? localize ( 'coverage.declExecutedNo' , '`{0}` was not executed.' , name )
486
+ : typeof detail . count === 'number'
487
+ ? localize ( 'coverage.declExecutedCount' , '`{0}` was executed {1} time(s).' , name , detail . count )
488
+ : localize ( 'coverage.declExecutedYes' , '`{0}` was executed.' , name )
489
+ ) ;
490
+ }
491
+
481
492
// 'tidies' the range by normalizing it into a range and removing leading
482
493
// and trailing whitespace.
483
494
function tidyLocation ( location : Range | Position ) : Range {
0 commit comments