Skip to content

Commit

Permalink
Add a bespoke URL.with_fragment.
Browse files Browse the repository at this point in the history
Clearly this doesn't fully solve #6, but we're going to incrementally
maintain immutability while adding out methods here.
  • Loading branch information
Julian committed Jun 6, 2024
1 parent 549c005 commit 6514873
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ impl UrlPy {
fn cannot_be_a_base(&self) -> bool {
self.inner.cannot_be_a_base()
}

fn with_fragment(&self, fragment: Option<&str>) -> Self {
let mut cloned = self.inner.clone();
cloned.set_fragment(fragment);
UrlPy { inner: cloned }
}
}

#[repr(transparent)]
Expand Down
8 changes: 8 additions & 0 deletions tests/test_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ def test_make_relative():
assert relative == "c.png"


def test_with_fragment():
url = URL.parse("https://example.com/data.csv")
assert url.fragment is None

evolved = url.with_fragment("foo")
assert (evolved.fragment, url.fragment) == ("foo", None)


@pytest.mark.parametrize(
"base_url",
["http://foo.com/bar", "http://foo.com/bar/"],
Expand Down

0 comments on commit 6514873

Please sign in to comment.