4
4
extractTargetedMarks ,
5
5
ExtraSnapshotField ,
6
6
marksToPlainObject ,
7
+ PartialTargetDescriptor ,
7
8
PlainSpyIDERecordedValues ,
8
9
ReadOnlyHatMap ,
9
10
serialize ,
@@ -16,22 +17,15 @@ import {
16
17
Token ,
17
18
} from "@cursorless/common" ;
18
19
import { pick } from "lodash" ;
19
- import { StoredTargetMap } from ".." ;
20
20
import { ide } from "../singletons/ide.singleton" ;
21
21
import { cleanUpTestCaseCommand } from "../testUtil/cleanUpTestCaseCommand" ;
22
22
import { extractTargetKeys } from "../testUtil/extractTargetKeys" ;
23
23
import { takeSnapshot } from "../testUtil/takeSnapshot" ;
24
- import { TargetDescriptor } from "../typings/TargetDescriptor" ;
25
-
26
- export type TestCaseContext = {
27
- storedTargets : StoredTargetMap ;
28
- targets : TargetDescriptor [ ] ;
29
- hatTokenMap : ReadOnlyHatMap ;
30
- } ;
24
+ import { StoredTargetMap } from ".." ;
31
25
32
26
export class TestCase {
33
27
private languageId : string ;
34
- private fullTargets : TargetDescriptor [ ] ;
28
+ private partialTargetDescriptors : PartialTargetDescriptor [ ] ;
35
29
private initialState : TestCaseSnapshot | null = null ;
36
30
private finalState ?: TestCaseSnapshot ;
37
31
thrownError ?: ThrownError ;
@@ -44,7 +38,8 @@ export class TestCase {
44
38
45
39
constructor (
46
40
command : CommandLatest ,
47
- private context : TestCaseContext ,
41
+ private hatTokenMap : ReadOnlyHatMap ,
42
+ private storedTargets : StoredTargetMap ,
48
43
private spyIde : SpyIDE ,
49
44
private isHatTokenMapTest : boolean = false ,
50
45
private isDecorationsTest : boolean = false ,
@@ -55,34 +50,33 @@ export class TestCase {
55
50
const activeEditor = ide ( ) . activeTextEditor ! ;
56
51
this . command = cleanUpTestCaseCommand ( command ) ;
57
52
58
- const { targets } = context ;
59
-
60
- this . targetKeys = targets . map ( extractTargetKeys ) . flat ( ) ;
53
+ this . targetKeys = command . targets . map ( extractTargetKeys ) . flat ( ) ;
61
54
62
55
this . languageId = activeEditor . document . languageId ;
63
- this . fullTargets = targets ;
56
+ this . partialTargetDescriptors = command . targets ;
64
57
this . _awaitingFinalMarkInfo = isHatTokenMapTest ;
65
58
}
66
59
67
60
private getMarks ( ) {
68
61
let marks : Record < string , Token > ;
69
62
70
- const { hatTokenMap } = this . context ;
71
-
72
63
if ( this . isHatTokenMapTest ) {
73
64
// If we're doing a navigation map test, then we grab the entire
74
65
// navigation map because we'll filter it later based on the marks
75
66
// referenced in the expected follow up command
76
- marks = Object . fromEntries ( hatTokenMap . getEntries ( ) ) ;
67
+ marks = Object . fromEntries ( this . hatTokenMap . getEntries ( ) ) ;
77
68
} else {
78
- marks = extractTargetedMarks ( this . targetKeys , hatTokenMap ) ;
69
+ marks = extractTargetedMarks ( this . targetKeys , this . hatTokenMap ) ;
79
70
}
80
71
81
72
return marksToPlainObject ( marks ) ;
82
73
}
83
74
84
- private includesThatMark ( target : TargetDescriptor , type : string ) : boolean {
85
- if ( target . type === "primitive" && target . mark . type === type ) {
75
+ private includesThatMark (
76
+ target : PartialTargetDescriptor ,
77
+ type : string ,
78
+ ) : boolean {
79
+ if ( target . type === "primitive" && target . mark ?. type === type ) {
86
80
return true ;
87
81
} else if ( target . type === "list" ) {
88
82
return target . elements . some ( ( target ) =>
@@ -114,13 +108,13 @@ export class TestCase {
114
108
thatMark :
115
109
( ! isInitialSnapshot && ! this . captureFinalThatMark ) ||
116
110
( isInitialSnapshot &&
117
- ! this . fullTargets . some ( ( target ) =>
111
+ ! this . partialTargetDescriptors . some ( ( target ) =>
118
112
this . includesThatMark ( target , "that" ) ,
119
113
) ) ,
120
114
sourceMark :
121
115
( ! isInitialSnapshot && ! this . captureFinalThatMark ) ||
122
116
( isInitialSnapshot &&
123
- ! this . fullTargets . some ( ( target ) =>
117
+ ! this . partialTargetDescriptors . some ( ( target ) =>
124
118
this . includesThatMark ( target , "source" ) ,
125
119
) ) ,
126
120
visibleRanges : ! visibleRangeActions . includes ( this . command . action . name ) ,
@@ -154,7 +148,7 @@ export class TestCase {
154
148
async recordInitialState ( ) {
155
149
const excludeFields = this . getExcludedFields ( true ) ;
156
150
this . initialState = await takeSnapshot (
157
- this . context . storedTargets ,
151
+ this . storedTargets ,
158
152
excludeFields ,
159
153
this . extraSnapshotFields ,
160
154
ide ( ) . activeTextEditor ! ,
@@ -168,7 +162,7 @@ export class TestCase {
168
162
const excludeFields = this . getExcludedFields ( false ) ;
169
163
this . returnValue = returnValue ;
170
164
this . finalState = await takeSnapshot (
171
- this . context . storedTargets ,
165
+ this . storedTargets ,
172
166
excludeFields ,
173
167
this . extraSnapshotFields ,
174
168
ide ( ) . activeTextEditor ! ,
@@ -185,8 +179,10 @@ export class TestCase {
185
179
raw == null ? undefined : spyIDERecordedValuesToPlainObject ( raw ) ;
186
180
}
187
181
188
- filterMarks ( command : CommandLatest , context : TestCaseContext ) {
189
- const marksToCheck = context . targets . map ( extractTargetKeys ) . flat ( ) ;
182
+ filterMarks ( ) {
183
+ const marksToCheck = this . partialTargetDescriptors
184
+ . map ( extractTargetKeys )
185
+ . flat ( ) ;
190
186
const keys = this . targetKeys . concat ( marksToCheck ) ;
191
187
192
188
this . initialState ! . marks = pick (
0 commit comments