Trait cargo_test_support::prelude::IntoData

source ·
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§

source

fn into_data(self) -> Data

Convert to Data, applying defaults

Provided Methods§

source

fn raw(self) -> Data

Remove default filters from this expected result

source

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);
source

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

Initialize as format or 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);
source

fn is_json(self) -> Data

Initialize as json or 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);
source

fn json(self) -> Data

👎Deprecated since 0.6.13: Replaced with IntoData::is_json
source

fn is_jsonlines(self) -> Data

Initialize as json lines or 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);
source

fn json_lines(self) -> Data

👎Deprecated since 0.6.13: Replaced with IntoData::is_jsonlines
source

fn is_termsvg(self) -> Data

Initialize as Term SVG

This is generally used for expected data

source

fn term_svg(self) -> Data

👎Deprecated since 0.6.13: Replaced with IntoData::is_termsvg
source

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);
source

fn against_json(self) -> Data

Initialize as json or Error

This is generally used for expected data

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

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

fn against_jsonlines(self) -> Data

Initialize as json lines or 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§

source§

impl IntoData for &str

source§

impl IntoData for &String

source§

impl IntoData for &[u8]

source§

impl IntoData for String

source§

impl IntoData for Vec<u8>

Implementors§