Skip to content

Commit

Permalink
Updated with good test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jaynus committed Mar 15, 2019
1 parent 3c40241 commit fe5bb3d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
12 changes: 6 additions & 6 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 25 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
use bitflags::bitflags;
use option_set::option_set;

option_set! {
pub struct Test: UpperCamel + u8 {

bitflags! {
#[derive(serde::Serialize, serde::Deserialize)]
pub struct TestGood: u8 {
const One = 1;
const Two = 1 << 1;
const Three = 1 << 2;
}
}

option_set! {
pub struct TestBad: UpperCamel + u8 {
const One = 1;
const Two = 1 << 1;
const Three = 1 << 2;
}
}


fn main() {
let flag = Test::One | Test::Two;
let flag_good = TestGood::One | TestGood::Two;

let json_ser_good = serde_json::ser::to_string(&flag_good).unwrap();
let ron_ser_good = ron::ser::to_string(&flag_good).unwrap();

let json_der_good: TestGood = serde_json::de::from_str(json_ser_good.as_str()).unwrap();
let ron_ser_good: TestGood = ron::de::from_str(ron_ser_good.as_str()).unwrap();


let flag_bad = TestBad::One | TestBad::Two;

let json_ser = serde_json::ser::to_string(&flag).unwrap();
let ron_ser = ron::ser::to_string(&flag).unwrap();
let json_ser_bad = serde_json::ser::to_string(&flag_bad).unwrap();
let ron_ser_bad = ron::ser::to_string(&flag_bad).unwrap();

let json_der: Test = serde_json::de::from_str(json_ser.as_str()).unwrap();
let ron_ser: Test = ron::de::from_str(ron_ser.as_str()).unwrap();
let json_der_bad: TestBad = serde_json::de::from_str(json_ser_bad.as_str()).unwrap();
let ron_ser_bad: TestBad = ron::de::from_str(ron_ser_bad.as_str()).unwrap();
}

0 comments on commit fe5bb3d

Please sign in to comment.