MCPcopy Create free account
hub / github.com/chanced/jsonptr / get_by_explicit_bounds

Function get_by_explicit_bounds

src/pointer/slice.rs:441–499  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

439
440 #[test]
441 fn get_by_explicit_bounds() {
442 let ptr = Pointer::from_static("/foo/bar/qux");
443 let s = ptr.get((Bound::Excluded(0), Bound::Included(2)));
444 assert_eq!(s, Some(Pointer::from_static("/bar/qux")));
445 let s = ptr.get((Bound::Excluded(0), Bound::Excluded(2)));
446 assert_eq!(s, Some(Pointer::from_static("/bar")));
447 let s = ptr.get((Bound::Excluded(0), Bound::Unbounded));
448 assert_eq!(s, Some(Pointer::from_static("/bar/qux")));
449 let s = ptr.get((Bound::Included(0), Bound::Included(2)));
450 assert_eq!(s, Some(Pointer::from_static("/foo/bar/qux")));
451 let s = ptr.get((Bound::Included(0), Bound::Excluded(2)));
452 assert_eq!(s, Some(Pointer::from_static("/foo/bar")));
453 let s = ptr.get((Bound::Included(0), Bound::Unbounded));
454 assert_eq!(s, Some(Pointer::from_static("/foo/bar/qux")));
455 let s = ptr.get((Bound::Unbounded, Bound::Included(2)));
456 assert_eq!(s, Some(Pointer::from_static("/foo/bar/qux")));
457 let s = ptr.get((Bound::Unbounded, Bound::Excluded(2)));
458 assert_eq!(s, Some(Pointer::from_static("/foo/bar")));
459 let s = ptr.get((Bound::Unbounded, Bound::Unbounded));
460 assert_eq!(s, Some(Pointer::from_static("/foo/bar/qux")));
461
462 let ptr = Pointer::from_static("/foo/bar");
463 let s = ptr.get((Bound::Excluded(0), Bound::Included(2)));
464 assert_eq!(s, None);
465 let s = ptr.get((Bound::Excluded(0), Bound::Excluded(2)));
466 assert_eq!(s, Some(Pointer::from_static("/bar")));
467 let s = ptr.get((Bound::Excluded(0), Bound::Unbounded));
468 assert_eq!(s, Some(Pointer::from_static("/bar")));
469 let s = ptr.get((Bound::Included(0), Bound::Included(2)));
470 assert_eq!(s, None);
471 let s = ptr.get((Bound::Included(0), Bound::Excluded(2)));
472 assert_eq!(s, Some(ptr));
473 let s = ptr.get((Bound::Included(0), Bound::Unbounded));
474 assert_eq!(s, Some(ptr));
475 let s = ptr.get((Bound::Unbounded, Bound::Included(2)));
476 assert_eq!(s, None);
477 let s = ptr.get((Bound::Unbounded, Bound::Excluded(2)));
478 assert_eq!(s, Some(ptr));
479 let s = ptr.get((Bound::Unbounded, Bound::Unbounded));
480 assert_eq!(s, Some(ptr));
481
482 // testing only the start excluded case a bit more exhaustively since
483 // other cases just delegate directly (so are covered by other tests)
484 let ptr = Pointer::from_static("/");
485 let s = ptr.get((Bound::Excluded(0), Bound::Included(0)));
486 assert_eq!(s, None);
487 let s = ptr.get((Bound::Excluded(0), Bound::Excluded(0)));
488 assert_eq!(s, None);
489 let s = ptr.get((Bound::Excluded(0), Bound::Unbounded));
490 assert_eq!(s, None);
491
492 let ptr = Pointer::from_static("");
493 let s = ptr.get((Bound::Excluded(0), Bound::Included(0)));
494 assert_eq!(s, None);
495 let s = ptr.get((Bound::Excluded(0), Bound::Excluded(0)));
496 assert_eq!(s, None);
497 let s = ptr.get((Bound::Excluded(0), Bound::Unbounded));
498 assert_eq!(s, None);

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected