Add tests for aliases

failures (2):
    field_identifier::unknown
    variant_identifier::unknown
This commit is contained in:
Mingun 2023-05-19 23:11:06 +05:00
parent bc1960b106
commit 1efb8b6a53

View File

@ -12,6 +12,7 @@ mod variant_identifier {
#[serde(variant_identifier)] #[serde(variant_identifier)]
enum V { enum V {
Aaa, Aaa,
#[serde(alias = "Ccc", alias = "Ddd")]
Bbb, Bbb,
} }
@ -25,6 +26,23 @@ mod variant_identifier {
assert_de_tokens(&V::Aaa, &[Token::Bytes(b"Aaa")]); assert_de_tokens(&V::Aaa, &[Token::Bytes(b"Aaa")]);
} }
#[test]
fn aliases() {
assert_de_tokens(&V::Bbb, &[Token::U8(1)]);
assert_de_tokens(&V::Bbb, &[Token::U16(1)]);
assert_de_tokens(&V::Bbb, &[Token::U32(1)]);
assert_de_tokens(&V::Bbb, &[Token::U64(1)]);
assert_de_tokens(&V::Bbb, &[Token::Str("Bbb")]);
assert_de_tokens(&V::Bbb, &[Token::Bytes(b"Bbb")]);
assert_de_tokens(&V::Bbb, &[Token::Str("Ccc")]);
assert_de_tokens(&V::Bbb, &[Token::Bytes(b"Ccc")]);
assert_de_tokens(&V::Bbb, &[Token::Str("Ddd")]);
assert_de_tokens(&V::Bbb, &[Token::Bytes(b"Ddd")]);
}
#[test] #[test]
fn unknown() { fn unknown() {
assert_de_tokens_error::<V>( assert_de_tokens_error::<V>(
@ -45,11 +63,11 @@ mod variant_identifier {
); );
assert_de_tokens_error::<V>( assert_de_tokens_error::<V>(
&[Token::Str("Unknown")], &[Token::Str("Unknown")],
"unknown variant `Unknown`, expected `Aaa` or `Bbb`", "unknown variant `Unknown`, expected one of `Aaa`, `Bbb`, `Ccc`, `Ddd`",
); );
assert_de_tokens_error::<V>( assert_de_tokens_error::<V>(
&[Token::Bytes(b"Unknown")], &[Token::Bytes(b"Unknown")],
"unknown variant `Unknown`, expected `Aaa` or `Bbb`", "unknown variant `Unknown`, expected one of `Aaa`, `Bbb`, `Ccc`, `Ddd`",
); );
} }
} }
@ -61,6 +79,7 @@ mod field_identifier {
#[serde(field_identifier, rename_all = "snake_case")] #[serde(field_identifier, rename_all = "snake_case")]
enum F { enum F {
Aaa, Aaa,
#[serde(alias = "ccc", alias = "ddd")]
Bbb, Bbb,
} }
@ -74,6 +93,23 @@ mod field_identifier {
assert_de_tokens(&F::Aaa, &[Token::Bytes(b"aaa")]); assert_de_tokens(&F::Aaa, &[Token::Bytes(b"aaa")]);
} }
#[test]
fn aliases() {
assert_de_tokens(&F::Bbb, &[Token::U8(1)]);
assert_de_tokens(&F::Bbb, &[Token::U16(1)]);
assert_de_tokens(&F::Bbb, &[Token::U32(1)]);
assert_de_tokens(&F::Bbb, &[Token::U64(1)]);
assert_de_tokens(&F::Bbb, &[Token::Str("bbb")]);
assert_de_tokens(&F::Bbb, &[Token::Bytes(b"bbb")]);
assert_de_tokens(&F::Bbb, &[Token::Str("ccc")]);
assert_de_tokens(&F::Bbb, &[Token::Bytes(b"ccc")]);
assert_de_tokens(&F::Bbb, &[Token::Str("ddd")]);
assert_de_tokens(&F::Bbb, &[Token::Bytes(b"ddd")]);
}
#[test] #[test]
fn unknown() { fn unknown() {
assert_de_tokens_error::<F>( assert_de_tokens_error::<F>(
@ -94,11 +130,11 @@ mod field_identifier {
); );
assert_de_tokens_error::<F>( assert_de_tokens_error::<F>(
&[Token::Str("unknown")], &[Token::Str("unknown")],
"unknown field `unknown`, expected `aaa` or `bbb`", "unknown field `unknown`, expected one of `aaa`, `bbb`, `ccc`, `ddd`",
); );
assert_de_tokens_error::<F>( assert_de_tokens_error::<F>(
&[Token::Bytes(b"unknown")], &[Token::Bytes(b"unknown")],
"unknown field `unknown`, expected `aaa` or `bbb`", "unknown field `unknown`, expected one of `aaa`, `bbb`, `ccc`, `ddd`",
); );
} }