Skip to content

Commit

Permalink
Document and test UrlPartsBuilder::push_fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
camelid committed Jan 14, 2022
1 parent cef250d commit c7147e4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/librustdoc/html/url_parts_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ impl UrlPartsBuilder {
self.buf.push_str(part);
}

/// Push a component onto the buffer, using [`format!`]'s formatting syntax.
///
/// # Examples
///
/// Basic usage (equivalent to the example for [`UrlPartsBuilder::push`]):
///
/// ```ignore (private-type)
/// let mut builder = UrlPartsBuilder::new();
/// builder.push("core");
/// builder.push("str");
/// builder.push_fmt(format_args!("{}.{}.html", "struct", "Bytes"));
/// assert_eq!(builder.finish(), "core/str/struct.Bytes.html");
/// ```
crate fn push_fmt(&mut self, args: fmt::Arguments<'_>) {
if !self.buf.is_empty() {
self.buf.push('/');
Expand Down
10 changes: 10 additions & 0 deletions src/librustdoc/html/url_parts_builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ fn push_front_non_empty() {
t(builder, "nightly/core/str/struct.Bytes.html");
}

#[test]
fn push_fmt() {
let mut builder = UrlPartsBuilder::new();
builder.push_fmt(format_args!("{}", "core"));
builder.push("str");
builder.push_front("nightly");
builder.push_fmt(format_args!("{}.{}.html", "struct", "Bytes"));
t(builder, "nightly/core/str/struct.Bytes.html");
}

#[test]
fn collect() {
t(["core", "str"].into_iter().collect(), "core/str");
Expand Down

0 comments on commit c7147e4

Please sign in to comment.