@@ -100,43 +100,41 @@ mod test {
102 fn test_find_line_comment() {
102 fn test_find_line_comment() {
105 // four lines, two space indented, except for line 1 which is blank.
103 // four lines, two space indented, except for line 1 which is blank.
106− let doc = Rope::from(" 1\n\n 2\n 3");
104+ let mut doc = Rope::from(" 1\n\n 2\n 3");
108− let mut state = State::new(doc);
109 // select whole document
105 // select whole document
110− state.selection = Selection::single(0, state.doc.len_chars() - 1);
106+ let mut selection = Selection::single(0, doc.len_chars() - 1);
112− let text = state.doc.slice(..);
108+ let text = doc.slice(..);
114 let res = find_line_comment("//", text, 0..3);
110 let res = find_line_comment("//", text, 0..3);
115 // (commented = true, to_change = [line 0, line 2], min = col 2, margin = 1)
111 // (commented = true, to_change = [line 0, line 2], min = col 2, margin = 1)
116 assert_eq!(res, (false, vec![0, 2], 2, 1));
112 assert_eq!(res, (false, vec![0, 2], 2, 1));
118 // comment
114 // comment
119− let transaction = toggle_line_comments(&state.doc, &state.selection, None);
115+ let transaction = toggle_line_comments(&doc, &selection, None);
120− transaction.apply(&mut state.doc);
116+ transaction.apply(&mut doc);
121− state.selection = state.selection.map(transaction.changes());
117+ selection = selection.map(transaction.changes());
123− assert_eq!(state.doc, " // 1\n\n // 2\n // 3");
119+ assert_eq!(doc, " // 1\n\n // 2\n // 3");
125 // uncomment
121 // uncomment
126− let transaction = toggle_line_comments(&state.doc, &state.selection, None);
122+ let transaction = toggle_line_comments(&doc, &selection, None);
127− transaction.apply(&mut state.doc);
123+ transaction.apply(&mut doc);
128− state.selection = state.selection.map(transaction.changes());
124+ selection = selection.map(transaction.changes());
129− assert_eq!(state.doc, " 1\n\n 2\n 3");
125+ assert_eq!(doc, " 1\n\n 2\n 3");
126+ assert!(selection.len() == 1); // to ignore the selection unused warning
131 // 0 margin comments
128 // 0 margin comments
132− state.doc = Rope::from(" //1\n\n //2\n //3");
129+ doc = Rope::from(" //1\n\n //2\n //3");
133 // reset the selection.
130 // reset the selection.
134− state.selection = Selection::single(0, state.doc.len_chars() - 1);
131+ selection = Selection::single(0, doc.len_chars() - 1);
136− let transaction = toggle_line_comments(&state.doc, &state.selection, None);
133+ let transaction = toggle_line_comments(&doc, &selection, None);
137− transaction.apply(&mut state.doc);
134+ transaction.apply(&mut doc);
138− state.selection = state.selection.map(transaction.changes());
135+ selection = selection.map(transaction.changes());
139− assert_eq!(state.doc, " 1\n\n 2\n 3");
136+ assert_eq!(doc, " 1\n\n 2\n 3");
137+ assert!(selection.len() == 1); // to ignore the selection unused warning
141 // TODO: account for uncommenting with uneven comment indentation
139 // TODO: account for uncommenting with uneven comment indentation