sum_tree: Replace rayon with futures (#41586)
Release Notes: - N/A *or* Added/Fixed/Improved ... Co-authored by: Kate <kate@zed.dev>
This commit is contained in:
@@ -503,11 +503,12 @@ fn is_line_end(point: Point, text: &Rope) -> bool {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use gpui::BackgroundExecutor;
|
||||
use rand::prelude::*;
|
||||
use std::env;
|
||||
|
||||
#[test]
|
||||
fn test_delete_first_of_two_lines() {
|
||||
#[gpui::test]
|
||||
fn test_delete_first_of_two_lines(cx: &mut gpui::TestAppContext) {
|
||||
let old_text = "aaaa\nbbbb";
|
||||
let char_ops = vec![
|
||||
CharOperation::Delete { bytes: 5 },
|
||||
@@ -523,18 +524,18 @@ mod tests {
|
||||
apply_line_operations(old_text, &new_text, &expected_line_ops)
|
||||
);
|
||||
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops);
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor());
|
||||
assert_eq!(line_ops, expected_line_ops);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_delete_second_of_two_lines() {
|
||||
#[gpui::test]
|
||||
fn test_delete_second_of_two_lines(cx: &mut gpui::TestAppContext) {
|
||||
let old_text = "aaaa\nbbbb";
|
||||
let char_ops = vec![
|
||||
CharOperation::Keep { bytes: 5 },
|
||||
CharOperation::Delete { bytes: 4 },
|
||||
];
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops);
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor());
|
||||
assert_eq!(
|
||||
line_ops,
|
||||
vec![
|
||||
@@ -550,8 +551,8 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_add_new_line() {
|
||||
#[gpui::test]
|
||||
fn test_add_new_line(cx: &mut gpui::TestAppContext) {
|
||||
let old_text = "aaaa\nbbbb";
|
||||
let char_ops = vec![
|
||||
CharOperation::Keep { bytes: 9 },
|
||||
@@ -559,7 +560,7 @@ mod tests {
|
||||
text: "\ncccc".into(),
|
||||
},
|
||||
];
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops);
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor());
|
||||
assert_eq!(
|
||||
line_ops,
|
||||
vec![
|
||||
@@ -574,15 +575,15 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_delete_line_in_middle() {
|
||||
#[gpui::test]
|
||||
fn test_delete_line_in_middle(cx: &mut gpui::TestAppContext) {
|
||||
let old_text = "aaaa\nbbbb\ncccc";
|
||||
let char_ops = vec![
|
||||
CharOperation::Keep { bytes: 5 },
|
||||
CharOperation::Delete { bytes: 5 },
|
||||
CharOperation::Keep { bytes: 4 },
|
||||
];
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops);
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor());
|
||||
assert_eq!(
|
||||
line_ops,
|
||||
vec![
|
||||
@@ -598,8 +599,8 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_replace_line() {
|
||||
#[gpui::test]
|
||||
fn test_replace_line(cx: &mut gpui::TestAppContext) {
|
||||
let old_text = "aaaa\nbbbb\ncccc";
|
||||
let char_ops = vec![
|
||||
CharOperation::Keep { bytes: 5 },
|
||||
@@ -609,7 +610,7 @@ mod tests {
|
||||
},
|
||||
CharOperation::Keep { bytes: 5 },
|
||||
];
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops);
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor());
|
||||
assert_eq!(
|
||||
line_ops,
|
||||
vec![
|
||||
@@ -626,8 +627,8 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multiple_edits_on_different_lines() {
|
||||
#[gpui::test]
|
||||
fn test_multiple_edits_on_different_lines(cx: &mut gpui::TestAppContext) {
|
||||
let old_text = "aaaa\nbbbb\ncccc\ndddd";
|
||||
let char_ops = vec![
|
||||
CharOperation::Insert { text: "A".into() },
|
||||
@@ -638,7 +639,7 @@ mod tests {
|
||||
text: "\nEEEE".into(),
|
||||
},
|
||||
];
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops);
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor());
|
||||
assert_eq!(
|
||||
line_ops,
|
||||
vec![
|
||||
@@ -656,15 +657,15 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_edit_at_end_of_line() {
|
||||
#[gpui::test]
|
||||
fn test_edit_at_end_of_line(cx: &mut gpui::TestAppContext) {
|
||||
let old_text = "aaaa\nbbbb\ncccc";
|
||||
let char_ops = vec![
|
||||
CharOperation::Keep { bytes: 4 },
|
||||
CharOperation::Insert { text: "A".into() },
|
||||
CharOperation::Keep { bytes: 10 },
|
||||
];
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops);
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor());
|
||||
assert_eq!(
|
||||
line_ops,
|
||||
vec![
|
||||
@@ -680,8 +681,8 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_insert_newline_character() {
|
||||
#[gpui::test]
|
||||
fn test_insert_newline_character(cx: &mut gpui::TestAppContext) {
|
||||
let old_text = "aaaabbbb";
|
||||
let char_ops = vec![
|
||||
CharOperation::Keep { bytes: 4 },
|
||||
@@ -689,7 +690,7 @@ mod tests {
|
||||
CharOperation::Keep { bytes: 4 },
|
||||
];
|
||||
let new_text = apply_char_operations(old_text, &char_ops);
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops);
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor());
|
||||
assert_eq!(
|
||||
line_ops,
|
||||
vec![
|
||||
@@ -703,14 +704,14 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_insert_newline_at_beginning() {
|
||||
#[gpui::test]
|
||||
fn test_insert_newline_at_beginning(cx: &mut gpui::TestAppContext) {
|
||||
let old_text = "aaaa\nbbbb";
|
||||
let char_ops = vec![
|
||||
CharOperation::Insert { text: "\n".into() },
|
||||
CharOperation::Keep { bytes: 9 },
|
||||
];
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops);
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor());
|
||||
assert_eq!(
|
||||
line_ops,
|
||||
vec![
|
||||
@@ -725,15 +726,15 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_delete_newline() {
|
||||
#[gpui::test]
|
||||
fn test_delete_newline(cx: &mut gpui::TestAppContext) {
|
||||
let old_text = "aaaa\nbbbb";
|
||||
let char_ops = vec![
|
||||
CharOperation::Keep { bytes: 4 },
|
||||
CharOperation::Delete { bytes: 1 },
|
||||
CharOperation::Keep { bytes: 4 },
|
||||
];
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops);
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor());
|
||||
assert_eq!(
|
||||
line_ops,
|
||||
vec![
|
||||
@@ -749,8 +750,8 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_insert_multiple_newlines() {
|
||||
#[gpui::test]
|
||||
fn test_insert_multiple_newlines(cx: &mut gpui::TestAppContext) {
|
||||
let old_text = "aaaa\nbbbb";
|
||||
let char_ops = vec![
|
||||
CharOperation::Keep { bytes: 5 },
|
||||
@@ -759,7 +760,7 @@ mod tests {
|
||||
},
|
||||
CharOperation::Keep { bytes: 4 },
|
||||
];
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops);
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor());
|
||||
assert_eq!(
|
||||
line_ops,
|
||||
vec![
|
||||
@@ -775,15 +776,15 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_delete_multiple_newlines() {
|
||||
#[gpui::test]
|
||||
fn test_delete_multiple_newlines(cx: &mut gpui::TestAppContext) {
|
||||
let old_text = "aaaa\n\n\nbbbb";
|
||||
let char_ops = vec![
|
||||
CharOperation::Keep { bytes: 5 },
|
||||
CharOperation::Delete { bytes: 2 },
|
||||
CharOperation::Keep { bytes: 4 },
|
||||
];
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops);
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor());
|
||||
assert_eq!(
|
||||
line_ops,
|
||||
vec![
|
||||
@@ -799,8 +800,8 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_complex_scenario() {
|
||||
#[gpui::test]
|
||||
fn test_complex_scenario(cx: &mut gpui::TestAppContext) {
|
||||
let old_text = "line1\nline2\nline3\nline4";
|
||||
let char_ops = vec![
|
||||
CharOperation::Keep { bytes: 6 },
|
||||
@@ -814,7 +815,7 @@ mod tests {
|
||||
},
|
||||
CharOperation::Keep { bytes: 6 },
|
||||
];
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops);
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor());
|
||||
assert_eq!(
|
||||
line_ops,
|
||||
vec![
|
||||
@@ -834,8 +835,8 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cleaning_up_common_suffix() {
|
||||
#[gpui::test]
|
||||
fn test_cleaning_up_common_suffix(cx: &mut gpui::TestAppContext) {
|
||||
let old_text = concat!(
|
||||
" for y in 0..size.y() {\n",
|
||||
" let a = 10;\n",
|
||||
@@ -883,7 +884,7 @@ mod tests {
|
||||
},
|
||||
CharOperation::Keep { bytes: 1 },
|
||||
];
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops);
|
||||
let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor());
|
||||
assert_eq!(
|
||||
line_ops,
|
||||
vec![
|
||||
@@ -901,8 +902,8 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_random_diffs() {
|
||||
#[gpui::test]
|
||||
fn test_random_diffs(cx: &mut gpui::TestAppContext) {
|
||||
random_test(|mut rng| {
|
||||
let old_text_len = env::var("OLD_TEXT_LEN")
|
||||
.map(|i| i.parse().expect("invalid `OLD_TEXT_LEN` variable"))
|
||||
@@ -922,15 +923,19 @@ mod tests {
|
||||
assert_eq!(patched, new);
|
||||
|
||||
// Test char_ops_to_line_ops
|
||||
let line_ops = char_ops_to_line_ops(&old, &char_operations);
|
||||
let line_ops = char_ops_to_line_ops(&old, &char_operations, cx.background_executor());
|
||||
println!("line operations: {:?}", line_ops);
|
||||
let patched = apply_line_operations(&old, &new, &line_ops);
|
||||
assert_eq!(patched, new);
|
||||
});
|
||||
}
|
||||
|
||||
fn char_ops_to_line_ops(old_text: &str, char_ops: &[CharOperation]) -> Vec<LineOperation> {
|
||||
let old_rope = Rope::from(old_text);
|
||||
fn char_ops_to_line_ops(
|
||||
old_text: &str,
|
||||
char_ops: &[CharOperation],
|
||||
executor: &BackgroundExecutor,
|
||||
) -> Vec<LineOperation> {
|
||||
let old_rope = Rope::from_str(old_text, executor);
|
||||
let mut diff = LineDiff::default();
|
||||
for op in char_ops {
|
||||
diff.push_char_operation(op, &old_rope);
|
||||
|
||||
Reference in New Issue
Block a user