| 1 |
use super::*; |
| 2 |
|
| 3 |
/// Shorthand to reduce boilerplate when creating [`Revision`] for testing |
| 4 |
macro_rules! R { |
| 5 |
($revision:literal) => { |
| 6 |
Revision($revision) |
| 7 |
}; |
| 8 |
} |
| 9 |
|
| 10 |
/// Unit tests for: |
| 11 |
/// |
| 12 |
/// ```ignore |
| 13 |
/// fn compare_value( |
| 14 |
/// current_merge: Revision, |
| 15 |
/// merge_case_for_dest: impl Fn() -> MergeCase, |
| 16 |
/// src_minor: &CopySource, |
| 17 |
/// src_major: &CopySource, |
| 18 |
/// ) -> (MergePick, /* overwrite: */ bool) |
| 19 |
/// ``` |
| 20 |
#[test] |
| 21 |
fn test_compare_value() { |
| 22 |
// The `compare_value!` macro calls the `compare_value` function with |
| 23 |
// arguments given in pseudo-syntax: |
| 24 |
// |
| 25 |
// * For `merge_case_for_dest` it takes a plain `MergeCase` value instead of |
| 26 |
// a closure. |
| 27 |
// * `CopySource` values are represented as `(rev, path, overwritten)` |
| 28 |
// tuples of type `(Revision, Option<PathToken>, OrdSet<Revision>)`. |
| 29 |
// * `PathToken` is an integer not read by `compare_value`. It only checks |
| 30 |
// for `Some(_)` indicating a file copy v.s. `None` for a file deletion. |
| 31 |
// * `OrdSet<Revision>` is represented as a Python-like set literal. |
| 32 |
|
| 33 |
use MergeCase::*; |
| 34 |
use MergePick::*; |
| 35 |
|
| 36 |
assert_eq!( |
| 37 |
compare_value!( |
| 38 |
R!(1), |
| 39 |
Normal, |
| 40 |
(R!(1), None, { R!(1) }), |
| 41 |
(R!(1), None, { R!(1) }) |
| 42 |
), |
| 43 |
(Any, false) |
| 44 |
); |
| 45 |
} |
| 46 |
|
| 47 |
/// Unit tests for: |
| 48 |
/// |
| 49 |
/// ```ignore |
| 50 |
/// fn merge_copies_dict( |
| 51 |
/// path_map: &TwoWayPathMap, // Not visible in test cases |
| 52 |
/// current_merge: Revision, |
| 53 |
/// minor: InternalPathCopies, |
| 54 |
/// major: InternalPathCopies, |
| 55 |
/// get_merge_case: impl Fn(&HgPath) -> MergeCase + Copy, |
| 56 |
/// ) -> InternalPathCopies |
| 57 |
/// ``` |
| 58 |
#[test] |
| 59 |
fn test_merge_copies_dict() { |
| 60 |
// The `merge_copies_dict!` macro calls the `merge_copies_dict` function |
| 61 |
// with arguments given in pseudo-syntax: |
| 62 |
// |
| 63 |
// * `TwoWayPathMap` and path tokenization are implicitly taken care of. All |
| 64 |
// paths are given as string literals. |
| 65 |
// * Key-value maps are represented with `{key1 => value1, key2 => value2}` |
| 66 |
// pseudo-syntax. |
| 67 |
// * `InternalPathCopies` is a map of copy destination path keys to |
| 68 |
// `CopySource` values. |
| 69 |
// - `CopySource` is represented as a `(rev, source_path, overwritten)` |
| 70 |
// tuple of type `(Revision, Option<Path>, OrdSet<Revision>)`. |
| 71 |
// - Unlike in `test_compare_value`, source paths are string literals. |
| 72 |
// - `OrdSet<Revision>` is again represented as a Python-like set literal. |
| 73 |
// * `get_merge_case` is represented as a map of copy destination path to |
| 74 |
// `MergeCase`. The default for paths not in the map is |
| 75 |
// `MergeCase::Normal`. |
| 76 |
// |
| 77 |
// `internal_path_copies!` creates an `InternalPathCopies` value with the |
| 78 |
// same pseudo-syntax as in `merge_copies_dict!`. |
| 79 |
|
| 80 |
use MergeCase::*; |
| 81 |
|
| 82 |
assert_eq!( |
| 83 |
merge_copies_dict!( |
| 84 |
R!(1), |
| 85 |
{"foo" => (R!(1), None, {})}, |
| 86 |
{}, |
| 87 |
{"foo" => Merged} |
| 88 |
), |
| 89 |
internal_path_copies!("foo" => (R!(1), None, {})) |
| 90 |
); |
| 91 |
} |
| 92 |
|
| 93 |
/// Unit tests for: |
| 94 |
/// |
| 95 |
/// ```ignore |
| 96 |
/// impl CombineChangesetCopies { |
| 97 |
/// fn new(children_count: HashMap<Revision, usize>) -> Self |
| 98 |
/// |
| 99 |
/// // Called repeatedly: |
| 100 |
/// fn add_revision_inner<'a>( |
| 101 |
/// &mut self, |
| 102 |
/// rev: Revision, |
| 103 |
/// p1: Revision, |
| 104 |
/// p2: Revision, |
| 105 |
/// copy_actions: impl Iterator<Item = Action<'a>>, |
| 106 |
/// get_merge_case: impl Fn(&HgPath) -> MergeCase + Copy, |
| 107 |
/// ) |
| 108 |
/// |
| 109 |
/// fn finish(mut self, target_rev: Revision) -> PathCopies |
| 110 |
/// } |
| 111 |
/// ``` |
| 112 |
#[test] |
| 113 |
fn test_combine_changeset_copies() { |
| 114 |
// `combine_changeset_copies!` creates a `CombineChangesetCopies` with |
| 115 |
// `new`, then calls `add_revision_inner` repeatedly, then calls `finish` |
| 116 |
// for its return value. |
| 117 |
// |
| 118 |
// All paths given as string literals. |
| 119 |
// |
| 120 |
// * Key-value maps are represented with `{key1 => value1, key2 => value2}` |
| 121 |
// pseudo-syntax. |
| 122 |
// * `children_count` is a map of revision numbers to count of children in |
| 123 |
// the DAG. It includes all revisions that should be considered by the |
| 124 |
// algorithm. |
| 125 |
// * Calls to `add_revision_inner` are represented as an array of anonymous |
| 126 |
// structs with named fields, one pseudo-struct per call. |
| 127 |
// |
| 128 |
// `path_copies!` creates a `PathCopies` value, a map of copy destination |
| 129 |
// keys to copy source values. Note: the arrows for map literal syntax |
| 130 |
// point **backwards** compared to the logical direction of copy! |
| 131 |
|
| 132 |
use Action::*; |
| 133 |
use MergeCase::*; |
| 134 |
|
| 135 |
use crate::revlog::NULL_REVISION as NULL; |
| 136 |
|
| 137 |
assert_eq!( |
| 138 |
combine_changeset_copies!( |
| 139 |
{ R!(1) => 1, R!(2) => 1 }, |
| 140 |
[ |
| 141 |
{ |
| 142 |
rev: R!(1), |
| 143 |
p1: NULL, |
| 144 |
p2: NULL, |
| 145 |
actions: [], |
| 146 |
merge_cases: {}, |
| 147 |
}, |
| 148 |
{ |
| 149 |
rev: R!(2), |
| 150 |
p1: NULL, |
| 151 |
p2: NULL, |
| 152 |
actions: [], |
| 153 |
merge_cases: {}, |
| 154 |
}, |
| 155 |
{ |
| 156 |
rev: R!(3), p1: R!(1), p2: R!(2), |
| 157 |
actions: [CopiedFromP1("destination.txt", "source.txt")], |
| 158 |
merge_cases: {"destination.txt" => Merged}, |
| 159 |
}, |
| 160 |
], |
| 161 |
R!(3), |
| 162 |
), |
| 163 |
path_copies!("destination.txt" => "source.txt") |
| 164 |
); |
| 165 |
} |