-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support tuple/unit and generics in omit macro
- Loading branch information
Showing
2 changed files
with
67 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,72 @@ | ||
#![allow(dead_code)] | ||
use types_rs::omit; | ||
|
||
#[test] | ||
fn in_progress() {} | ||
|
||
#[test] | ||
fn should_pass_omit() { | ||
// omit partial field | ||
{ | ||
mod foo { | ||
mod x { | ||
use super::*; | ||
#[omit(NewFoo, [b])] | ||
pub struct Foo { | ||
#[omit(NewS, [b])] | ||
pub struct S { | ||
pub a: i32, | ||
pub b: &str, | ||
} | ||
} | ||
_ = foo::NewFoo { a: 1 }; | ||
_ = x::NewS { a: 1 }; | ||
} | ||
|
||
// omit all fields | ||
{ | ||
#[omit(NewFoo2, [a, b])] | ||
struct Foo { | ||
#[omit(NewS, [a, b])] | ||
struct S { | ||
a: i32, | ||
b: &str, | ||
} | ||
_ = NewFoo2; | ||
_ = NewS {}; | ||
} | ||
|
||
// skip non-existent field | ||
{ | ||
#[omit(NewFoo3, [c])] | ||
struct Foo { | ||
#[omit(NewS, [c])] | ||
struct S { | ||
a: i32, | ||
b: &'static str, | ||
} | ||
_ = NewFoo3 { a: 1, b: "2" }; | ||
_ = NewS { a: 1, b: "2" }; | ||
} | ||
|
||
// omit unit struct | ||
// omit tuple struct | ||
{ | ||
#[omit(NewPair)] | ||
struct Pair(i32); | ||
_ = NewPair(1); | ||
} | ||
|
||
// omit tuple struct that has no fields | ||
{ | ||
#[omit(NewFoo4)] | ||
struct Foo; | ||
_ = NewFoo4; | ||
struct Pair(); | ||
_ = NewFoo4(); | ||
} | ||
|
||
// omit unit struct | ||
{ | ||
#[omit(NewS)] | ||
struct Unit; | ||
_ = NewS {}; | ||
} | ||
|
||
// TODO: support generics | ||
// omit generic struct | ||
//{ | ||
// #[omit(NewFoo5, [])] | ||
// struct Foo<T> { | ||
// a: T, | ||
// } | ||
// _ = NewFoo5 { a: 1 }; | ||
//} | ||
{ | ||
#[omit(NewS)] | ||
struct S<'a, T> { | ||
a: &'a T, | ||
} | ||
let x = (1, 2, 3); | ||
_ = NewS { a: &x }; | ||
} | ||
} |