-
-
Notifications
You must be signed in to change notification settings - Fork 795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move Token De/Serializer to serde_test crate #412
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fb0e629
Rename serde_tests to testing
dtolnay 6d64104
Factor the Token De/Serializer into serde_test
dtolnay 093201a
Assert tokens are empty after reaching error
dtolnay 00f9429
Add message to CustomError
dtolnay cfc2f9a
Remove Error from name of Error variants
dtolnay d6a462b
Add serde_test to dev dependencies of serde_macros
dtolnay 8e87926
Round out the Error variants
dtolnay 7d09053
Fix declare_ser_tests to work on old rustc
dtolnay 041d5c0
Make serde_test asserts more consistent
dtolnay 10b1508
Sync serde_test version with the other crates
dtolnay f531be1
Turn comments into doc comments
dtolnay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "serde_test" | ||
version = "0.1.0" | ||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"] | ||
license = "MIT/Apache-2.0" | ||
description = "Token De/Serializer for testing De/Serialize implementations" | ||
repository = "https://github.com/serde-rs/serde" | ||
documentation = "https://serde-rs.github.io/serde/serde/" | ||
readme = "../README.md" | ||
keywords = ["serde", "serialization"] | ||
include = ["Cargo.toml", "src/**/*.rs"] | ||
|
||
[dependencies] | ||
serde = { version = "0.7.11", path = "../serde" } |
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use serde::{Serialize, Deserialize}; | ||
|
||
use de::Deserializer; | ||
use error::Error; | ||
use ser::Serializer; | ||
use token::Token; | ||
|
||
use std::fmt::Debug; | ||
|
||
pub fn assert_tokens<T>(value: &T, tokens: Vec<Token<'static>>) | ||
where T: Serialize + Deserialize + PartialEq + Debug, | ||
{ | ||
assert_ser_tokens(value, &tokens[..]); | ||
assert_de_tokens(value, tokens); | ||
} | ||
|
||
pub fn assert_ser_tokens<T>(value: &T, tokens: &[Token]) | ||
where T: Serialize, | ||
{ | ||
let mut ser = Serializer::new(tokens.iter()); | ||
assert_eq!(Serialize::serialize(value, &mut ser), Ok(())); | ||
assert_eq!(ser.next_token(), None); | ||
} | ||
|
||
// Expect an error deserializing tokens into a T | ||
pub fn assert_ser_tokens_error<T>(value: &T, tokens: &[Token], error: Error) | ||
where T: Serialize + PartialEq + Debug, | ||
{ | ||
let mut ser = Serializer::new(tokens.iter()); | ||
let v: Result<(), Error> = Serialize::serialize(value, &mut ser); | ||
assert_eq!(v.as_ref(), Err(&error)); | ||
} | ||
|
||
pub fn assert_de_tokens<T>(value: &T, tokens: Vec<Token<'static>>) | ||
where T: Deserialize + PartialEq + Debug, | ||
{ | ||
let mut de = Deserializer::new(tokens.into_iter()); | ||
let v: Result<T, Error> = Deserialize::deserialize(&mut de); | ||
assert_eq!(v.as_ref(), Ok(value)); | ||
assert_eq!(de.next_token(), None); | ||
} | ||
|
||
// Expect an error deserializing tokens into a T | ||
pub fn assert_de_tokens_error<T>(tokens: Vec<Token<'static>>, error: Error) | ||
where T: Deserialize + PartialEq + Debug, | ||
{ | ||
let mut de = Deserializer::new(tokens.into_iter()); | ||
let v: Result<T, Error> = Deserialize::deserialize(&mut de); | ||
assert_eq!(v, Err(error)); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since people are actually meant to use this crate, maybe we should sync versions with serde. Otherwise this becomes a piston-like mess
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. Done.