-
Notifications
You must be signed in to change notification settings - Fork 0
/
the_test.rs
71 lines (64 loc) · 1.71 KB
/
the_test.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use iterable::Iterable;
use iterable_trait::Iterable;
use std::any::TypeId;
#[derive(Iterable)]
pub struct Book {
id: u64,
title: String,
pages: u64,
author: String,
}
#[test]
fn check_field_types() {
let b = Book {
id: 1728,
title: "My Story".to_string(),
pages: 121,
author: "Jms Dnns".to_string(),
};
let mut bi = b.iter();
if let Some((_, value)) = bi.next() {
assert_eq!(value.type_id(), TypeId::of::<u64>());
}
if let Some((_, value)) = bi.next() {
assert_eq!(value.type_id(), TypeId::of::<String>());
}
if let Some((_, value)) = bi.next() {
assert_eq!(value.type_id(), TypeId::of::<u64>());
}
if let Some((_, value)) = bi.next() {
assert_eq!(value.type_id(), TypeId::of::<String>());
}
}
#[test]
fn check_field_names_and_values() {
let b = Book {
id: 1728,
title: "My Story".to_string(),
pages: 121,
author: "Jms Dnns".to_string(),
};
let mut bi = b.iter();
if let Some((name, value)) = bi.next() {
assert_eq!(name, "id");
assert_eq!(value.downcast_ref::<u64>().unwrap(), &1728);
}
if let Some((name, value)) = bi.next() {
assert_eq!(name, "title");
assert_eq!(
value.downcast_ref::<String>().unwrap(),
&"My Story".to_string()
);
}
if let Some((name, value)) = bi.next() {
assert_eq!(name, "pages");
assert_eq!(value.downcast_ref::<u64>().unwrap(), &121);
}
if let Some((name, value)) = bi.next() {
assert_eq!(name, "author");
assert_eq!(
value.downcast_ref::<String>().unwrap(),
&"Jms Dnns".to_string()
);
}
}