cargo_test_support::prelude

Trait IntoData

pub trait IntoData: Sized {
Show 13 methods // Required method fn into_data(self) -> Data; // Provided methods fn raw(self) -> Data { ... } fn unordered(self) -> Data { ... } fn is(self, format: DataFormat) -> Data { ... } fn is_json(self) -> Data { ... } fn json(self) -> Data { ... } fn is_jsonlines(self) -> Data { ... } fn json_lines(self) -> Data { ... } fn is_termsvg(self) -> Data { ... } fn term_svg(self) -> Data { ... } fn against(self, format: DataFormat) -> Data { ... } fn against_json(self) -> Data { ... } fn against_jsonlines(self) -> Data { ... }
}
Expand description

Convert to [Data] with modifiers for expected data

Required Methods§

fn into_data(self) -> Data

Convert to [Data], applying defaults

Provided Methods§

fn raw(self) -> Data

Remove default [filters][crate::filter] from this expected result

fn unordered(self) -> Data

Treat lines and json arrays as unordered

§Examples
use snapbox::prelude::*;
use snapbox::str;
use snapbox::assert_data_eq;

let actual = str![[r#"["world", "hello"]"#]]
    .is(snapbox::data::DataFormat::Json)
    .unordered();
let expected = str![[r#"["hello", "world"]"#]]
    .is(snapbox::data::DataFormat::Json)
    .unordered();
assert_data_eq!(actual, expected);

fn is(self, format: DataFormat) -> Data

Initialize as [format][DataFormat] or [Error][DataFormat::Error]

This is generally used for expected data

§Examples
use snapbox::prelude::*;
use snapbox::str;

let expected = str![[r#"{"hello": "world"}"#]]
    .is(snapbox::data::DataFormat::Json);
assert_eq!(expected.format(), snapbox::data::DataFormat::Json);

fn is_json(self) -> Data

Initialize as json or [Error][DataFormat::Error]

This is generally used for expected data

§Examples
use snapbox::prelude::*;
use snapbox::str;

let expected = str![[r#"{"hello": "world"}"#]]
    .is_json();
assert_eq!(expected.format(), snapbox::data::DataFormat::Json);

fn json(self) -> Data

👎Deprecated since 0.6.13: Replaced with IntoData::is_json

fn is_jsonlines(self) -> Data

Initialize as json lines or [Error][DataFormat::Error]

This is generally used for expected data

§Examples
use snapbox::prelude::*;
use snapbox::str;

let expected = str![[r#"{"hello": "world"}"#]]
    .is_jsonlines();
assert_eq!(expected.format(), snapbox::data::DataFormat::JsonLines);

fn json_lines(self) -> Data

👎Deprecated since 0.6.13: Replaced with IntoData::is_jsonlines

fn is_termsvg(self) -> Data

Initialize as Term SVG

This is generally used for expected data

fn term_svg(self) -> Data

👎Deprecated since 0.6.13: Replaced with IntoData::is_termsvg

fn against(self, format: DataFormat) -> Data

Override the type this snapshot will be compared against

Normally, the actual data is coerced to IntoData::is. This allows overriding that so you can store your snapshot in a more readable, diffable format.

§Examples
use snapbox::prelude::*;
use snapbox::str;

let expected = str![[r#"{"hello": "world"}"#]]
    .against(snapbox::data::DataFormat::JsonLines);

fn against_json(self) -> Data

Initialize as json or [Error][DataFormat::Error]

This is generally used for expected data

§Examples
use snapbox::prelude::*;
use snapbox::str;

let expected = str![[r#"{"hello": "world"}"#]]
    .is_json();

fn against_jsonlines(self) -> Data

Initialize as json lines or [Error][DataFormat::Error]

This is generally used for expected data

§Examples
use snapbox::prelude::*;
use snapbox::str;

let expected = str![[r#"{"hello": "world"}"#]]
    .against_jsonlines();

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

§

impl IntoData for &str

§

fn into_data(self) -> Data

§

impl IntoData for &String

§

fn into_data(self) -> Data

§

impl IntoData for &[u8]

§

fn into_data(self) -> Data

§

impl IntoData for String

§

fn into_data(self) -> Data

§

impl IntoData for Vec<u8>

§

fn into_data(self) -> Data

Implementors§

§

impl IntoData for &Data

§

impl IntoData for Data

§

impl IntoData for Inline