ArrayString: Add PartialEq, Eq, Hash, and tests
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
extern crate arrayvec;
|
||||
|
||||
use arrayvec::ArrayVec;
|
||||
use arrayvec::ArrayString;
|
||||
use std::mem;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_simple() {
|
||||
@@ -260,3 +263,21 @@ fn test_write() {
|
||||
assert_eq!(r, 5);
|
||||
assert_eq!(&v[..], &[1, 2, 3, 9, 9, 9, 9, 9]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_string() {
|
||||
let text = "hello world";
|
||||
let mut s = ArrayString::<[_; 16]>::new();
|
||||
s.push_str(text).unwrap();
|
||||
assert_eq!(&s, text);
|
||||
assert_eq!(text, &s);
|
||||
|
||||
// Make sure Hash / Eq / Borrow match up so we can use HashMap
|
||||
let mut map = HashMap::new();
|
||||
map.insert(s, 1);
|
||||
assert_eq!(map[text], 1);
|
||||
|
||||
let mut t = ArrayString::<[_; 2]>::new();
|
||||
assert!(t.push_str(text).is_err());
|
||||
assert_eq!(&t, "");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user