]>
git.proxmox.com Git - rustc.git/blob - src/librustc_data_structures/snapshot_map/test.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use super::SnapshotMap
;
15 let mut map
= SnapshotMap
::default();
16 map
.insert(22, "twenty-two");
17 let snapshot
= map
.snapshot();
18 map
.insert(22, "thirty-three");
19 assert_eq
!(map
[&22], "thirty-three");
20 map
.insert(44, "fourty-four");
21 assert_eq
!(map
[&44], "fourty-four");
22 assert_eq
!(map
.get(&33), None
);
23 map
.rollback_to(&snapshot
);
24 assert_eq
!(map
[&22], "twenty-two");
25 assert_eq
!(map
.get(&33), None
);
26 assert_eq
!(map
.get(&44), None
);
32 let mut map
= SnapshotMap
::default();
33 map
.insert(22, "twenty-two");
34 let snapshot1
= map
.snapshot();
35 let _snapshot2
= map
.snapshot();
36 map
.rollback_to(&snapshot1
);
40 fn nested_commit_then_rollback() {
41 let mut map
= SnapshotMap
::default();
42 map
.insert(22, "twenty-two");
43 let snapshot1
= map
.snapshot();
44 let snapshot2
= map
.snapshot();
45 map
.insert(22, "thirty-three");
46 map
.commit(&snapshot2
);
47 assert_eq
!(map
[&22], "thirty-three");
48 map
.rollback_to(&snapshot1
);
49 assert_eq
!(map
[&22], "twenty-two");