-
Notifications
You must be signed in to change notification settings - Fork 367
/
test_map_simple.rs
73 lines (55 loc) · 1.82 KB
/
test_map_simple.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
72
73
use protobuf::text_format::print_to_string;
use super::test_map_simple_pb::*;
use protobuf_test_common::*;
#[test]
fn test_map() {
let mut map = TestMap::new();
let mut entry = TestMapEntry::new();
entry.set_v(10);
test_serialize_deserialize("", &map);
map.mut_m().insert("two".to_owned(), 2);
test_serialize_deserialize("0a 07 0a 03 74 77 6f 10 02", &map);
map.mut_m().insert("sixty six".to_owned(), 66);
// Insert map entry sub message
map.mut_mm().insert("map".to_owned(), entry);
// cannot (easily) test hex, because order is not specified
test_serialize_deserialize_no_hex(&map);
}
#[test]
fn test_map_negative_i32_value() {
let mut map = TestMap::new();
map.mut_m().insert("two".to_owned(), -2);
test_serialize_deserialize("0a 10 0a 03 74 77 6f 10 fe ff ff ff ff ff ff ff ff 01", &map);
}
#[test]
fn test_map_with_object() {
let mut map = TestMap::new();
let mut entry = TestMapEntry::new();
entry.set_v(10);
test_serialize_deserialize("", &map);
map.mut_mm().insert("map".to_owned(), entry);
// cannot (easily) test hex, because order is not specified
test_serialize_deserialize_no_hex(&map);
}
#[test]
fn test_map_unset_default_fields() {
// unset key and value
let mut m = TestMap::new();
m.m.insert("".to_owned(), 0);
test_deserialize("0a 00", &m);
// unset value
let mut m = TestMap::new();
m.m.insert("ab".to_owned(), 0);
test_deserialize("0a 04 0a 02 61 62", &m);
// unset key
let mut m = TestMap::new();
m.m.insert("".to_owned(), 17);
test_deserialize("0a 02 10 11", &m);
}
#[test]
fn text_format() {
let mut map = TestMap::new();
assert_eq!(&*print_to_string(&map), "");
map.mut_m().insert("two".to_owned(), 2);
assert_eq!(&*print_to_string(&map), "m {key: \"two\" value: 2}")
}