Skip to content
Merged
Show file tree
Hide file tree
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
21 changes: 0 additions & 21 deletions crates/snapbox/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,27 +89,6 @@ impl Data {
op.normalize(self)
}

/// Coerce to a string
///
/// Note: this will **not** do a binary-content check
pub fn make_text(&mut self) -> Result<(), std::str::Utf8Error> {
*self = Self::text(std::mem::take(self).into_string()?);
Ok(())
}

/// Coerce to a string
///
/// Note: this will **not** do a binary-content check
pub fn into_string(self) -> Result<String, std::str::Utf8Error> {
match self.inner {
DataInner::Binary(data) => {
let data = String::from_utf8(data).map_err(|e| e.utf8_error())?;
Ok(data)
}
DataInner::Text(data) => Ok(data),
}
}

/// Return the underlying `String`
///
/// Note: this will not inspect binary data for being a valid `String`.
Expand Down
10 changes: 5 additions & 5 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::io::prelude::*;

use rayon::prelude::*;
use snapbox::path::FileType;
use snapbox::{NormalizeNewlines, NormalizePaths};
use snapbox::{DataFormat, NormalizeNewlines, NormalizePaths};

#[derive(Debug)]
pub(crate) struct Runner {
Expand Down Expand Up @@ -720,11 +720,11 @@ struct Stream {

impl Stream {
fn make_text(mut self) -> Self {
if self.content.make_text().is_err() {
self.status = StreamStatus::Failure("invalid UTF-8".into());
let content = self.content.try_coerce(DataFormat::Text);
if content.format() != DataFormat::Text {
self.status = StreamStatus::Failure("Unable to convert underlying Data to Text".into());
}
self.content = self
.content
self.content = content
.normalize(NormalizePaths)
.normalize(NormalizeNewlines);
self
Expand Down