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
4 changes: 2 additions & 2 deletions cargo-insta/tests/functional/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn test_trailing_comma_in_inline_snapshot() {

assert!(&output.status.success());

assert_snapshot!(test_project.diff("src/lib.rs"), @r##"
assert_snapshot!(test_project.diff("src/lib.rs"), @r#"
--- Original: src/lib.rs
+++ Updated: src/lib.rs
@@ -1,21 +1,19 @@
Expand Down Expand Up @@ -223,7 +223,7 @@ fn test_trailing_comma_in_inline_snapshot() {
+ @"new value", // comma here
);
}
"##);
"#);
}

/// Test the old format of inline YAML snapshots with a leading `---` still passes
Expand Down
24 changes: 12 additions & 12 deletions cargo-insta/tests/functional/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn test_root_crate_workspace_accept() {

assert!(&output.status.success());

assert_snapshot!(test_project.file_tree_diff(), @r###"
assert_snapshot!(test_project.file_tree_diff(), @r"
--- Original file tree
+++ Updated file tree
@@ -1,8 +1,13 @@
Expand All @@ -105,7 +105,7 @@ fn test_root_crate_workspace_accept() {
src/main.rs
+ src/snapshots
+ src/snapshots/root_crate_workspace_accept__root.snap
"### );
" );
}

/// Check that in a workspace with a default root crate, running `cargo insta
Expand Down Expand Up @@ -145,7 +145,7 @@ fn test_root_crate_no_all() {

assert!(&output.status.success());

assert_snapshot!(test_project.file_tree_diff(), @r###"
assert_snapshot!(test_project.file_tree_diff(), @r"
--- Original file tree
+++ Updated file tree
@@ -1,4 +1,5 @@
Expand All @@ -160,7 +160,7 @@ fn test_root_crate_no_all() {
src/main.rs
+ src/snapshots
+ src/snapshots/root_crate_no_all__root.snap
"### );
" );
}

fn workspace_with_virtual_manifest(name: String) -> TestFiles {
Expand Down Expand Up @@ -247,7 +247,7 @@ fn test_virtual_manifest_all() {

assert!(&output.status.success());

assert_snapshot!(test_project.file_tree_diff(), @r###"
assert_snapshot!(test_project.file_tree_diff(), @r"
--- Original file tree
+++ Updated file tree
@@ -1,10 +1,15 @@
Expand All @@ -266,7 +266,7 @@ fn test_virtual_manifest_all() {
member-2/src/lib.rs
+ member-2/src/snapshots
+ member-2/src/snapshots/virtual_manifest_all_member_2__member_2.snap
"### );
" );
}

/// Check that in a workspace with a virtual manifest, running `cargo insta test
Expand All @@ -284,7 +284,7 @@ fn test_virtual_manifest_default() {

assert!(&output.status.success());

assert_snapshot!(test_project.file_tree_diff(), @r###"
assert_snapshot!(test_project.file_tree_diff(), @r"
--- Original file tree
+++ Updated file tree
@@ -1,10 +1,15 @@
Expand All @@ -303,7 +303,7 @@ fn test_virtual_manifest_default() {
member-2/src/lib.rs
+ member-2/src/snapshots
+ member-2/src/snapshots/virtual_manifest_default_member_2__member_2.snap
"### );
" );
}

/// Check that in a workspace with a virtual manifest, running `cargo insta test
Expand All @@ -321,7 +321,7 @@ fn test_virtual_manifest_single_crate() {

assert!(&output.status.success());

assert_snapshot!(test_project.file_tree_diff(), @r###"
assert_snapshot!(test_project.file_tree_diff(), @r"
--- Original file tree
+++ Updated file tree
@@ -1,9 +1,12 @@
Expand All @@ -337,7 +337,7 @@ fn test_virtual_manifest_single_crate() {
member-2
member-2/Cargo.toml
member-2/src
"### );
" );
}

use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -943,7 +943,7 @@ fn test_inline() {
assert!(output.status.success());

// Verify inline snapshot
assert_snapshot!(test_project.diff("src/lib.rs"), @r##"
assert_snapshot!(test_project.diff("src/lib.rs"), @r#"
--- Original: src/lib.rs
+++ Updated: src/lib.rs
@@ -10,5 +10,5 @@
Expand All @@ -953,7 +953,7 @@ fn test_inline() {
- insta::assert_snapshot!("This is an inline snapshot for manifest path test", @"");
+ insta::assert_snapshot!("This is an inline snapshot for manifest path test", @"This is an inline snapshot for manifest path test");
}
"##);
"#);
assert_snapshot!(test_project.file_tree_diff(), @r"
--- Original file tree
+++ Updated file tree
Expand Down
14 changes: 7 additions & 7 deletions insta/src/content/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ fn test_to_string() {
(Content::from("cmdline"), Content::Seq(vec![])),
(Content::from("extra"), Content::Map(vec![])),
]));
crate::assert_snapshot!(&json, @r###"{"environments":["development","production"],"cmdline":[],"extra":{}}"###);
crate::assert_snapshot!(&json, @r#"{"environments":["development","production"],"cmdline":[],"extra":{}}"#);
}

#[test]
Expand All @@ -352,7 +352,7 @@ fn test_to_string_pretty() {
(Content::from("cmdline"), Content::Seq(vec![])),
(Content::from("extra"), Content::Map(vec![])),
]));
crate::assert_snapshot!(&json, @r###"
crate::assert_snapshot!(&json, @r#"
{
"environments": [
"development",
Expand All @@ -361,7 +361,7 @@ fn test_to_string_pretty() {
"cmdline": [],
"extra": {}
}
"###);
"#);
}

#[test]
Expand All @@ -371,12 +371,12 @@ fn test_to_string_num_keys() {
(Content::from(-23i32), Content::from(false)),
]);
let json = to_string_pretty(&content);
crate::assert_snapshot!(&json, @r###"
crate::assert_snapshot!(&json, @r#"
{
"42": true,
"-23": false
}
"###);
"#);
}

#[test]
Expand Down Expand Up @@ -466,7 +466,7 @@ fn test_to_string_pretty_complex() {
]);
let json = to_string_pretty(&content);

crate::assert_snapshot!(&json, @r###"
crate::assert_snapshot!(&json, @r##"
{
"is_alive": true,
"newtype_variant": {
Expand Down Expand Up @@ -525,5 +525,5 @@ fn test_to_string_pretty_complex() {
"unit": null,
"crazy_string": "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
}
"###);
"##);
}
8 changes: 4 additions & 4 deletions insta/src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ fn test_yaml_serialization() {
]),
SerializationFormat::Yaml,
);
crate::assert_snapshot!(&yaml, @r###"
crate::assert_snapshot!(&yaml, @r"
env:
- ENVIRONMENT
- production
cmdline:
- my-tool
- run
"###);
");

let inline_yaml = serialize_content(
Content::Map(vec![
Expand All @@ -151,12 +151,12 @@ fn test_yaml_serialization() {
]),
SerializationFormat::Yaml,
);
crate::assert_snapshot!(&inline_yaml, @r###"
crate::assert_snapshot!(&inline_yaml, @r"
env:
- ENVIRONMENT
- production
cmdline:
- my-tool
- run
"###);
");
}
17 changes: 8 additions & 9 deletions insta/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,28 +860,28 @@ fn names_of_path(path: &Path) -> (String, String) {
#[test]
fn test_names_of_path() {
assert_debug_snapshot!(
names_of_path(Path::new("/src/snapshots/insta_tests__tests__name_foo.snap")), @r###"
names_of_path(Path::new("/src/snapshots/insta_tests__tests__name_foo.snap")), @r#"
(
"name_foo",
"insta_tests__tests",
)
"###
"#
);
assert_debug_snapshot!(
names_of_path(Path::new("/src/snapshots/name_foo.snap")), @r###"
names_of_path(Path::new("/src/snapshots/name_foo.snap")), @r#"
(
"name_foo",
"",
)
"###
"#
);
assert_debug_snapshot!(
names_of_path(Path::new("foo/src/snapshots/go1.20.5.snap")), @r###"
names_of_path(Path::new("foo/src/snapshots/go1.20.5.snap")), @r#"
(
"go1.20.5",
"",
)
"###
"#
);
}

Expand Down Expand Up @@ -1282,12 +1282,11 @@ fn test_empty_lines() {
assert_snapshot!(r#"multiline content starting on first line

final line
"#, @r###"
"#, @r"
multiline content starting on first line

final line

"###);
");

assert_snapshot!(r#"
multiline content starting on second line
Expand Down
4 changes: 2 additions & 2 deletions insta/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fn test_format_rust_expression() {
use crate::assert_snapshot;
assert_snapshot!(format_rust_expression("vec![1,2,3]"), @"vec![1, 2, 3]");
assert_snapshot!(format_rust_expression("vec![1,2,3].iter()"), @"vec![1, 2, 3].iter()");
assert_snapshot!(format_rust_expression(r#" "aoeu""#), @r###""aoeu""###);
assert_snapshot!(format_rust_expression(r#" "aoe😄""#), @r###""aoe😄""###);
assert_snapshot!(format_rust_expression(r#" "aoeu""#), @r#""aoeu""#);
assert_snapshot!(format_rust_expression(r#" "aoe😄""#), @r#""aoe😄""#);
assert_snapshot!(format_rust_expression("😄😄😄😄😄"), @"😄😄😄😄😄")
}
2 changes: 1 addition & 1 deletion insta/tests/snapshots/test_redaction__foo_bar.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: insta/tests/test_redaction.rs
expression: "Selector::parse(\".foo.bar\").unwrap()"
expression: "Selector :: parse(\".foo.bar\").unwrap()"
---
Selector {
selectors: [
Expand Down
2 changes: 1 addition & 1 deletion insta/tests/snapshots/test_redaction__foo_bar_alt.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: insta/tests/test_redaction.rs
expression: "Selector::parse(\".foo[\\\"bar\\\"]\").unwrap()"
expression: "Selector :: parse(\".foo[\\\"bar\\\"]\").unwrap()"
---
Selector {
selectors: [
Expand Down
2 changes: 1 addition & 1 deletion insta/tests/snapshots/test_redaction__foo_bar_deep.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: insta/tests/test_redaction.rs
expression: "Selector::parse(\".foo.bar.**\").unwrap()"
expression: "Selector :: parse(\".foo.bar.**\").unwrap()"
---
Selector {
selectors: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: insta/tests/test_redaction.rs
expression: "Selector::parse(\".foo.bar[]\").unwrap()"
expression: "Selector :: parse(\".foo.bar[]\").unwrap()"
---
Selector {
selectors: [
Expand Down
2 changes: 1 addition & 1 deletion insta/tests/snapshots/test_redaction__foo_bar_range.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: insta/tests/test_redaction.rs
expression: "Selector::parse(\".foo.bar[10:20]\").unwrap()"
expression: "Selector :: parse(\".foo.bar[10:20]\").unwrap()"
---
Selector {
selectors: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: insta/tests/test_redaction.rs
expression: "Selector::parse(\".foo.bar[10:]\").unwrap()"
expression: "Selector :: parse(\".foo.bar[10:]\").unwrap()"
---
Selector {
selectors: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: insta/tests/test_redaction.rs
expression: "Selector::parse(\".foo.bar[:10]\").unwrap()"
expression: "Selector :: parse(\".foo.bar[:10]\").unwrap()"
---
Selector {
selectors: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: insta/tests/test_redaction.rs
expression: "&MyPoint { x: 1.0 / 3.0, y: 6.0 / 3.0 }"
expression: "&MyPoint { x: 1.0 / 3.0, y: 6.0 / 3.0, }"
---
{
"x": 0.3333,
Expand Down
2 changes: 1 addition & 1 deletion insta/tests/snapshots/test_redaction__user_json.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: insta/tests/test_redaction.rs
expression: "&User {\n id: 9999,\n username: \"jason_doe\".to_string(),\n email: Email(\"[email protected]\".to_string()),\n extra: \"ssn goes here\".to_string(),\n }"
expression: "&User\n{\n id: 9999, username: \"jason_doe\".to_string(), email:\n Email(\"[email protected]\".to_string()), extra:\n \"ssn goes here\".to_string(),\n}"
---
{
"id": "[id]",
Expand Down
2 changes: 1 addition & 1 deletion insta/tests/snapshots/test_redaction__user_json_flags.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: insta/tests/test_redaction.rs
expression: "&User {\n id: 122,\n username: \"jason_doe\".to_string(),\n flags: vec![\"zzz\".into(), \"foo\".into(), \"aha\".into(),\n \"is_admin\".into()].into_iter().collect(),\n }"
expression: "&User\n{\n id: 122, username: \"jason_doe\".to_string(), flags:\n vec![\"zzz\".into(), \"foo\".into(), \"aha\".into(),\n \"is_admin\".into()].into_iter().collect(),\n}"
---
{
"id": "[id]",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: insta/tests/test_redaction.rs
expression: "&User {\n id: 122,\n username: \"jason_doe\".to_string(),\n flags: MySet(vec![\"zzz\".into(), \"foo\".into(), \"aha\".into(),\n \"is_admin\".into()].into_iter().collect()),\n }"
expression: "&User\n{\n id: 122, username: \"jason_doe\".to_string(), flags:\n MySet(vec![\"zzz\".into(), \"foo\".into(), \"aha\".into(),\n \"is_admin\".into()].into_iter().collect()),\n}"
---
{
"flags": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: insta/tests/test_redaction.rs
expression: "&User {\n id: 122,\n username: \"jason_doe\".to_string(),\n email: Email(\"[email protected]\".to_string()),\n extra: \"ssn goes here\".to_string(),\n }"
expression: "&User\n{\n id: 122, username: \"jason_doe\".to_string(), email:\n Email(\"[email protected]\".to_string()), extra:\n \"ssn goes here\".to_string(),\n}"
---
{
"id": "[id]",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: insta/tests/test_redaction.rs
expression: "&User {\n id: 1234,\n username: \"jason_doe\".to_string(),\n email: Email(\"[email protected]\".to_string()),\n extra: \"extra here\".to_string(),\n }"
expression: "&User\n{\n id: 1234, username: \"jason_doe\".to_string(), email:\n Email(\"[email protected]\".to_string()), extra: \"extra here\".to_string(),\n}"
---
{
"id": "[id]",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: insta/tests/test_redaction.rs
expression: "&User {\n id: 42,\n username: \"john_doe\".to_string(),\n email: Email(\"[email protected]\".to_string()),\n extra: \"\".to_string(),\n }"
expression: "&User\n{\n id: 42, username: \"john_doe\".to_string(), email:\n Email(\"[email protected]\".to_string()), extra: \"\".to_string(),\n}"
---
id: "[id]"
username: john_doe
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: insta/tests/test_redaction.rs
expression: "&User {\n id: 11,\n username: \"john_doe\".to_string(),\n email: Email(\"[email protected]\".to_string()),\n extra: \"\".to_string(),\n }"
expression: "&User\n{\n id: 11, username: \"john_doe\".to_string(), email:\n Email(\"[email protected]\".to_string()), extra: \"\".to_string(),\n}"
---
id: "[id]"
username: john_doe
Expand Down
Loading
Loading