-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow trailing commas in inline snapshots (#472)
- Loading branch information
Showing
10 changed files
with
147 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
--- | ||
source: src/main.rs | ||
source: cargo-insta/tests/main.rs | ||
expression: "&fs::read_to_string(gen_file).unwrap()" | ||
input_file: tests/test_json_inline.rs | ||
--- | ||
use serde::Serialize; | ||
|
||
|
@@ -27,3 +26,34 @@ fn test_json_snapshot() { | |
"###); | ||
} | ||
|
||
#[test] | ||
fn test_json_snapshot_trailing_comma() { | ||
let user = User { | ||
id: 42, | ||
email: "[email protected]".into(), | ||
}; | ||
insta::assert_compact_json_snapshot!( | ||
&user, | ||
@r###"{"id": 42, "email": "john.doe@example.com"}"###, | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_json_snapshot_trailing_comma_redaction() { | ||
let user = User { | ||
id: 42, | ||
email: "[email protected]".into(), | ||
}; | ||
insta::assert_json_snapshot!( | ||
&user, | ||
{ | ||
".id" => "[user_id]", | ||
}, | ||
@r###" | ||
{ | ||
"id": "[user_id]", | ||
"email": "[email protected]" | ||
} | ||
"###, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
--- | ||
source: src/main.rs | ||
source: cargo-insta/tests/main.rs | ||
expression: "&fs::read_to_string(gen_file).unwrap()" | ||
input_file: tests/test_yaml_inline.rs | ||
--- | ||
use serde::Serialize; | ||
|
||
|
@@ -26,3 +25,21 @@ fn test_yaml_snapshot() { | |
"###); | ||
} | ||
|
||
#[test] | ||
fn test_yaml_snapshot_trailing_comma() { | ||
let user = User { | ||
id: 42, | ||
email: "[email protected]".into(), | ||
}; | ||
insta::assert_yaml_snapshot!( | ||
&user, | ||
{ | ||
".id" => "[user_id]", | ||
}, | ||
@r###" | ||
--- | ||
id: "[user_id]" | ||
email: john.doe@example.com | ||
"###, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,30 @@ fn test_json_snapshot() { | |
".id" => "[user_id]", | ||
}, @""); | ||
} | ||
|
||
#[test] | ||
fn test_json_snapshot_trailing_comma() { | ||
let user = User { | ||
id: 42, | ||
email: "[email protected]".into(), | ||
}; | ||
insta::assert_compact_json_snapshot!( | ||
&user, | ||
@"", | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_json_snapshot_trailing_comma_redaction() { | ||
let user = User { | ||
id: 42, | ||
email: "[email protected]".into(), | ||
}; | ||
insta::assert_json_snapshot!( | ||
&user, | ||
{ | ||
".id" => "[user_id]", | ||
}, | ||
@"", | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,18 @@ fn test_yaml_snapshot() { | |
".id" => "[user_id]", | ||
}, @""); | ||
} | ||
|
||
#[test] | ||
fn test_yaml_snapshot_trailing_comma() { | ||
let user = User { | ||
id: 42, | ||
email: "[email protected]".into(), | ||
}; | ||
insta::assert_yaml_snapshot!( | ||
&user, | ||
{ | ||
".id" => "[user_id]", | ||
}, | ||
@"", | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,6 +111,24 @@ fn test_with_random_value_and_match_comma() { | |
".id" => "[id]", | ||
}, // comma here | ||
); | ||
assert_yaml_snapshot!( | ||
&User { | ||
id: 11, | ||
username: "john_doe".to_string(), | ||
email: Email("[email protected]".to_string()), | ||
extra: "".to_string(), | ||
}, | ||
match .. { | ||
".id" => "[id]", | ||
}, | ||
@r###" | ||
--- | ||
id: "[id]" | ||
username: john_doe | ||
email: [email protected] | ||
extra: "" | ||
"###, // comma here | ||
); | ||
} | ||
|
||
#[cfg(feature = "csv")] | ||
|