@@ -309,7 +309,7 @@ fn drain_to_empty_test() {
309
309
fn test_cursor_move_peek ( ) {
310
310
let mut m: LinkedList < u32 > = LinkedList :: new ( ) ;
311
311
m. extend ( & [ 1 , 2 , 3 , 4 , 5 , 6 ] ) ;
312
- let mut cursor = m. cursor ( ) ;
312
+ let mut cursor = m. cursor_front ( ) ;
313
313
assert_eq ! ( cursor. current( ) , Some ( & 1 ) ) ;
314
314
assert_eq ! ( cursor. peek_next( ) , Some ( & 2 ) ) ;
315
315
assert_eq ! ( cursor. peek_prev( ) , None ) ;
@@ -326,9 +326,26 @@ fn test_cursor_move_peek() {
326
326
assert_eq ! ( cursor. peek_prev( ) , Some ( & 1 ) ) ;
327
327
assert_eq ! ( cursor. index( ) , Some ( 1 ) ) ;
328
328
329
+ let mut cursor = m. cursor_back ( ) ;
330
+ assert_eq ! ( cursor. current( ) , Some ( & 6 ) ) ;
331
+ assert_eq ! ( cursor. peek_next( ) , None ) ;
332
+ assert_eq ! ( cursor. peek_prev( ) , Some ( & 5 ) ) ;
333
+ assert_eq ! ( cursor. index( ) , Some ( 5 ) ) ;
334
+ cursor. move_next ( ) ;
335
+ assert_eq ! ( cursor. current( ) , None ) ;
336
+ assert_eq ! ( cursor. peek_next( ) , Some ( & 1 ) ) ;
337
+ assert_eq ! ( cursor. peek_prev( ) , Some ( & 6 ) ) ;
338
+ assert_eq ! ( cursor. index( ) , None ) ;
339
+ cursor. move_prev ( ) ;
340
+ cursor. move_prev ( ) ;
341
+ assert_eq ! ( cursor. current( ) , Some ( & 5 ) ) ;
342
+ assert_eq ! ( cursor. peek_next( ) , Some ( & 6 ) ) ;
343
+ assert_eq ! ( cursor. peek_prev( ) , Some ( & 4 ) ) ;
344
+ assert_eq ! ( cursor. index( ) , Some ( 4 ) ) ;
345
+
329
346
let mut m: LinkedList < u32 > = LinkedList :: new ( ) ;
330
347
m. extend ( & [ 1 , 2 , 3 , 4 , 5 , 6 ] ) ;
331
- let mut cursor = m. cursor_mut ( ) ;
348
+ let mut cursor = m. cursor_front_mut ( ) ;
332
349
assert_eq ! ( cursor. current( ) , Some ( & mut 1 ) ) ;
333
350
assert_eq ! ( cursor. peek_next( ) , Some ( & mut 2 ) ) ;
334
351
assert_eq ! ( cursor. peek_prev( ) , None ) ;
@@ -352,24 +369,51 @@ fn test_cursor_move_peek() {
352
369
assert_eq ! ( cursor2. index( ) , Some ( 2 ) ) ;
353
370
assert_eq ! ( cursor. current( ) , Some ( & mut 2 ) ) ;
354
371
assert_eq ! ( cursor. index( ) , Some ( 1 ) ) ;
372
+
373
+ let mut m: LinkedList < u32 > = LinkedList :: new ( ) ;
374
+ m. extend ( & [ 1 , 2 , 3 , 4 , 5 , 6 ] ) ;
375
+ let mut cursor = m. cursor_back_mut ( ) ;
376
+ assert_eq ! ( cursor. current( ) , Some ( & mut 6 ) ) ;
377
+ assert_eq ! ( cursor. peek_next( ) , None ) ;
378
+ assert_eq ! ( cursor. peek_prev( ) , Some ( & mut 5 ) ) ;
379
+ assert_eq ! ( cursor. index( ) , Some ( 5 ) ) ;
380
+ cursor. move_next ( ) ;
381
+ assert_eq ! ( cursor. current( ) , None ) ;
382
+ assert_eq ! ( cursor. peek_next( ) , Some ( & mut 1 ) ) ;
383
+ assert_eq ! ( cursor. peek_prev( ) , Some ( & mut 6 ) ) ;
384
+ assert_eq ! ( cursor. index( ) , None ) ;
385
+ cursor. move_prev ( ) ;
386
+ cursor. move_prev ( ) ;
387
+ assert_eq ! ( cursor. current( ) , Some ( & mut 5 ) ) ;
388
+ assert_eq ! ( cursor. peek_next( ) , Some ( & mut 6 ) ) ;
389
+ assert_eq ! ( cursor. peek_prev( ) , Some ( & mut 4 ) ) ;
390
+ assert_eq ! ( cursor. index( ) , Some ( 4 ) ) ;
391
+ let mut cursor2 = cursor. as_cursor ( ) ;
392
+ assert_eq ! ( cursor2. current( ) , Some ( & 5 ) ) ;
393
+ assert_eq ! ( cursor2. index( ) , Some ( 4 ) ) ;
394
+ cursor2. move_prev ( ) ;
395
+ assert_eq ! ( cursor2. current( ) , Some ( & 4 ) ) ;
396
+ assert_eq ! ( cursor2. index( ) , Some ( 3 ) ) ;
397
+ assert_eq ! ( cursor. current( ) , Some ( & mut 5 ) ) ;
398
+ assert_eq ! ( cursor. index( ) , Some ( 4 ) ) ;
355
399
}
356
400
357
401
#[ test]
358
402
fn test_cursor_mut_insert ( ) {
359
403
let mut m: LinkedList < u32 > = LinkedList :: new ( ) ;
360
404
m. extend ( & [ 1 , 2 , 3 , 4 , 5 , 6 ] ) ;
361
- let mut cursor = m. cursor_mut ( ) ;
405
+ let mut cursor = m. cursor_front_mut ( ) ;
362
406
cursor. insert_before ( 7 ) ;
363
407
cursor. insert_after ( 8 ) ;
364
408
check_links ( & m) ;
365
409
assert_eq ! ( m. iter( ) . cloned( ) . collect:: <Vec <_>>( ) , & [ 7 , 1 , 8 , 2 , 3 , 4 , 5 , 6 ] ) ;
366
- let mut cursor = m. cursor_mut ( ) ;
410
+ let mut cursor = m. cursor_front_mut ( ) ;
367
411
cursor. move_prev ( ) ;
368
412
cursor. insert_before ( 9 ) ;
369
413
cursor. insert_after ( 10 ) ;
370
414
check_links ( & m) ;
371
415
assert_eq ! ( m. iter( ) . cloned( ) . collect:: <Vec <_>>( ) , & [ 10 , 7 , 1 , 8 , 2 , 3 , 4 , 5 , 6 , 9 ] ) ;
372
- let mut cursor = m. cursor_mut ( ) ;
416
+ let mut cursor = m. cursor_front_mut ( ) ;
373
417
cursor. move_prev ( ) ;
374
418
assert_eq ! ( cursor. remove_current( ) , None ) ;
375
419
cursor. move_next ( ) ;
@@ -383,7 +427,7 @@ fn test_cursor_mut_insert() {
383
427
assert_eq ! ( cursor. remove_current( ) , Some ( 10 ) ) ;
384
428
check_links ( & m) ;
385
429
assert_eq ! ( m. iter( ) . cloned( ) . collect:: <Vec <_>>( ) , & [ 1 , 8 , 2 , 3 , 4 , 5 , 6 ] ) ;
386
- let mut cursor = m. cursor_mut ( ) ;
430
+ let mut cursor = m. cursor_front_mut ( ) ;
387
431
let mut p: LinkedList < u32 > = LinkedList :: new ( ) ;
388
432
p. extend ( & [ 100 , 101 , 102 , 103 ] ) ;
389
433
let mut q: LinkedList < u32 > = LinkedList :: new ( ) ;
@@ -395,12 +439,12 @@ fn test_cursor_mut_insert() {
395
439
m. iter( ) . cloned( ) . collect:: <Vec <_>>( ) ,
396
440
& [ 200 , 201 , 202 , 203 , 1 , 100 , 101 , 102 , 103 , 8 , 2 , 3 , 4 , 5 , 6 ]
397
441
) ;
398
- let mut cursor = m. cursor_mut ( ) ;
442
+ let mut cursor = m. cursor_front_mut ( ) ;
399
443
cursor. move_prev ( ) ;
400
444
let tmp = cursor. split_before ( ) ;
401
445
assert_eq ! ( m. into_iter( ) . collect:: <Vec <_>>( ) , & [ ] ) ;
402
446
m = tmp;
403
- let mut cursor = m. cursor_mut ( ) ;
447
+ let mut cursor = m. cursor_front_mut ( ) ;
404
448
cursor. move_next ( ) ;
405
449
cursor. move_next ( ) ;
406
450
cursor. move_next ( ) ;
0 commit comments