|
8 | 8 | #include <catch2/catch_all.hpp> |
9 | 9 |
|
10 | 10 | #include "mamba/specs/conda_url.hpp" |
| 11 | +#include "mamba/util/build.hpp" |
11 | 12 |
|
12 | 13 | using namespace mamba::specs; |
13 | 14 |
|
@@ -488,4 +489,96 @@ namespace |
488 | 489 | REQUIRE(url. pretty_str() == "https://[email protected]:*****@mamba.org/some /path$/"); |
489 | 490 | } |
490 | 491 | } |
| 492 | + |
| 493 | + TEST_CASE("CondaURL::parse") |
| 494 | + { |
| 495 | + SECTION("File URL with 4 slashes, a drive letter, and percent encoded space") |
| 496 | + { |
| 497 | + // The URL passed to `CondaURL::parse` must be percent encoded |
| 498 | + auto url = CondaURL::parse("file:////D:/a/_temp/popen-gw0/some_other_parts%20spaces").value(); |
| 499 | + REQUIRE(url.path() == "//D:/a/_temp/popen-gw0/some_other_parts spaces"); |
| 500 | + REQUIRE( |
| 501 | + url.path(CondaURL::Decode::no) == "//D:/a/_temp/popen-gw0/some_other_parts%20spaces" |
| 502 | + ); |
| 503 | + REQUIRE(url.str() == "file:////D:/a/_temp/popen-gw0/some_other_parts%20spaces"); |
| 504 | + REQUIRE(url.pretty_str() == "file:////D:/a/_temp/popen-gw0/some_other_parts spaces"); |
| 505 | + } |
| 506 | + |
| 507 | + SECTION("File URL with 4 slashes, a drive letter, and non-encoded space") |
| 508 | + { |
| 509 | + // The URL passed to `CondaURL::parse` must be percent encoded |
| 510 | + REQUIRE_FALSE( |
| 511 | + CondaURL::parse("file:////D:/a/_temp/popen-gw0/some_other_parts spaces").has_value() |
| 512 | + ); |
| 513 | + } |
| 514 | + |
| 515 | + SECTION("File URL with 4 slashes") |
| 516 | + { |
| 517 | + auto url = CondaURL::parse("file:////ab/_temp/popen-gw0/some_other_parts").value(); |
| 518 | + REQUIRE(url.path() == "//ab/_temp/popen-gw0/some_other_parts"); |
| 519 | + REQUIRE(url.str() == "file:////ab/_temp/popen-gw0/some_other_parts"); |
| 520 | + REQUIRE(url.pretty_str() == "file:////ab/_temp/popen-gw0/some_other_parts"); |
| 521 | + } |
| 522 | + |
| 523 | + SECTION("File URL with 3 slashes and drive letter") |
| 524 | + { |
| 525 | + auto url = CondaURL::parse("file:///D:/a/_temp/popen-gw0/some_other_parts").value(); |
| 526 | + if (mamba::util::on_win) |
| 527 | + { |
| 528 | + REQUIRE(url.path() == "/D:/a/_temp/popen-gw0/some_other_parts"); |
| 529 | + REQUIRE(url.str() == "file:///D:/a/_temp/popen-gw0/some_other_parts"); |
| 530 | + REQUIRE(url.pretty_str() == "file:///D:/a/_temp/popen-gw0/some_other_parts"); |
| 531 | + } |
| 532 | + else |
| 533 | + { |
| 534 | + REQUIRE(url.path() == "//D:/a/_temp/popen-gw0/some_other_parts"); |
| 535 | + REQUIRE(url.str() == "file:////D:/a/_temp/popen-gw0/some_other_parts"); |
| 536 | + REQUIRE(url.pretty_str() == "file:////D:/a/_temp/popen-gw0/some_other_parts"); |
| 537 | + } |
| 538 | + } |
| 539 | + |
| 540 | + SECTION("File URL with 3 slashes") |
| 541 | + { |
| 542 | + auto url = CondaURL::parse("file:///ab/_temp/popen-gw0/some_other_parts").value(); |
| 543 | + REQUIRE(url.path() == "/ab/_temp/popen-gw0/some_other_parts"); |
| 544 | + REQUIRE(url.str() == "file:///ab/_temp/popen-gw0/some_other_parts"); |
| 545 | + REQUIRE(url.pretty_str() == "file:///ab/_temp/popen-gw0/some_other_parts"); |
| 546 | + } |
| 547 | + |
| 548 | + SECTION("File URL with 2 slashes and drive letter") |
| 549 | + { |
| 550 | + auto url = CondaURL::parse("file://D:/a/_temp/popen-gw0/some_other_parts").value(); |
| 551 | + if (mamba::util::on_win) |
| 552 | + { |
| 553 | + REQUIRE(url.path() == "/D:/a/_temp/popen-gw0/some_other_parts"); |
| 554 | + REQUIRE(url.str() == "file:///D:/a/_temp/popen-gw0/some_other_parts"); |
| 555 | + REQUIRE(url.pretty_str() == "file:///D:/a/_temp/popen-gw0/some_other_parts"); |
| 556 | + } |
| 557 | + else |
| 558 | + { |
| 559 | + REQUIRE(url.path() == "//D:/a/_temp/popen-gw0/some_other_parts"); |
| 560 | + REQUIRE(url.str() == "file:////D:/a/_temp/popen-gw0/some_other_parts"); |
| 561 | + REQUIRE(url.pretty_str() == "file:////D:/a/_temp/popen-gw0/some_other_parts"); |
| 562 | + } |
| 563 | + } |
| 564 | + |
| 565 | + SECTION("File URL with 2 slashes") |
| 566 | + { |
| 567 | + auto url = CondaURL::parse("file://ab/_temp/popen-gw0/some_other_parts").value(); |
| 568 | + REQUIRE(url.path() == "//ab/_temp/popen-gw0/some_other_parts"); |
| 569 | + REQUIRE(url.str() == "file:////ab/_temp/popen-gw0/some_other_parts"); |
| 570 | + REQUIRE(url.pretty_str() == "file:////ab/_temp/popen-gw0/some_other_parts"); |
| 571 | + } |
| 572 | + |
| 573 | + // NOTE This is not valid on any platform: |
| 574 | + // "file://\\D:/a/_temp/popen-gw0/some_other_parts" |
| 575 | + |
| 576 | + SECTION("file://\\abcd/_temp/popen-gw0/some_other_parts") |
| 577 | + { |
| 578 | + auto url = CondaURL::parse("file://\\abcd/_temp/popen-gw0/some_other_parts").value(); |
| 579 | + REQUIRE(url.path() == "//\\abcd/_temp/popen-gw0/some_other_parts"); |
| 580 | + REQUIRE(url.str() == "file:////\\abcd/_temp/popen-gw0/some_other_parts"); |
| 581 | + REQUIRE(url.pretty_str() == "file:////\\abcd/_temp/popen-gw0/some_other_parts"); |
| 582 | + } |
| 583 | + } |
491 | 584 | } |
0 commit comments