docs(codegen): fix example for CodeBuffer::print_ascii_bytes (#6535)

Fix example and add a test.
This commit is contained in:
overlookmotel 2024-10-14 01:09:02 +00:00
parent 77f3a1a9dd
commit 7e909a7e6c

View file

@ -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)
@ -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();