Skip to content

Commit

Permalink
docs(codegen): fix example for CodeBuffer::print_ascii_bytes (#6535)
Browse files Browse the repository at this point in the history
Fix example and add a test.
  • Loading branch information
overlookmotel committed Oct 14, 2024
1 parent 77f3a1a commit 7e909a7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion crates/oxc_codegen/src/code_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ impl CodeBuffer {
/// use oxc_codegen::CodeBuffer;
/// let mut code = CodeBuffer::new();
///
/// code.print_ascii([b'f', b'o', b'o'].into_iter());
/// code.print_ascii_bytes([b'f', b'o', b'o']);
/// assert_eq!(String::from(code), "foo");
/// ```
pub fn print_ascii_bytes<I>(&mut self, bytes: I)
Expand Down Expand Up @@ -497,6 +497,17 @@ mod test {
assert_eq!(String::from(code), "foo");
}

#[test]
#[allow(clippy::byte_char_slices)]
fn print_ascii_bytes() {
let mut code = CodeBuffer::new();
code.print_ascii_bytes([b'f', b'o', b'o']);

assert_eq!(code.len(), 3);
assert_eq!(code.as_bytes(), &[b'f', b'o', b'o']);
assert_eq!(String::from(code), "foo");
}

#[test]
fn peek_nth_char_back() {
let mut code = CodeBuffer::new();
Expand Down

0 comments on commit 7e909a7

Please sign in to comment.