Add test for nonzero catchall schema versions
This commit is contained in:
parent
805c6cf15e
commit
14fd399403
60
src/lib.rs
60
src/lib.rs
|
@ -524,7 +524,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn catchall_schema() {
|
fn catchall_schema_v0() {
|
||||||
#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)]
|
#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)]
|
||||||
struct Catchall(HashMap<String, String>);
|
struct Catchall(HashMap<String, String>);
|
||||||
impl SchemaV0 for Catchall {}
|
impl SchemaV0 for Catchall {}
|
||||||
|
@ -539,6 +539,64 @@ mod tests {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn catchall_schema_v1_v2() {
|
||||||
|
#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)]
|
||||||
|
struct Catchall0(HashMap<String, String>);
|
||||||
|
impl SchemaV0 for Catchall0 {}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)]
|
||||||
|
struct Catchall1 {
|
||||||
|
count: usize,
|
||||||
|
#[serde(flatten)]
|
||||||
|
data: HashMap<String, String>,
|
||||||
|
}
|
||||||
|
impl Schema for Catchall1 {
|
||||||
|
type Prev = Catchall0;
|
||||||
|
}
|
||||||
|
impl From<Catchall0> for Catchall1 {
|
||||||
|
fn from(old: Catchall0) -> Self {
|
||||||
|
Catchall1 {
|
||||||
|
data: old.0,
|
||||||
|
count: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)]
|
||||||
|
struct Catchall2 {
|
||||||
|
count: usize,
|
||||||
|
name: String,
|
||||||
|
#[serde(flatten)]
|
||||||
|
data: HashMap<String, String>,
|
||||||
|
}
|
||||||
|
impl Schema for Catchall2 {
|
||||||
|
type Prev = Catchall1;
|
||||||
|
}
|
||||||
|
impl From<Catchall1> for Catchall2 {
|
||||||
|
fn from(old: Catchall1) -> Self {
|
||||||
|
Catchall2 {
|
||||||
|
data: old.data,
|
||||||
|
count: old.count,
|
||||||
|
name: String::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut data = HashMap::new();
|
||||||
|
data.insert("hello".into(), "world".into());
|
||||||
|
data.insert("catch".into(), "all".into());
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
Catchall2::parse(r#"{"version":1,"count":42,"hello":"world","catch":"all"}"#).unwrap(),
|
||||||
|
Catchall2 {
|
||||||
|
data,
|
||||||
|
count: 42,
|
||||||
|
name: String::new(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unversioned() {
|
fn unversioned() {
|
||||||
#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)]
|
#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)]
|
||||||
|
|
Loading…
Reference in a new issue