Skip to content

Commit

Permalink
test: add tests for replace_non_printable and cleanup commented out code
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpasmantier committed Nov 23, 2024
1 parent 4efe89c commit b3c55b3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
4 changes: 0 additions & 4 deletions crates/television-channels/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ impl Entry {
self
}

//pub fn display_name(&self) -> &str {
// self.display_name.as_ref().unwrap_or(&self.name)
//}

pub fn stdout_repr(&self) -> String {
let mut repr = self.name.clone();
if repr.contains(|c| char::is_ascii_whitespace(&c)) {
Expand Down
39 changes: 29 additions & 10 deletions crates/television-utils/src/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,6 @@ const APPLICATION_PROGRAM_COMMAND_CHARACTER: char = '\u{009F}';
/// let (output, offsets) = replace_non_printable(input, 2);
/// assert_eq!(output, "Hello,World!");
/// assert_eq!(offsets, vec![0,0,0,0,0,0,0,-1,-1,-1,-1,-1,-1]);
///
/// let input = b"Hello,\x00World!";
/// let (output, offsets) = replace_non_printable(input, 2);
/// assert_eq!(output, "Hello,␀World!");
/// assert_eq!(offsets, vec![0,0,0,0,0,0,0,0,0,0,0,0,0]);
///
/// let input = b"Hello,\x7FWorld!";
/// let (output, offsets) = replace_non_printable(input, 2);
/// assert_eq!(output, "Hello,␀World!");
/// assert_eq!(offsets, vec![0,0,0,0,0,0,0,0,0,0,0,0,0]);
/// ```
pub fn replace_non_printable(
input: &[u8],
Expand Down Expand Up @@ -569,6 +559,35 @@ mod tests {
test_replace_non_printable("Àì", "Àì␀");
}

#[test]
fn test_replace_non_printable_range_tab() {
let input = b"Hello,\tWorld!";
let (output, offsets) = replace_non_printable(input, 4);
assert_eq!(output, "Hello, World!");
assert_eq!(offsets, vec![0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3]);
}

#[test]
fn test_replace_non_printable_range_line_feed() {
let input = b"Hello,\nWorld!";
let (output, offsets) = replace_non_printable(input, 2);
assert_eq!(output, "Hello,World!");
assert_eq!(offsets, vec![0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1]);
}

#[test]
fn test_replace_non_printable_no_range_changes() {
let input = b"Hello,\x00World!";
let (output, offsets) = replace_non_printable(input, 2);
assert_eq!(output, "Hello,␀World!");
assert_eq!(offsets, vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);

let input = b"Hello,\x7FWorld!";
let (output, offsets) = replace_non_printable(input, 2);
assert_eq!(output, "Hello,␀World!");
assert_eq!(offsets, vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
}

fn test_proportion_of_printable_ascii_characters(
input: &str,
expected: f32,
Expand Down

0 comments on commit b3c55b3

Please sign in to comment.