1 //! This test file ensures that all of the lifetimes work the way we
2 //! want, and that there are no regressions. It's a "does this compile?"
3 //! test.
4 
5 extern crate ropey;
6 
7 use ropey::{Rope, RopeSlice};
8 
9 const TEXT: &str = include_str!("test_text.txt");
10 
main()11 fn main() {
12     let rope = Rope::from_str(TEXT);
13 
14     let (a, b, c, d, e, f, g, count, line, string) = {
15         // The lifetimes of intermediate slices shouldn't matter.  The
16         // lifetimes of the things produced by the calls below should be
17         // tied to the lifetime of the original rope, not the lifetimes of
18         // the slices they were created from.  Therefore, this should all
19         // compile.
20 
21         let a = rope.slice(4..500).slice(4..400).slice(4..300);
22         let b = rope.slice(4..500).slice(4..400).as_str();
23         let c = rope.slice(4..500).slice(4..400).line(1);
24         let d = rope.line(1).slice(4..20).slice(4..10);
25         let e = rope.slice(4..500).slice(4..400).chunk_at_byte(50);
26         let f = rope.slice(4..500).slice(4..400).chunk_at_char(50);
27         let g = rope.slice(4..500).slice(4..400).chunk_at_line_break(3);
28 
29         // Same for iterators.  In addition, the items _yielded_ by the
30         // iterators should also be tied to the lifetime of the original
31         // rope, not to the iterators or slices they came from.
32 
33         let mut count = 0;
34         for _ in rope.slice(4..500).slice(4..400).bytes() {
35             count += 1;
36         }
37         for _ in rope.slice(4..500).slice(4..400).chars() {
38             count += 1;
39         }
40 
41         let mut line: RopeSlice = "".into();
42         for l in rope.slice(4..500).slice(4..400).lines() {
43             line = l;
44         }
45         line = line.slice(..).slice(..);
46 
47         let mut string = "";
48         for c in rope.slice(4..500).slice(4..400).chunks() {
49             string = c;
50         }
51 
52         (a, b, c, d, e, f, g, count, line, string)
53     };
54 
55     println!(
56         "{} {:?} {} {} {:?} {:?} {:?} {} {} {}",
57         a, b, c, d, e, f, g, count, line, string
58     );
59 }
60