@@ -34,48 +34,39 @@ suite(`Performance: ${numLines} lines JSON`, async function () {
3434 asyncSafety ( ( ) => removeToken ( textBasedThreshold ) ) ,
3535 ) ;
3636
37- const scopeTypeTypes : Partial < Record < SimpleScopeTypeType , number > > = {
37+ const fixtures : [ SimpleScopeTypeType | ScopeType , number ] [ ] = [
3838 // Text based
39- character : textBasedThreshold ,
40- word : textBasedThreshold ,
41- token : textBasedThreshold ,
42- identifier : textBasedThreshold ,
43- line : textBasedThreshold ,
44- sentence : textBasedThreshold ,
45- paragraph : textBasedThreshold ,
46- document : textBasedThreshold ,
47- nonWhitespaceSequence : textBasedThreshold ,
39+ [ " character" , textBasedThreshold ] ,
40+ [ " word" , textBasedThreshold ] ,
41+ [ " token" , textBasedThreshold ] ,
42+ [ " identifier" , textBasedThreshold ] ,
43+ [ " line" , textBasedThreshold ] ,
44+ [ " sentence" , textBasedThreshold ] ,
45+ [ " paragraph" , textBasedThreshold ] ,
46+ [ " document" , textBasedThreshold ] ,
47+ [ " nonWhitespaceSequence" , textBasedThreshold ] ,
4848 // Parse tree based
49- string : parseTreeThreshold ,
50- map : parseTreeThreshold ,
51- collectionKey : parseTreeThreshold ,
52- value : parseTreeThreshold ,
49+ [ " string" , parseTreeThreshold ] ,
50+ [ " map" , parseTreeThreshold ] ,
51+ [ " collectionKey" , parseTreeThreshold ] ,
52+ [ " value" , parseTreeThreshold ] ,
5353 // Utilizes surrounding pair
54- boundedParagraph : surroundingPairThreshold ,
55- boundedNonWhitespaceSequence : surroundingPairThreshold ,
56- } ;
57-
58- for ( const [ scopeTypeType , threshold ] of Object . entries ( scopeTypeTypes ) ) {
54+ [ "boundedParagraph" , surroundingPairThreshold ] ,
55+ [ "boundedNonWhitespaceSequence" , surroundingPairThreshold ] ,
56+ [ { type : "surroundingPair" , delimiter : "any" } , surroundingPairThreshold ] ,
57+ [
58+ { type : "surroundingPair" , delimiter : "curlyBrackets" } ,
59+ surroundingPairThreshold ,
60+ ] ,
61+ ] ;
62+
63+ for ( const [ scope , threshold ] of fixtures ) {
64+ const [ scopeType , title ] = getScopeTypeAndTitle ( scope ) ;
5965 test (
60- `Select ${ scopeTypeType } ` ,
61- asyncSafety ( ( ) =>
62- selectScopeType (
63- { type : scopeTypeType as SimpleScopeTypeType } ,
64- threshold ,
65- ) ,
66- ) ,
66+ `Select ${ title } ` ,
67+ asyncSafety ( ( ) => selectScopeType ( scopeType , threshold ) ) ,
6768 ) ;
6869 }
69-
70- test (
71- "Select any surrounding pair" ,
72- asyncSafety ( ( ) =>
73- selectScopeType (
74- { type : "surroundingPair" , delimiter : "any" } ,
75- surroundingPairThreshold ,
76- ) ,
77- ) ,
78- ) ;
7970} ) ;
8071
8172async function removeToken ( threshold : number ) {
@@ -123,7 +114,20 @@ async function testPerformance(threshold: number, action: ActionDescriptor) {
123114 ) ;
124115}
125116
126- function generateTestData ( ) {
117+ function getScopeTypeAndTitle (
118+ scope : SimpleScopeTypeType | ScopeType ,
119+ ) : [ ScopeType , string ] {
120+ if ( typeof scope === "string" ) {
121+ return [ { type : scope } , scope ] ;
122+ }
123+ switch ( scope . type ) {
124+ case "surroundingPair" :
125+ return [ scope , `${ scope . type } .${ scope . delimiter } ` ] ;
126+ }
127+ throw Error ( `Unexpected scope type: ${ scope . type } ` ) ;
128+ }
129+
130+ function generateTestData ( ) : string {
127131 const value = Object . fromEntries (
128132 new Array ( 100 ) . fill ( "" ) . map ( ( _ , i ) => [ i . toString ( ) , "value" ] ) ,
129133 ) ;
0 commit comments