Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(codegen): add test for CodeBuffer::print_byte_unchecked #6497

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions crates/oxc_codegen/src/code_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,15 +365,15 @@ mod test {
use super::CodeBuffer;

#[test]
fn test_empty() {
fn empty() {
let code = CodeBuffer::default();
assert!(code.is_empty());
assert_eq!(code.len(), 0);
assert_eq!(String::from(code), "");
}

#[test]
fn test_string_isomorphism() {
fn string_isomorphism() {
let s = "Hello, world!";
let mut code = CodeBuffer::with_capacity(s.len());
code.print_str(s);
Expand All @@ -382,7 +382,7 @@ mod test {
}

#[test]
fn test_into_source_string() {
fn into_source_string() {
let s = "Hello, world!";
let mut code = CodeBuffer::with_capacity(s.len());
code.print_str(s);
Expand All @@ -400,7 +400,7 @@ mod test {

#[test]
#[allow(clippy::byte_char_slices)]
fn test_print_byte_unchecked() {
fn print_ascii_byte() {
let mut code = CodeBuffer::new();
code.print_ascii_byte(b'f');
code.print_ascii_byte(b'o');
Expand All @@ -412,7 +412,23 @@ mod test {
}

#[test]
fn test_peek() {
#[allow(clippy::byte_char_slices)]
fn print_byte_unchecked() {
let mut code = CodeBuffer::new();
// SAFETY: These bytes are all ASCII
unsafe {
code.print_byte_unchecked(b'f');
code.print_byte_unchecked(b'o');
code.print_byte_unchecked(b'o');
}

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

#[test]
fn peek_nth_back() {
let mut code = CodeBuffer::new();
code.print_str("foo");

Expand Down