| 534 | |
| 535 | #[test] |
| 536 | fn test_prefix_path() { |
| 537 | let root = std::env::current_dir().unwrap(); |
| 538 | let root = root.to_string_lossy(); |
| 539 | |
| 540 | let url = ListingTableUrl::parse(root).unwrap(); |
| 541 | let child = url.prefix.clone().join("partition").join("file"); |
| 542 | |
| 543 | let prefix: Vec<_> = url.strip_prefix(&child).unwrap().collect(); |
| 544 | assert_eq!(prefix, vec!["partition", "file"]); |
| 545 | |
| 546 | let url = ListingTableUrl::parse("file:///").unwrap(); |
| 547 | let child = Path::parse("/foo/bar").unwrap(); |
| 548 | let prefix: Vec<_> = url.strip_prefix(&child).unwrap().collect(); |
| 549 | assert_eq!(prefix, vec!["foo", "bar"]); |
| 550 | |
| 551 | let url = ListingTableUrl::parse("file:///foo").unwrap(); |
| 552 | let child = Path::parse("/foob/bar").unwrap(); |
| 553 | assert!(url.strip_prefix(&child).is_none()); |
| 554 | |
| 555 | let url = ListingTableUrl::parse("file:///foo/file").unwrap(); |
| 556 | let child = Path::parse("/foo/file").unwrap(); |
| 557 | assert_eq!(url.strip_prefix(&child).unwrap().count(), 0); |
| 558 | |
| 559 | let url = ListingTableUrl::parse("file:///foo/ bar").unwrap(); |
| 560 | assert_eq!(url.prefix.as_ref(), "foo/ bar"); |
| 561 | |
| 562 | let url = ListingTableUrl::parse("file:///foo/bar?").unwrap(); |
| 563 | assert_eq!(url.prefix.as_ref(), "foo/bar"); |
| 564 | |
| 565 | let url = ListingTableUrl::parse("file:///foo/😺").unwrap(); |
| 566 | assert_eq!(url.prefix.as_ref(), "foo/😺"); |
| 567 | |
| 568 | let url = ListingTableUrl::parse("file:///foo/bar%2Efoo").unwrap(); |
| 569 | assert_eq!(url.prefix.as_ref(), "foo/bar.foo"); |
| 570 | |
| 571 | let url = ListingTableUrl::parse("file:///foo/bar%2Efoo").unwrap(); |
| 572 | assert_eq!(url.prefix.as_ref(), "foo/bar.foo"); |
| 573 | |
| 574 | let url = ListingTableUrl::parse("file:///foo/bar%252Ffoo").unwrap(); |
| 575 | assert_eq!(url.prefix.as_ref(), "foo/bar%2Ffoo"); |
| 576 | |
| 577 | let url = ListingTableUrl::parse("file:///foo/a%252Fb.txt").unwrap(); |
| 578 | assert_eq!(url.prefix.as_ref(), "foo/a%2Fb.txt"); |
| 579 | |
| 580 | let dir = tempdir().unwrap(); |
| 581 | let path = dir.path().join("bar%2Ffoo"); |
| 582 | std::fs::File::create(&path).unwrap(); |
| 583 | |
| 584 | let url = ListingTableUrl::parse(path.to_str().unwrap()).unwrap(); |
| 585 | assert!(url.prefix.as_ref().ends_with("bar%2Ffoo"), "{}", url.prefix); |
| 586 | |
| 587 | let url = ListingTableUrl::parse("file:///foo/../a%252Fb.txt").unwrap(); |
| 588 | assert_eq!(url.prefix.as_ref(), "a%2Fb.txt"); |
| 589 | |
| 590 | let url = |
| 591 | ListingTableUrl::parse("file:///foo/./bar/../../baz/./test.txt").unwrap(); |
| 592 | assert_eq!(url.prefix.as_ref(), "baz/test.txt"); |
| 593 | |