1
1
import { Filtering , type MatchResult } from '@/components/ComponentBrowser/filtering'
2
- import { SuggestionEntry } from '@/stores/suggestionDatabase/entry'
2
+ import { type SuggestionEntry } from '@/stores/suggestionDatabase/entry'
3
3
import {
4
4
makeConstructor ,
5
5
makeFunction ,
@@ -9,9 +9,12 @@ import {
9
9
makeModuleMethod ,
10
10
makeStaticMethod ,
11
11
} from '@/stores/suggestionDatabase/mockSuggestion'
12
- import { qnLastSegment , QualifiedName } from '@/util/qualifiedName'
12
+ import { assert } from '@/util/assert'
13
+ import { parseAbsoluteProjectPath } from '@/util/projectPath'
14
+ import { qnLastSegment , tryQualifiedName } from '@/util/qualifiedName'
13
15
import { expect , test } from 'vitest'
14
- import { Opt } from 'ydoc-shared/util/data/opt'
16
+ import { type Opt } from 'ydoc-shared/util/data/opt'
17
+ import { unwrap } from 'ydoc-shared/util/data/result'
15
18
16
19
test . each ( [
17
20
makeModuleMethod ( 'Standard.Base.Data.read' , { group : 'Standard.Base.MockGroup1' } ) ,
@@ -37,11 +40,19 @@ test.each([
37
40
expect ( filtering . filter ( entry , [ ] ) ) . toBeNull ( )
38
41
} )
39
42
43
+ function stdPath ( path : string ) {
44
+ assert ( path . startsWith ( 'Standard.' ) )
45
+ return parseAbsoluteProjectPath ( unwrap ( tryQualifiedName ( path ) ) )
46
+ }
47
+
40
48
test ( 'An Instance method is shown when self arg matches' , ( ) => {
41
49
const entry1 = makeMethod ( 'Standard.Base.Data.Vector.Vector.get' )
42
50
const entry2 = makeMethod ( 'Standard.Base.Data.Table.get' )
43
51
const filteringWithSelfType = new Filtering ( {
44
- selfArg : { type : 'known' , typename : 'Standard.Base.Data.Vector.Vector' } ,
52
+ selfArg : {
53
+ type : 'known' ,
54
+ typename : stdPath ( 'Standard.Base.Data.Vector.Vector' ) ,
55
+ } ,
45
56
} )
46
57
expect ( filteringWithSelfType . filter ( entry1 , [ ] ) ) . not . toBeNull ( )
47
58
expect ( filteringWithSelfType . filter ( entry2 , [ ] ) ) . toBeNull ( )
@@ -59,7 +70,10 @@ test('`Any` type methods taken into account when filtering', () => {
59
70
const entry1 = makeMethod ( 'Standard.Base.Data.Vector.Vector.get' )
60
71
const entry2 = makeMethod ( 'Standard.Base.Any.Any.to_string' )
61
72
const filtering = new Filtering ( {
62
- selfArg : { type : 'known' , typename : 'Standard.Base.Data.Vector.Vector' } ,
73
+ selfArg : {
74
+ type : 'known' ,
75
+ typename : stdPath ( 'Standard.Base.Data.Vector.Vector' ) ,
76
+ } ,
63
77
} )
64
78
expect ( filtering . filter ( entry1 , [ ] ) ) . not . toBeNull ( )
65
79
expect ( filtering . filter ( entry2 , [ ] ) ) . not . toBeNull ( )
@@ -72,9 +86,9 @@ test('`Any` type methods taken into account when filtering', () => {
72
86
test ( 'Additional self types are taken into account when filtering' , ( ) => {
73
87
const entry1 = makeMethod ( 'Standard.Base.Data.Numbers.Float.abs' )
74
88
const entry2 = makeMethod ( 'Standard.Base.Data.Numbers.Number.sqrt' )
75
- const additionalSelfType = 'Standard.Base.Data.Numbers.Number' as QualifiedName
89
+ const additionalSelfType = stdPath ( 'Standard.Base.Data.Numbers.Number' )
76
90
const filtering = new Filtering ( {
77
- selfArg : { type : 'known' , typename : 'Standard.Base.Data.Numbers.Float' } ,
91
+ selfArg : { type : 'known' , typename : stdPath ( 'Standard.Base.Data.Numbers.Float' ) } ,
78
92
} )
79
93
expect ( filtering . filter ( entry1 , [ additionalSelfType ] ) ) . not . toBeNull ( )
80
94
expect ( filtering . filter ( entry2 , [ additionalSelfType ] ) ) . not . toBeNull ( )
@@ -97,7 +111,10 @@ test.each([
97
111
makeMethod ( 'Standard.Base.Data.Vector.Vector2.get' ) ,
98
112
] ) ( '$name is filtered out when Vector self type is specified' , ( entry ) => {
99
113
const filtering = new Filtering ( {
100
- selfArg : { type : 'known' , typename : 'Standard.Base.Data.Vector.Vector' } ,
114
+ selfArg : {
115
+ type : 'known' ,
116
+ typename : stdPath ( 'Standard.Base.Data.Vector.Vector' ) ,
117
+ } ,
101
118
} )
102
119
expect ( filtering . filter ( entry , [ ] ) ) . toBeNull ( )
103
120
} )
@@ -203,14 +220,14 @@ test.each<MatchingTestCase>([
203
220
] ,
204
221
} ,
205
222
{
206
- pattern : 'pr .foo' ,
223
+ pattern : 'ma .foo' ,
207
224
matchedSorted : [
208
- { module : 'local.Pr ' , name : 'foo' } , // exact match
209
- { module : 'local.Project' , name : 'foo' } , // name exact match and owner name start match
210
- { module : 'local.Pr ' , name : 'foobar' } , // module exact match and name start match
211
- { module : 'local.Pr ' , name : 'bar' , aliases : [ 'baz' , 'foo' ] } , // exact alias match
212
- { module : 'local.Project' , name : 'bar' , aliases : [ 'baz' , 'foo' ] } , // exact alias match, but nonexact owner match
213
- { module : 'local.Project' , name : 'bar' , aliases : [ 'bazbar' , 'foobar' ] } , // alias start match
225
+ { module : 'local.Project.Ma ' , name : 'foo' } , // exact match
226
+ { module : 'local.Project.Main ' , name : 'foo' } , // name exact match and owner name start match
227
+ { module : 'local.Project.Ma ' , name : 'foobar' } , // module exact match and name start match
228
+ { module : 'local.Project.Ma ' , name : 'bar' , aliases : [ 'baz' , 'foo' ] } , // exact alias match
229
+ { module : 'local.Project.Main ' , name : 'bar' , aliases : [ 'baz' , 'foo' ] } , // exact alias match, but nonexact owner match
230
+ { module : 'local.Project.Main ' , name : 'bar' , aliases : [ 'bazbar' , 'foobar' ] } , // alias start match
214
231
{ name : 'bar_foo' } , // name word exact match
215
232
{ name : 'baz_foobar' } , // name word start match
216
233
{ name : 'bar' , aliases : [ 'bar_foo' ] } , // alias word exact match
@@ -220,22 +237,25 @@ test.each<MatchingTestCase>([
220
237
] ,
221
238
notMatched : [
222
239
{ module : 'local.Project.Data' , name : 'foo' } ,
223
- { module : 'local.Ploject' , name : 'foo' } ,
224
240
{ module : 'local.Pr' , name : 'bar' } ,
225
241
] ,
226
242
} ,
227
243
] ) ( 'Matching pattern $pattern' , ( { pattern, matchedSorted, notMatched } ) => {
228
244
const filtering = new Filtering ( { pattern } )
229
- const matchedSortedEntries = Array . from ( matchedSorted , ( { name, aliases, module } ) =>
245
+ const matchedSortedEntries = matchedSorted . map ( ( { name, aliases, module } ) =>
230
246
makeModuleMethod ( `${ module ?? 'local.Project' } .${ name } ` , { aliases : aliases ?? [ ] } ) ,
231
247
)
232
- const matchResults = Array . from ( matchedSortedEntries , ( entry ) => filtering . filter ( entry , [ ] ) )
248
+ const matchResults = matchedSortedEntries . map ( ( entry ) => filtering . filter ( entry , [ ] ) )
233
249
// Checking matching entries
234
250
function checkResult ( entry : SuggestionEntry , result : Opt < MatchResult > ) {
235
- expect ( result , `Matching entry ${ entry . definitionPath } ` ) . not . toBeNull ( )
251
+ expect ( result , `Matching entry ${ JSON . stringify ( entry . definitionPath ) } ` ) . not . toBeNull ( )
236
252
expect (
237
253
matchedText (
238
- 'memberOf' in entry && entry . memberOf ? qnLastSegment ( entry . memberOf ) : '' ,
254
+ 'memberOf' in entry ?
255
+ entry . memberOf . path ?
256
+ qnLastSegment ( entry . memberOf . path )
257
+ : 'Main'
258
+ : '' ,
239
259
entry . name ,
240
260
result ! ,
241
261
)
@@ -257,10 +277,9 @@ test.each<MatchingTestCase>([
257
277
258
278
// Checking non-matching entries
259
279
for ( const { module, name, aliases } of notMatched ) {
260
- const entry = {
261
- ...makeModuleMethod ( `${ module ?? 'local.Project' } .${ name } ` ) ,
280
+ const entry = makeModuleMethod ( `${ module ?? 'local.Project' } .${ name } ` , {
262
281
aliases : aliases ?? [ ] ,
263
- }
264
- expect ( filtering . filter ( entry , [ ] ) , entry . definitionPath ) . toBeNull ( )
282
+ } )
283
+ expect ( filtering . filter ( entry , [ ] ) , JSON . stringify ( entry . definitionPath ) ) . toBeNull ( )
265
284
}
266
285
} )
0 commit comments