Skip to content

Commit

Permalink
test(codegen): add test for CodeBuffer::print_byte_unchecked (#6497)
Browse files Browse the repository at this point in the history
Add test, and rename the rest of the test functions for `CodeBuffer`.
  • Loading branch information
overlookmotel committed Oct 13, 2024
1 parent 8ae174b commit d816b0b
Showing 1 changed file with 21 additions and 5 deletions.
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

0 comments on commit d816b0b

Please sign in to comment.