Skip to content

Commit

Permalink
Merge pull request #125 from Muscraft/refactor-make-text
Browse files Browse the repository at this point in the history
refactor(snapbox): Remove `into_string`
  • Loading branch information
epage committed Aug 22, 2022
2 parents 9494040 + 8724a5c commit 1bfcac1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 26 deletions.
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

0 comments on commit 1bfcac1

Please sign in to comment.