diff options
author | est31 <est31@users.noreply.github.com> | 2019-10-25 21:05:31 +0200 |
---|---|---|
committer | Alex Crichton <alex@alexcrichton.com> | 2019-10-25 14:05:31 -0500 |
commit | 8995cef9d6c347c275ea6bbbe0c45523df1b1314 (patch) | |
tree | 7cf48ffd82b44b4ff089ce2c4b74eccaa9c0fbfd /test-suite/tests | |
parent | 9ed2903517fe1e63e70fb2138a22296aa434da9e (diff) | |
download | milf-rs-8995cef9d6c347c275ea6bbbe0c45523df1b1314.tar.gz milf-rs-8995cef9d6c347c275ea6bbbe0c45523df1b1314.zip |
Spanned: impl PartialEq, Eq, Hash, PartialOrd, Ord in terms of the value (#344)
* Spanned: impl PartialEq, Eq, Hash, PartialOrd, Ord in terms of the value
This is because we want to be able to index into HashMap<Spanned<String>, T>
with a dummy span and get results where only the content has to match.
* Add Borrow impl
* Add tests
Diffstat (limited to 'test-suite/tests')
-rw-r--r-- | test-suite/tests/spanned-impls.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test-suite/tests/spanned-impls.rs b/test-suite/tests/spanned-impls.rs new file mode 100644 index 0000000..cb12b1a --- /dev/null +++ b/test-suite/tests/spanned-impls.rs @@ -0,0 +1,41 @@ +use std::cmp::{Ord, Ordering, PartialOrd}; +use toml::{from_str, Spanned}; +#[macro_use] +extern crate serde_derive; + +#[test] +fn test_spans_impls() { + #[derive(Deserialize)] + struct Foo { + bar: Spanned<bool>, + baz: Spanned<String>, + } + let f: Foo = from_str( + " + bar = true + baz = \"yes\" + ", + ) + .unwrap(); + let g: Foo = from_str( + " + baz = \"yes\" + bar = true + ", + ) + .unwrap(); + assert!(f.bar.span() != g.bar.span()); + assert!(f.baz.span() != g.baz.span()); + + // test that eq still holds + assert_eq!(f.bar, g.bar); + assert_eq!(f.baz, g.baz); + + // test that Ord returns equal order + assert_eq!(f.bar.cmp(&g.bar), Ordering::Equal); + assert_eq!(f.baz.cmp(&g.baz), Ordering::Equal); + + // test that PartialOrd returns equal order + assert_eq!(f.bar.partial_cmp(&g.bar), Some(Ordering::Equal)); + assert_eq!(f.baz.partial_cmp(&g.baz), Some(Ordering::Equal)); +} |