File tree 2 files changed +11
-8
lines changed
2 files changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -74,11 +74,6 @@ URLTrie.prototype.remove = function (path) {
74
74
return ;
75
75
}
76
76
var part = path . shift ( ) ;
77
- if ( path . length === 0 ) {
78
- delete this . branches [ part ] ;
79
- this . size -= 1 ;
80
- return ;
81
- }
82
77
var child = this . branches [ part ] ;
83
78
child . remove ( path ) ;
84
79
if ( child . size === 0 && child . data === undefined ) {
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ describe("URLTrie", function () {
13
13
'/a/b/c/d' ,
14
14
'/a/b/d' ,
15
15
'/a/b/e' ,
16
+ '/b' ,
16
17
'/b/c' ,
17
18
'/b/c/d' ,
18
19
] ;
@@ -137,11 +138,18 @@ describe("URLTrie", function () {
137
138
it ( "trie_remove" , function ( done ) {
138
139
var trie = full_trie ( ) ;
139
140
var size = trie . size ;
141
+ var node ;
142
+ node = trie . get ( '/b/just-b' ) ;
143
+ expect ( node . prefix ) . toEqual ( '/b' ) ;
144
+
140
145
trie . remove ( '/b' ) ;
141
- expect ( trie . size ) . toEqual ( size - 1 ) ;
142
- expect ( trie . get ( '/b/c/dword' ) ) . toBe ( undefined ) ;
146
+ // deleting a node doesn't change size if no children
147
+ expect ( trie . size ) . toEqual ( size ) ;
148
+ expect ( trie . get ( '/b/just-b' ) ) . toBe ( undefined ) ;
149
+ node = trie . get ( '/b/c/sub-still-here' ) ;
150
+ expect ( node . prefix ) . toEqual ( '/b/c' ) ;
143
151
144
- var node = trie . get ( '/a/b/c/d/word' ) ;
152
+ node = trie . get ( '/a/b/c/d/word' ) ;
145
153
expect ( node . prefix ) . toEqual ( '/a/b/c/d' ) ;
146
154
var b = trie . branches . a . branches . b ;
147
155
expect ( b . size ) . toEqual ( 3 ) ;
You can’t perform that action at this time.
0 commit comments