aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_editor
diff options
context:
space:
mode:
authorJeremy A. Kolb <[email protected]>2018-09-24 15:48:13 +0100
committerJeremy A. Kolb <[email protected]>2018-09-24 15:48:13 +0100
commit4d52d004d58ff8d0479220d22bd0adfcfd7ffa9f (patch)
tree8afdb4cfc707d47e77c728355ca0c4cb649575af /crates/ra_editor
parentff0a706a30567f297642ba1fa6ee9537ed82c40f (diff)
Unit Tests
Diffstat (limited to 'crates/ra_editor')
-rw-r--r--crates/ra_editor/src/folding_ranges.rs56
1 files changed, 56 insertions, 0 deletions
diff --git a/crates/ra_editor/src/folding_ranges.rs b/crates/ra_editor/src/folding_ranges.rs
index 4518e8d24..817da28d1 100644
--- a/crates/ra_editor/src/folding_ranges.rs
+++ b/crates/ra_editor/src/folding_ranges.rs
@@ -6,11 +6,13 @@ use ra_syntax::{
6 algo::{walk, Direction, siblings}, 6 algo::{walk, Direction, siblings},
7}; 7};
8 8
9#[derive(Debug, PartialEq, Eq)]
9pub enum FoldKind { 10pub enum FoldKind {
10 Comment, 11 Comment,
11 Imports, 12 Imports,
12} 13}
13 14
15#[derive(Debug)]
14pub struct Fold { 16pub struct Fold {
15 pub range: TextRange, 17 pub range: TextRange,
16 pub kind: FoldKind, 18 pub kind: FoldKind,
@@ -83,4 +85,58 @@ fn contiguous_range_for<'a>(
83 } else { 85 } else {
84 None 86 None
85 } 87 }
88}
89
90#[cfg(test)]
91mod tests {
92 use super::*;
93
94 #[test]
95 fn test_fold_comments() {
96 let text = r#"
97// Hello
98// this is a multiline
99// comment
100//
101
102// But this is not
103
104fn main() {
105 // We should
106 // also
107 // fold
108 // this one.
109}"#;
110
111 let file = File::parse(&text);
112 let folds = folding_ranges(&file);
113 assert_eq!(folds.len(), 2);
114 assert_eq!(folds[0].range.start(), 1.into());
115 assert_eq!(folds[0].range.end(), 46.into());
116 assert_eq!(folds[0].kind, FoldKind::Comment);
117
118 assert_eq!(folds[1].range.start(), 84.into());
119 assert_eq!(folds[1].range.end(), 137.into());
120 assert_eq!(folds[1].kind, FoldKind::Comment);
121 }
122
123 #[test]
124 fn test_fold_imports() {
125 let text = r#"
126use std::str;
127use std::vec;
128use std::io as iop;
129
130fn main() {
131}"#;
132
133 let file = File::parse(&text);
134 let folds = folding_ranges(&file);
135 assert_eq!(folds.len(), 1);
136 assert_eq!(folds[0].range.start(), 1.into());
137 assert_eq!(folds[0].range.end(), 48.into());
138 assert_eq!(folds[0].kind, FoldKind::Imports);
139 }
140
141
86} \ No newline at end of file 142} \ No newline at end of file