File tree 4 files changed +17
-9
lines changed
4 files changed +17
-9
lines changed Original file line number Diff line number Diff line change @@ -74,12 +74,12 @@ 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 ;
77
+ var child = this . branches [ part ] ;
78
+ if ( child === undefined ) {
79
+ // Requested node doesn't exist,
80
+ // consider it already removed.
80
81
return ;
81
82
}
82
- var child = this . branches [ part ] ;
83
83
child . remove ( path ) ;
84
84
if ( child . size === 0 && child . data === undefined ) {
85
85
// child has no branches and is not a leaf
Original file line number Diff line number Diff line change 1
1
{
2
2
"spec_dir" : " test" ,
3
3
"stopSpecOnExpectationFailure" : false ,
4
- "spec_files" : [" *spec .js" ]
4
+ "spec_files" : [" store_spec .js" ]
5
5
}
Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ describe("MemoryStore", function () {
102
102
103
103
it ( "doesn't explode when route is not defined" , function ( done ) {
104
104
// would blow up if an error was thrown
105
- this . subject . remove ( "/my_route" , done ) ;
105
+ this . subject . remove ( "/my_route/foo/bar " , done ) ;
106
106
} ) ;
107
107
} ) ;
108
108
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