Skip to content

Commit

Permalink
tests: migrate .diff() callers to .diff_stream()
Browse files Browse the repository at this point in the history
  • Loading branch information
yuja committed Aug 8, 2024
1 parent 63e254d commit 24b8934
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 29 deletions.
12 changes: 10 additions & 2 deletions lib/tests/test_local_working_copy_sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use futures::StreamExt as _;
use itertools::Itertools;
use jj_lib::local_working_copy::LocalWorkingCopy;
use jj_lib::matchers::EverythingMatcher;
use jj_lib::repo::Repo;
use jj_lib::repo_path::{RepoPath, RepoPathBuf};
use jj_lib::working_copy::{CheckoutStats, WorkingCopy};
use pollster::FutureExt as _;
use testutils::{commit_with_tree, create_tree, TestWorkspace};

fn to_owned_path_vec(paths: &[&RepoPath]) -> Vec<RepoPathBuf> {
Expand Down Expand Up @@ -194,7 +196,10 @@ fn test_sparse_commit() {
// Create a tree from the working copy. Only dir1/file1 should be updated in the
// tree.
let modified_tree = test_workspace.snapshot().unwrap();
let diff = tree.diff(&modified_tree, &EverythingMatcher).collect_vec();
let diff: Vec<_> = tree
.diff_stream(&modified_tree, &EverythingMatcher)
.collect()
.block_on();
assert_eq!(diff.len(), 1);
assert_eq!(diff[0].0.as_ref(), dir1_file1_path);

Expand All @@ -213,7 +218,10 @@ fn test_sparse_commit() {
// Create a tree from the working copy. Only dir1/file1 and dir2/file1 should be
// updated in the tree.
let modified_tree = test_workspace.snapshot().unwrap();
let diff = tree.diff(&modified_tree, &EverythingMatcher).collect_vec();
let diff: Vec<_> = tree
.diff_stream(&modified_tree, &EverythingMatcher)
.collect()
.block_on();
assert_eq!(diff.len(), 2);
assert_eq!(diff[0].0.as_ref(), dir1_file1_path);
assert_eq!(diff[1].0.as_ref(), dir2_file1_path);
Expand Down
63 changes: 36 additions & 27 deletions lib/tests/test_merged_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,10 +777,11 @@ fn test_diff_resolved() {
let before_merged = MergedTree::new(Merge::resolved(before.clone()));
let after_merged = MergedTree::new(Merge::resolved(after.clone()));

let diff = before_merged
.diff(&after_merged, &EverythingMatcher)
let diff: Vec<_> = before_merged
.diff_stream(&after_merged, &EverythingMatcher)
.map(|(path, diff)| (path, diff.unwrap()))
.collect_vec();
.collect()
.block_on();
assert_eq!(diff.len(), 3);
assert_eq!(
diff[0].clone(),
Expand Down Expand Up @@ -886,10 +887,11 @@ fn test_diff_conflicted() {
));

// Test the forwards diff
let actual_diff = left_merged
.diff(&right_merged, &EverythingMatcher)
let actual_diff: Vec<_> = left_merged
.diff_stream(&right_merged, &EverythingMatcher)
.map(|(path, diff)| (path, diff.unwrap()))
.collect_vec();
.collect()
.block_on();
let expected_diff = [path2, path3, path4]
.iter()
.map(|&path| {
Expand All @@ -905,10 +907,11 @@ fn test_diff_conflicted() {
assert_eq!(actual_diff, expected_diff);
diff_stream_equals_iter(&left_merged, &right_merged, &EverythingMatcher);
// Test the reverse diff
let actual_diff = right_merged
.diff(&left_merged, &EverythingMatcher)
let actual_diff: Vec<_> = right_merged
.diff_stream(&left_merged, &EverythingMatcher)
.map(|(path, diff)| (path, diff.unwrap()))
.collect_vec();
.collect()
.block_on();
let expected_diff = [path2, path3, path4]
.iter()
.map(|&path| {
Expand Down Expand Up @@ -1022,10 +1025,11 @@ fn test_diff_dir_file() {

// Test the forwards diff
{
let actual_diff = left_merged
.diff(&right_merged, &EverythingMatcher)
let actual_diff: Vec<_> = left_merged
.diff_stream(&right_merged, &EverythingMatcher)
.map(|(path, diff)| (path, diff.unwrap()))
.collect_vec();
.collect()
.block_on();
let expected_diff = vec![
// path1: file1 -> directory1
(path1.to_owned(), (left_value(path1), Merge::absent())),
Expand Down Expand Up @@ -1066,10 +1070,11 @@ fn test_diff_dir_file() {

// Test the reverse diff
{
let actual_diff = right_merged
.diff(&left_merged, &EverythingMatcher)
let actual_diff: Vec<_> = right_merged
.diff_stream(&left_merged, &EverythingMatcher)
.map(|(path, diff)| (path, diff.unwrap()))
.collect_vec();
.collect()
.block_on();
let expected_diff = vec![
// path1: file1 -> directory1
(
Expand Down Expand Up @@ -1111,10 +1116,11 @@ fn test_diff_dir_file() {
// Diff while filtering by `path1` (file1 -> directory1) as a file
{
let matcher = FilesMatcher::new([&path1]);
let actual_diff = left_merged
.diff(&right_merged, &matcher)
let actual_diff: Vec<_> = left_merged
.diff_stream(&right_merged, &matcher)
.map(|(path, diff)| (path, diff.unwrap()))
.collect_vec();
.collect()
.block_on();
let expected_diff = vec![
// path1: file1 -> directory1
(path1.to_owned(), (left_value(path1), Merge::absent())),
Expand All @@ -1126,10 +1132,11 @@ fn test_diff_dir_file() {
// Diff while filtering by `path1/file` (file1 -> directory1) as a file
{
let matcher = FilesMatcher::new([path1.join(file)]);
let actual_diff = left_merged
.diff(&right_merged, &matcher)
let actual_diff: Vec<_> = left_merged
.diff_stream(&right_merged, &matcher)
.map(|(path, diff)| (path, diff.unwrap()))
.collect_vec();
.collect()
.block_on();
let expected_diff = vec![
// path1: file1 -> directory1
(
Expand All @@ -1144,10 +1151,11 @@ fn test_diff_dir_file() {
// Diff while filtering by `path1` (file1 -> directory1) as a prefix
{
let matcher = PrefixMatcher::new([&path1]);
let actual_diff = left_merged
.diff(&right_merged, &matcher)
let actual_diff: Vec<_> = left_merged
.diff_stream(&right_merged, &matcher)
.map(|(path, diff)| (path, diff.unwrap()))
.collect_vec();
.collect()
.block_on();
let expected_diff = vec![
(path1.to_owned(), (left_value(path1), Merge::absent())),
(
Expand All @@ -1165,10 +1173,11 @@ fn test_diff_dir_file() {
// side.
{
let matcher = FilesMatcher::new([&path6]);
let actual_diff = left_merged
.diff(&right_merged, &matcher)
let actual_diff: Vec<_> = left_merged
.diff_stream(&right_merged, &matcher)
.map(|(path, diff)| (path, diff.unwrap()))
.collect_vec();
.collect()
.block_on();
let expected_diff = vec![(path6.to_owned(), (Merge::absent(), right_value(path6)))];
assert_eq!(actual_diff, expected_diff);
diff_stream_equals_iter(&left_merged, &right_merged, &matcher);
Expand Down

0 comments on commit 24b8934

Please sign in to comment.