Implement derive macros expansion tests using macrotest

This commit is contained in:
Evgenii P 2019-11-01 02:32:06 +08:00
parent 2ceabad360
commit dc6dbba47c
13 changed files with 112 additions and 0 deletions

View File

@ -18,3 +18,4 @@ serde = { path = "../serde", features = ["rc", "derive"] }
serde_derive = { path = "../serde_derive", features = ["deserialize_in_place"] }
serde_test = { path = "../serde_test" }
trybuild = "1.0"
macrotest = "0.1"

View File

@ -0,0 +1,13 @@
use serde::Deserialize;
#[derive(Debug, PartialEq, Serialize, Deserialize)]
enum DeEnum<B, C, D> {
Unit,
Seq(i8, B, C, D),
Map { a: i8, b: B, c: C, d: D },
// Make sure we can support more than one variant.
_Unit2,
_Seq2(i8, B, C, D),
_Map2 { a: i8, b: B, c: C, d: D },
}

View File

@ -0,0 +1,9 @@
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
pub enum GenericEnum<T, U> {
Unit,
NewType(T),
Seq(T, U),
Map { x: T, y: U },
}

View File

@ -0,0 +1,9 @@
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
enum Lifetimes<'a> {
LifetimeSeq(&'a i32),
NoLifetimeSeq(i32),
LifetimeMap { a: &'a i32 },
NoLifetimeMap { a: i32 },
}

View File

@ -0,0 +1,16 @@
use serde::Serialize;
#[derive(Serialize)]
enum SerEnum<'a, B: 'a, C: 'a, D>
where
D: 'a,
{
Unit,
Seq(i8, B, &'a C, &'a mut D),
Map { a: i8, b: B, c: &'a C, d: &'a mut D },
// Make sure we can support more than one variant.
_Unit2,
_Seq2(i8, B, &'a C, &'a mut D),
_Map2 { a: i8, b: B, c: &'a C, d: &'a mut D },
}

View File

@ -0,0 +1,4 @@
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
enum Void {}

View File

@ -0,0 +1,14 @@
use serde::{Serialize, Deserialize};
trait AssociatedType {
type X;
}
impl AssociatedType for i32 {
type X = i32;
}
#[derive(Serialize, Deserialize)]
struct DefaultTyParam<T: AssociatedType<X = i32> = i32> {
phantom: PhantomData<T>,
}

View File

@ -0,0 +1,9 @@
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
pub struct GenericStruct<T> {
x: T,
}
#[derive(Serialize, Deserialize)]
pub struct GenericNewTypeStruct<T>(T);

View File

@ -0,0 +1,4 @@
use serde::{Serialize, Deserialize};
#[derive(Deserialize)]
pub struct GenericTupleStruct<T, U>(T, U);

View File

@ -0,0 +1,15 @@
use serde::{Serialize, Deserialize};
#[derive(Serialize)]
struct SerNamedMap<'a, 'b, A: 'a, B: 'b, C> {
a: &'a A,
b: &'b mut B,
c: C,
}
#[derive(Deserialize)]
struct DeNamedMap<A, B, C> {
a: A,
b: B,
c: C,
}

View File

@ -0,0 +1,7 @@
use serde::{Serialize, Deserialize};
#[derive(Serialize)]
struct SerNamedTuple<'a, 'b, A: 'a, B: 'b, C>(&'a A, &'b mut B, C);
#[derive(Deserialize)]
struct DeNamedTuple<A, B, C>(A, B, C);

View File

@ -0,0 +1,4 @@
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
struct NamedUnit;

View File

@ -0,0 +1,7 @@
#[cfg(not(target_os = "emscripten"))]
#[rustversion::attr(not(nightly), ignore)]
#[test]
fn expandtest() {
macrotest::expand("tests/expand/**/enum/*.rs");
macrotest::expand("tests/expand/**/struct/*.rs");
}