File tree Expand file tree Collapse file tree 5 files changed +76
-3
lines changed Expand file tree Collapse file tree 5 files changed +76
-3
lines changed Original file line number Diff line number Diff line change @@ -326,9 +326,7 @@ viewNamespaceListing viewConfig openDefinitions expandedNamespaceListings (Names
326
326
]
327
327
328
328
hasOpenDefinitions =
329
- openDefinitions
330
- |> FQNSet . toList
331
- |> List . any ( \ openFqn -> FQN . isSuffixOf name openFqn && not ( FQN . equals openFqn name))
329
+ FQNSet . isPrefixOfAny openDefinitions name
332
330
in
333
331
div [ class " subtree" ]
334
332
[ a
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ module Code.FullyQualifiedName exposing
12
12
, fromString
13
13
, fromUrlList
14
14
, fromUrlString
15
+ , isPrefixOf
15
16
, isRoot
16
17
, isSuffixOf
17
18
, isValidSegmentChar
@@ -293,6 +294,11 @@ isSuffixOf suffixName fqn =
293
294
String . endsWith ( toString suffixName) ( toString fqn)
294
295
295
296
297
+ isPrefixOf : FQN -> FQN -> Bool
298
+ isPrefixOf prefixName fqn =
299
+ String . startsWith ( toString prefixName) ( toString fqn)
300
+
301
+
296
302
isRoot : FQN -> Bool
297
303
isRoot ( FQN segments_) =
298
304
case NEL . toList segments_ of
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ module Code.FullyQualifiedNameSet exposing
5
5
, fromReference
6
6
, fromReferenceList
7
7
, insert
8
+ , isPrefixOfAny
8
9
, member
9
10
, remove
10
11
, singleton
@@ -85,6 +86,17 @@ toList (FQNSet set) =
85
86
|> List . map FQN . fromString
86
87
87
88
89
+ isPrefixOfAny : FQNSet -> FQN -> Bool
90
+ isPrefixOfAny ( FQNSet set) prefixFqn =
91
+ set
92
+ |> Set . toList
93
+ |> List . map FQN . fromString
94
+ |> List . any
95
+ ( \ item ->
96
+ FQN . isPrefixOf prefixFqn item && not ( FQN . equals item prefixFqn)
97
+ )
98
+
99
+
88
100
toggle : FQN -> FQNSet -> FQNSet
89
101
toggle fqn ( FQNSet set) =
90
102
FQNSet ( Set . Extra . toggle ( FQN . toString fqn) set)
Original file line number Diff line number Diff line change
1
+ module Code.FullyQualifiedNameSetTests exposing (..)
2
+
3
+ import Code.FullyQualifiedName as FQN exposing (..)
4
+ import Code.FullyQualifiedNameSet as FQNSet exposing (..)
5
+ import Expect
6
+ import List.Nonempty as NEL
7
+ import Test exposing (..)
8
+
9
+
10
+ isPrefixOfAny : Test
11
+ isPrefixOfAny =
12
+ describe " FQNSet.isPrefixOfAny"
13
+ [ test " returns true when the given FQN is a prefix of any of the members of the set" <|
14
+ \ _ ->
15
+ let
16
+ prefix =
17
+ FQN . fromList [ " BlogAuthor" ]
18
+
19
+ set =
20
+ FQNSet . fromList
21
+ [ FQN . fromList [ " BlogAuthor" , " avatar" ]
22
+ , FQN . fromList [ " Blog" , " view" ]
23
+ , FQN . fromList [ " Css" , " toText" ]
24
+ ]
25
+ in
26
+ Expect . equal True ( FQNSet . isPrefixOfAny set prefix)
27
+ ]
Original file line number Diff line number Diff line change @@ -300,6 +300,36 @@ isSuffixOf =
300
300
]
301
301
302
302
303
+ isPrefixOf : Test
304
+ isPrefixOf =
305
+ describe " FullyQualifiedName.isPrefixOf"
306
+ [ test " Returns True when an FQN begin with the provided prefix" <|
307
+ \ _ ->
308
+ let
309
+ prefix =
310
+ FQN . fromString " base.List"
311
+
312
+ fqn =
313
+ FQN . fromString " base.List.map"
314
+ in
315
+ FQN . isPrefixOf prefix fqn
316
+ |> Expect . equal True
317
+ |> Expect . onFail " is correctly a prefix of"
318
+ , test " Returns False when an FQN does begin with the provided prefix" <|
319
+ \ _ ->
320
+ let
321
+ prefix =
322
+ FQN . fromString " base.Text"
323
+
324
+ fqn =
325
+ FQN . fromString " base.List.map"
326
+ in
327
+ FQN . isPrefixOf prefix fqn
328
+ |> Expect . equal False
329
+ |> Expect . onFail " is correctly *not* a prefix of"
330
+ ]
331
+
332
+
303
333
namespaceOf : Test
304
334
namespaceOf =
305
335
describe " FullyQualifiedName.namespaceOf"
You can’t perform that action at this time.
0 commit comments