-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Relax enum default case expansion rules
- Loading branch information
1 parent
36ffba2
commit 11738d4
Showing
5 changed files
with
113 additions
and
10 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 |
---|---|---|
|
@@ -15,5 +15,6 @@ anyhow = "1.0.86" | |
test-case = "3" | ||
|
||
[features] | ||
default = ["syn1"] | ||
syn1 = ["o2o/syn1"] | ||
syn2 = ["o2o/syn2"] |
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,53 @@ | ||
use test_case::test_case; | ||
|
||
#[derive(Debug, PartialEq, Clone)] | ||
pub enum Enum { | ||
Opt1, | ||
Opt2, | ||
Opt3 | ||
} | ||
|
||
#[derive(Debug, PartialEq, o2o::o2o)] | ||
#[map_owned(Enum| _ => todo!("unknown"))] | ||
enum EnumDto { | ||
Opt1, | ||
Opt2, | ||
} | ||
|
||
#[derive(Debug, PartialEq, Clone)] | ||
pub enum Enum2 { | ||
Opt1, | ||
Opt2, | ||
Opt3 | ||
} | ||
|
||
#[derive(Debug, PartialEq, o2o::o2o)] | ||
#[from_owned(Enum2| _ => EnumDto2::Opt1)] | ||
enum EnumDto2 { | ||
Opt1, | ||
Opt2, | ||
} | ||
|
||
#[test_case(Enum::Opt1, EnumDto::Opt1)] | ||
#[test_case(Enum::Opt2, EnumDto::Opt2)] | ||
fn legit_options(l: Enum, r: EnumDto) { | ||
let e: EnumDto = l.clone().into(); | ||
assert_eq!(r, e); | ||
|
||
let e: Enum = r.into(); | ||
assert_eq!(l, e); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "unknown")] | ||
fn default_case() { | ||
let _: EnumDto = Enum::Opt3.into(); | ||
} | ||
|
||
#[test_case(Enum2::Opt1, EnumDto2::Opt1)] | ||
#[test_case(Enum2::Opt2, EnumDto2::Opt2)] | ||
#[test_case(Enum2::Opt3, EnumDto2::Opt1)] | ||
fn legit_options_2(l: Enum2, r: EnumDto2) { | ||
let e: EnumDto2 = l.clone().into(); | ||
assert_eq!(r, e); | ||
} |
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,53 @@ | ||
use test_case::test_case; | ||
|
||
#[derive(Debug, PartialEq, Clone)] | ||
pub enum Enum { | ||
Opt1, | ||
Opt2, | ||
Opt3 | ||
} | ||
|
||
#[derive(Debug, PartialEq, o2o::o2o)] | ||
#[try_map_owned(Enum, String| _ => todo!("unknown"))] | ||
enum EnumDto { | ||
Opt1, | ||
Opt2, | ||
} | ||
|
||
#[derive(Debug, PartialEq, Clone)] | ||
pub enum Enum2 { | ||
Opt1, | ||
Opt2, | ||
Opt3 | ||
} | ||
|
||
#[derive(Debug, PartialEq, o2o::o2o)] | ||
#[try_from_owned(Enum2, String| _ => EnumDto2::Opt1)] | ||
enum EnumDto2 { | ||
Opt1, | ||
Opt2, | ||
} | ||
|
||
#[test_case(Enum::Opt1, EnumDto::Opt1)] | ||
#[test_case(Enum::Opt2, EnumDto::Opt2)] | ||
fn legit_options(l: Enum, r: EnumDto) { | ||
let e: EnumDto = l.clone().try_into().unwrap(); | ||
assert_eq!(r, e); | ||
|
||
let e: Enum = r.try_into().unwrap(); | ||
assert_eq!(l, e); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "unknown")] | ||
fn default_case() { | ||
let _: EnumDto = Enum::Opt3.try_into().unwrap(); | ||
} | ||
|
||
#[test_case(Enum2::Opt1, EnumDto2::Opt1)] | ||
#[test_case(Enum2::Opt2, EnumDto2::Opt2)] | ||
#[test_case(Enum2::Opt3, EnumDto2::Opt1)] | ||
fn legit_options_2(l: Enum2, r: EnumDto2) { | ||
let e: EnumDto2 = l.clone().try_into().unwrap(); | ||
assert_eq!(r, e); | ||
} |
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,7 +1,7 @@ | ||
cargo test -q -p o2o | ||
cargo test -q -p o2o --no-default-features --features syn1 | ||
cargo test -q -p o2o --no-default-features --features syn2 | ||
cargo test -q -p o2o-tests --features syn1 | ||
cargo test -q -p o2o-tests --features syn2 | ||
cargo test -q -p o2o-tests --no-default-features --features syn1 | ||
cargo test -q -p o2o-tests --no-default-features --features syn2 | ||
cargo test -q -p o2o-impl --features syn | ||
cargo test -q -p o2o-impl --features syn2 |