Run cargo fmt, minor code cleanup
This commit is contained in:
1 parent
4317afa003
commit
f9a9db2e9a
8 files changed
+420
-268
No files matched your search
@@ -1,17 +1,12 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use enumscribe::{
|
||||
ScribeCowStr,
|
||||
ScribeStaticStr,
|
||||
ScribeString,
|
||||
TryScribeCowStr,
|
||||
TryScribeStaticStr,
|
||||
ScribeCowStr, ScribeStaticStr, ScribeString, TryScribeCowStr, TryScribeStaticStr,
|
||||
TryScribeString,
|
||||
};
|
||||
|
||||
const TEST_STRINGS: [&'static str; 6] = [
|
||||
"", "\0", "foo", "baa", "Hello, world!", "こんにちは、世界"
|
||||
];
|
||||
const TEST_STRINGS: [&'static str; 6] =
|
||||
["", "\0", "foo", "baa", "Hello, world!", "こんにちは、世界"];
|
||||
|
||||
#[test]
|
||||
fn test_scribe_static_str() {
|
||||
@@ -54,7 +49,10 @@ fn test_try_scribe_static_str() {
|
||||
#[enumscribe(ignore)]
|
||||
V7(i32, i32),
|
||||
#[enumscribe(ignore)]
|
||||
V8 { s: &'static str, x: i32 },
|
||||
V8 {
|
||||
s: &'static str,
|
||||
x: i32,
|
||||
},
|
||||
}
|
||||
|
||||
assert_eq!(E0::V0.try_scribe(), Some("V0"));
|
||||
@@ -65,7 +63,14 @@ fn test_try_scribe_static_str() {
|
||||
assert_eq!(E0::V5 {}.try_scribe(), Some("baz"));
|
||||
assert_eq!(E0::V6.try_scribe(), None);
|
||||
assert_eq!(E0::V7(123, 456).try_scribe(), None);
|
||||
assert_eq!(E0::V8 { s: "lorem ipsum", x: 246 }.try_scribe(), None);
|
||||
assert_eq!(
|
||||
E0::V8 {
|
||||
s: "lorem ipsum",
|
||||
x: 246
|
||||
}
|
||||
.try_scribe(),
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -135,7 +140,10 @@ fn test_try_scribe_string() {
|
||||
#[enumscribe(ignore)]
|
||||
V7(i32, i32),
|
||||
#[enumscribe(ignore)]
|
||||
V8 { s: &'static str, x: i32 },
|
||||
V8 {
|
||||
s: &'static str,
|
||||
x: i32,
|
||||
},
|
||||
}
|
||||
|
||||
assert_eq!(E0::V0.try_scribe(), Some("V0".to_owned()));
|
||||
@@ -146,7 +154,14 @@ fn test_try_scribe_string() {
|
||||
assert_eq!(E0::V5 {}.try_scribe(), Some("baz".to_owned()));
|
||||
assert_eq!(E0::V6.try_scribe(), None);
|
||||
assert_eq!(E0::V7(123, 456).try_scribe(), None);
|
||||
assert_eq!(E0::V8 { s: "lorem ipsum", x: 246 }.try_scribe(), None);
|
||||
assert_eq!(
|
||||
E0::V8 {
|
||||
s: "lorem ipsum",
|
||||
x: 246
|
||||
}
|
||||
.try_scribe(),
|
||||
None
|
||||
);
|
||||
|
||||
#[derive(TryScribeString, Eq, PartialEq, Debug)]
|
||||
enum E1 {
|
||||
@@ -213,7 +228,10 @@ fn test_scribe_cow_str() {
|
||||
|
||||
assert_eq!(E1::V0.scribe(), Cow::Borrowed("foo"));
|
||||
for &x in &TEST_STRINGS {
|
||||
assert_eq!(E1::V1(x.to_owned()).scribe(), Cow::Owned::<'static, str>(x.to_owned()));
|
||||
assert_eq!(
|
||||
E1::V1(x.to_owned()).scribe(),
|
||||
Cow::Owned::<'static, str>(x.to_owned())
|
||||
);
|
||||
}
|
||||
|
||||
#[derive(ScribeCowStr, Eq, PartialEq, Debug)]
|
||||
@@ -226,7 +244,10 @@ fn test_scribe_cow_str() {
|
||||
|
||||
assert_eq!(E2::V0.scribe(), "foo".to_owned());
|
||||
for &x in &TEST_STRINGS {
|
||||
assert_eq!(E2::V1 { s: x.to_owned() }.scribe(), Cow::Owned::<'static, str>(x.to_owned()));
|
||||
assert_eq!(
|
||||
E2::V1 { s: x.to_owned() }.scribe(),
|
||||
Cow::Owned::<'static, str>(x.to_owned())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,7 +269,10 @@ fn test_try_scribe_cow_str() {
|
||||
#[enumscribe(ignore)]
|
||||
V7(i32, i32),
|
||||
#[enumscribe(ignore)]
|
||||
V8 { s: &'static str, x: i32 },
|
||||
V8 {
|
||||
s: &'static str,
|
||||
x: i32,
|
||||
},
|
||||
}
|
||||
|
||||
assert_eq!(E0::V0.try_scribe(), Some(Cow::Borrowed("V0")));
|
||||
@@ -259,7 +283,14 @@ fn test_try_scribe_cow_str() {
|
||||
assert_eq!(E0::V5 {}.try_scribe(), Some(Cow::Borrowed("baz")));
|
||||
assert_eq!(E0::V6.try_scribe(), None);
|
||||
assert_eq!(E0::V7(123, 456).try_scribe(), None);
|
||||
assert_eq!(E0::V8 { s: "lorem ipsum", x: 246 }.try_scribe(), None);
|
||||
assert_eq!(
|
||||
E0::V8 {
|
||||
s: "lorem ipsum",
|
||||
x: 246
|
||||
}
|
||||
.try_scribe(),
|
||||
None
|
||||
);
|
||||
|
||||
#[derive(TryScribeCowStr, Eq, PartialEq, Debug)]
|
||||
enum E1 {
|
||||
@@ -273,7 +304,10 @@ fn test_try_scribe_cow_str() {
|
||||
|
||||
assert_eq!(E1::V0.try_scribe(), Some(Cow::Borrowed("foo")));
|
||||
for &x in &TEST_STRINGS {
|
||||
assert_eq!(E1::V1(x.to_owned()).try_scribe(), Some(Cow::Owned::<'static, str>(x.to_owned())));
|
||||
assert_eq!(
|
||||
E1::V1(x.to_owned()).try_scribe(),
|
||||
Some(Cow::Owned::<'static, str>(x.to_owned()))
|
||||
);
|
||||
}
|
||||
assert_eq!(E1::V2.try_scribe(), None);
|
||||
|
||||
@@ -289,7 +323,10 @@ fn test_try_scribe_cow_str() {
|
||||
|
||||
assert_eq!(E2::V0.try_scribe(), Some(Cow::Borrowed("foo")));
|
||||
for &x in &TEST_STRINGS {
|
||||
assert_eq!(E2::V1 { s: x.to_owned() }.try_scribe(), Some(Cow::Owned::<'static, str>(x.to_owned())));
|
||||
assert_eq!(
|
||||
E2::V1 { s: x.to_owned() }.try_scribe(),
|
||||
Some(Cow::Owned::<'static, str>(x.to_owned()))
|
||||
);
|
||||
}
|
||||
assert_eq!(E2::V2.try_scribe(), None);
|
||||
}
|
||||
@@ -279,24 +279,42 @@ fn test_try_unscribe() {
|
||||
assert_eq!(E1::try_unscribe("loREM"), Some(E1::V7));
|
||||
assert_eq!(E1::try_unscribe("larem"), Some(E1::V12("larem".to_owned())));
|
||||
assert_eq!(E1::try_unscribe("lore"), Some(E1::V12("lore".to_owned())));
|
||||
assert_eq!(E1::try_unscribe("llorem"), Some(E1::V12("llorem".to_owned())));
|
||||
assert_eq!(E1::try_unscribe("loremm"), Some(E1::V12("loremm".to_owned())));
|
||||
assert_eq!(
|
||||
E1::try_unscribe("llorem"),
|
||||
Some(E1::V12("llorem".to_owned()))
|
||||
);
|
||||
assert_eq!(
|
||||
E1::try_unscribe("loremm"),
|
||||
Some(E1::V12("loremm".to_owned()))
|
||||
);
|
||||
assert_eq!(E1::try_unscribe("ipsum"), Some(E1::V9()));
|
||||
assert_eq!(E1::try_unscribe("IPSUM"), Some(E1::V9()));
|
||||
assert_eq!(E1::try_unscribe("IpSuM"), Some(E1::V9()));
|
||||
assert_eq!(E1::try_unscribe("ipSUM"), Some(E1::V9()));
|
||||
assert_eq!(E1::try_unscribe("ipdum"), Some(E1::V12("ipdum".to_owned())));
|
||||
assert_eq!(E1::try_unscribe("ipsu"), Some(E1::V12("ipsu".to_owned())));
|
||||
assert_eq!(E1::try_unscribe("iipsum"), Some(E1::V12("iipsum".to_owned())));
|
||||
assert_eq!(E1::try_unscribe("ipsumm"), Some(E1::V12("ipsumm".to_owned())));
|
||||
assert_eq!(
|
||||
E1::try_unscribe("iipsum"),
|
||||
Some(E1::V12("iipsum".to_owned()))
|
||||
);
|
||||
assert_eq!(
|
||||
E1::try_unscribe("ipsumm"),
|
||||
Some(E1::V12("ipsumm".to_owned()))
|
||||
);
|
||||
assert_eq!(E1::try_unscribe("dolor"), Some(E1::V11 {}));
|
||||
assert_eq!(E1::try_unscribe("DOLOR"), Some(E1::V11 {}));
|
||||
assert_eq!(E1::try_unscribe("DoLoR"), Some(E1::V11 {}));
|
||||
assert_eq!(E1::try_unscribe("doLOR"), Some(E1::V11 {}));
|
||||
assert_eq!(E1::try_unscribe("doler"), Some(E1::V12("doler".to_owned())));
|
||||
assert_eq!(E1::try_unscribe("dolo"), Some(E1::V12("dolo".to_owned())));
|
||||
assert_eq!(E1::try_unscribe("ddolor"), Some(E1::V12("ddolor".to_owned())));
|
||||
assert_eq!(E1::try_unscribe("dolorr"), Some(E1::V12("dolorr".to_owned())));
|
||||
assert_eq!(
|
||||
E1::try_unscribe("ddolor"),
|
||||
Some(E1::V12("ddolor".to_owned()))
|
||||
);
|
||||
assert_eq!(
|
||||
E1::try_unscribe("dolorr"),
|
||||
Some(E1::V12("dolorr".to_owned()))
|
||||
);
|
||||
assert_eq!(E1::try_unscribe(""), Some(E1::V12("".to_owned())));
|
||||
assert_eq!(E1::try_unscribe("\0"), Some(E1::V12("\0".to_owned())));
|
||||
}
|
||||
Reference in new issue
Block a user