pub struct Data { /* private fields */ }
Expand description
Test fixture, actual output, or expected result
This provides conveniences for tracking the intended format (binary vs text).
Implementations§
source§impl Data
impl Data
sourcepub fn text(raw: impl Into<String>) -> Self
pub fn text(raw: impl Into<String>) -> Self
Mark the data as text (post-processing)
Examples found in repository?
examples/diff.rs (line 10)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
fn main() {
let mut args = std::env::args();
let _ = args.next().expect("expects `$ diff <old> <new>`");
let old_path = args.next().expect("expects `$ diff <old> <new>`");
let new_path = args.next().expect("expects `$ diff <old> <new>`");
if args.next().is_some() {
panic!("expects `$ diff <old> <new>`");
}
let old = snapbox::Data::text(std::fs::read_to_string(&old_path).unwrap());
let new = snapbox::Data::text(std::fs::read_to_string(&new_path).unwrap());
let mut output = String::new();
snapbox::report::write_diff(
&mut output,
&old,
&new,
Some(&old_path),
Some(&new_path),
snapbox::report::Palette::color(),
)
.unwrap();
println!("{output}");
}
pub fn json(raw: impl Into<Value>) -> Self
Available on crate feature
json
only.sourcepub fn read_from(
path: &Path,
data_format: Option<DataFormat>
) -> Result<Self, Error>
pub fn read_from( path: &Path, data_format: Option<DataFormat> ) -> Result<Self, Error>
Load test data from a file
sourcepub fn render(&self) -> Option<String>
pub fn render(&self) -> Option<String>
Return the underlying String
Note: this will not inspect binary data for being a valid String
.
pub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn try_coerce(self, format: DataFormat) -> Self
sourcepub fn format(&self) -> DataFormat
pub fn format(&self) -> DataFormat
Outputs the current DataFormat
of the underlying data
Trait Implementations§
source§impl PartialEq for Data
impl PartialEq for Data
impl Eq for Data
impl StructuralPartialEq for Data
Auto Trait Implementations§
impl RefUnwindSafe for Data
impl Send for Data
impl Sync for Data
impl Unpin for Data
impl UnwindSafe for Data
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more