This repository has been archived by the owner on Sep 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Spanned: impl PartialEq, Eq, Hash, PartialOrd, Ord in terms of the v…
…alue (#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
- Loading branch information
1 parent
9ed2903
commit 8995cef
Showing
2 changed files
with
77 additions
and
1 deletion.
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 |
---|---|---|
@@ -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)); | ||
} |