author | Raphaël Gomès <rgomes@octobus.net> |
Sun, 01 Sep 2019 20:53:14 +0200 | |
changeset 42957 | 7a01778bc7b7 |
parent 42885 | a03a29462c0a |
child 43788 | 1fe2e574616e |
permissions | -rw-r--r-- |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
1 |
// dirs_multiset.rs |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
2 |
// |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
3 |
// Copyright 2019 Raphaël Gomès <rgomes@octobus.net> |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
4 |
// |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
5 |
// This software may be used and distributed according to the terms of the |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
6 |
// GNU General Public License version 2 or any later version. |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
7 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
8 |
//! A multiset of directory names. |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
9 |
//! |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
10 |
//! Used to counts the references to directories in a manifest or dirstate. |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
11 |
use crate::utils::hg_path::{HgPath, HgPathBuf}; |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
12 |
use crate::{ |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
13 |
dirstate::EntryState, utils::files, DirstateEntry, DirstateMapError, |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
14 |
}; |
42885
a03a29462c0a
rust-dirstate: specify concrete return type of DirsMultiset::iter()
Yuya Nishihara <yuya@tcha.org>
parents:
42841
diff
changeset
|
15 |
use std::collections::hash_map::{self, Entry}; |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
16 |
use std::collections::HashMap; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
17 |
|
42885
a03a29462c0a
rust-dirstate: specify concrete return type of DirsMultiset::iter()
Yuya Nishihara <yuya@tcha.org>
parents:
42841
diff
changeset
|
18 |
// could be encapsulated if we care API stability more seriously |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
19 |
pub type DirsMultisetIter<'a> = hash_map::Keys<'a, HgPathBuf, u32>; |
42885
a03a29462c0a
rust-dirstate: specify concrete return type of DirsMultiset::iter()
Yuya Nishihara <yuya@tcha.org>
parents:
42841
diff
changeset
|
20 |
|
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
21 |
#[derive(PartialEq, Debug)] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
22 |
pub struct DirsMultiset { |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
23 |
inner: HashMap<HgPathBuf, u32>, |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
24 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
25 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
26 |
impl DirsMultiset { |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
27 |
/// Initializes the multiset from a dirstate. |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
28 |
/// |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
29 |
/// If `skip_state` is provided, skips dirstate entries with equal state. |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
30 |
pub fn from_dirstate( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
31 |
vec: &HashMap<HgPathBuf, DirstateEntry>, |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
32 |
skip_state: Option<EntryState>, |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
33 |
) -> Self { |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
34 |
let mut multiset = DirsMultiset { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
35 |
inner: HashMap::new(), |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
36 |
}; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
37 |
|
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
38 |
for (filename, DirstateEntry { state, .. }) in vec { |
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
39 |
// This `if` is optimized out of the loop |
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
40 |
if let Some(skip) = skip_state { |
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
41 |
if skip != *state { |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
42 |
multiset.add_path(filename); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
43 |
} |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
44 |
} else { |
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
45 |
multiset.add_path(filename); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
46 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
47 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
48 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
49 |
multiset |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
50 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
51 |
|
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
52 |
/// Initializes the multiset from a manifest. |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
53 |
pub fn from_manifest(vec: &Vec<HgPathBuf>) -> Self { |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
54 |
let mut multiset = DirsMultiset { |
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
55 |
inner: HashMap::new(), |
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
56 |
}; |
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
57 |
|
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
58 |
for filename in vec { |
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
59 |
multiset.add_path(filename); |
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
60 |
} |
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
61 |
|
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
62 |
multiset |
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
63 |
} |
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
64 |
|
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
65 |
/// Increases the count of deepest directory contained in the path. |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
66 |
/// |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
67 |
/// If the directory is not yet in the map, adds its parents. |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
68 |
pub fn add_path(&mut self, path: &HgPath) { |
42608
717686c5e461
rust-utils: use new find_dirs iterator
Raphaël Gomès <rgomes@octobus.net>
parents:
42559
diff
changeset
|
69 |
for subpath in files::find_dirs(path) { |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
70 |
if let Some(val) = self.inner.get_mut(subpath) { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
71 |
*val += 1; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
72 |
break; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
73 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
74 |
self.inner.insert(subpath.to_owned(), 1); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
75 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
76 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
77 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
78 |
/// Decreases the count of deepest directory contained in the path. |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
79 |
/// |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
80 |
/// If it is the only reference, decreases all parents until one is |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
81 |
/// removed. |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
82 |
/// If the directory is not in the map, something horrible has happened. |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
83 |
pub fn delete_path( |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
84 |
&mut self, |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
85 |
path: &HgPath, |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
86 |
) -> Result<(), DirstateMapError> { |
42608
717686c5e461
rust-utils: use new find_dirs iterator
Raphaël Gomès <rgomes@octobus.net>
parents:
42559
diff
changeset
|
87 |
for subpath in files::find_dirs(path) { |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
88 |
match self.inner.entry(subpath.to_owned()) { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
89 |
Entry::Occupied(mut entry) => { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
90 |
let val = entry.get().clone(); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
91 |
if val > 1 { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
92 |
entry.insert(val - 1); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
93 |
break; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
94 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
95 |
entry.remove(); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
96 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
97 |
Entry::Vacant(_) => { |
42557
d26e4a434fe5
rust: run rfmt on all hg-core/hg-cpython code
Raphaël Gomès <rgomes@octobus.net>
parents:
42536
diff
changeset
|
98 |
return Err(DirstateMapError::PathNotFound( |
d26e4a434fe5
rust: run rfmt on all hg-core/hg-cpython code
Raphaël Gomès <rgomes@octobus.net>
parents:
42536
diff
changeset
|
99 |
path.to_owned(), |
d26e4a434fe5
rust: run rfmt on all hg-core/hg-cpython code
Raphaël Gomès <rgomes@octobus.net>
parents:
42536
diff
changeset
|
100 |
)) |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
101 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
102 |
}; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
103 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
104 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
105 |
Ok(()) |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
106 |
} |
42559
a80464e85ddd
rust: remove Deref in favor of explicit methods
Raphaël Gomès <rgomes@octobus.net>
parents:
42557
diff
changeset
|
107 |
|
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
108 |
pub fn contains(&self, key: &HgPath) -> bool { |
42559
a80464e85ddd
rust: remove Deref in favor of explicit methods
Raphaël Gomès <rgomes@octobus.net>
parents:
42557
diff
changeset
|
109 |
self.inner.contains_key(key) |
a80464e85ddd
rust: remove Deref in favor of explicit methods
Raphaël Gomès <rgomes@octobus.net>
parents:
42557
diff
changeset
|
110 |
} |
a80464e85ddd
rust: remove Deref in favor of explicit methods
Raphaël Gomès <rgomes@octobus.net>
parents:
42557
diff
changeset
|
111 |
|
42885
a03a29462c0a
rust-dirstate: specify concrete return type of DirsMultiset::iter()
Yuya Nishihara <yuya@tcha.org>
parents:
42841
diff
changeset
|
112 |
pub fn iter(&self) -> DirsMultisetIter { |
42750
849e744b925d
rust-dirstate: improve API of `DirsMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
42749
diff
changeset
|
113 |
self.inner.keys() |
42559
a80464e85ddd
rust: remove Deref in favor of explicit methods
Raphaël Gomès <rgomes@octobus.net>
parents:
42557
diff
changeset
|
114 |
} |
a80464e85ddd
rust: remove Deref in favor of explicit methods
Raphaël Gomès <rgomes@octobus.net>
parents:
42557
diff
changeset
|
115 |
|
a80464e85ddd
rust: remove Deref in favor of explicit methods
Raphaël Gomès <rgomes@octobus.net>
parents:
42557
diff
changeset
|
116 |
pub fn len(&self) -> usize { |
a80464e85ddd
rust: remove Deref in favor of explicit methods
Raphaël Gomès <rgomes@octobus.net>
parents:
42557
diff
changeset
|
117 |
self.inner.len() |
a80464e85ddd
rust: remove Deref in favor of explicit methods
Raphaël Gomès <rgomes@octobus.net>
parents:
42557
diff
changeset
|
118 |
} |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
119 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
120 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
121 |
#[cfg(test)] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
122 |
mod tests { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
123 |
use super::*; |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
124 |
use std::collections::HashMap; |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
125 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
126 |
#[test] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
127 |
fn test_delete_path_path_not_found() { |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
128 |
let mut map = DirsMultiset::from_manifest(&vec![]); |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
129 |
let path = HgPathBuf::from_bytes(b"doesnotexist/"); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
130 |
assert_eq!( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
131 |
Err(DirstateMapError::PathNotFound(path.to_owned())), |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
132 |
map.delete_path(&path) |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
133 |
); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
134 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
135 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
136 |
#[test] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
137 |
fn test_delete_path_empty_path() { |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
138 |
let mut map = DirsMultiset::from_manifest(&vec![HgPathBuf::new()]); |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
139 |
let path = HgPath::new(b""); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
140 |
assert_eq!(Ok(()), map.delete_path(path)); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
141 |
assert_eq!( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
142 |
Err(DirstateMapError::PathNotFound(path.to_owned())), |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
143 |
map.delete_path(path) |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
144 |
); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
145 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
146 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
147 |
#[test] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
148 |
fn test_delete_path_successful() { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
149 |
let mut map = DirsMultiset { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
150 |
inner: [("", 5), ("a", 3), ("a/b", 2), ("a/c", 1)] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
151 |
.iter() |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
152 |
.map(|(k, v)| (HgPathBuf::from_bytes(k.as_bytes()), *v)) |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
153 |
.collect(), |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
154 |
}; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
155 |
|
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
156 |
assert_eq!(Ok(()), map.delete_path(HgPath::new(b"a/b/"))); |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
157 |
eprintln!("{:?}", map); |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
158 |
assert_eq!(Ok(()), map.delete_path(HgPath::new(b"a/b/"))); |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
159 |
eprintln!("{:?}", map); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
160 |
assert_eq!( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
161 |
Err(DirstateMapError::PathNotFound(HgPathBuf::from_bytes( |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
162 |
b"a/b/" |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
163 |
))), |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
164 |
map.delete_path(HgPath::new(b"a/b/")) |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
165 |
); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
166 |
|
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
167 |
assert_eq!(2, *map.inner.get(HgPath::new(b"a")).unwrap()); |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
168 |
assert_eq!(1, *map.inner.get(HgPath::new(b"a/c")).unwrap()); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
169 |
eprintln!("{:?}", map); |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
170 |
assert_eq!(Ok(()), map.delete_path(HgPath::new(b"a/"))); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
171 |
eprintln!("{:?}", map); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
172 |
|
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
173 |
assert_eq!(Ok(()), map.delete_path(HgPath::new(b"a/c/"))); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
174 |
assert_eq!( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
175 |
Err(DirstateMapError::PathNotFound(HgPathBuf::from_bytes( |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
176 |
b"a/c/" |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
177 |
))), |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
178 |
map.delete_path(HgPath::new(b"a/c/")) |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
179 |
); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
180 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
181 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
182 |
#[test] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
183 |
fn test_add_path_empty_path() { |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
184 |
let mut map = DirsMultiset::from_manifest(&vec![]); |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
185 |
let path = HgPath::new(b""); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
186 |
map.add_path(path); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
187 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
188 |
assert_eq!(1, map.len()); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
189 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
190 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
191 |
#[test] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
192 |
fn test_add_path_successful() { |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
193 |
let mut map = DirsMultiset::from_manifest(&vec![]); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
194 |
|
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
195 |
map.add_path(HgPath::new(b"a/")); |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
196 |
assert_eq!(1, *map.inner.get(HgPath::new(b"a")).unwrap()); |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
197 |
assert_eq!(1, *map.inner.get(HgPath::new(b"")).unwrap()); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
198 |
assert_eq!(2, map.len()); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
199 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
200 |
// Non directory should be ignored |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
201 |
map.add_path(HgPath::new(b"a")); |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
202 |
assert_eq!(1, *map.inner.get(HgPath::new(b"a")).unwrap()); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
203 |
assert_eq!(2, map.len()); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
204 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
205 |
// Non directory will still add its base |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
206 |
map.add_path(HgPath::new(b"a/b")); |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
207 |
assert_eq!(2, *map.inner.get(HgPath::new(b"a")).unwrap()); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
208 |
assert_eq!(2, map.len()); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
209 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
210 |
// Duplicate path works |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
211 |
map.add_path(HgPath::new(b"a/")); |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
212 |
assert_eq!(3, *map.inner.get(HgPath::new(b"a")).unwrap()); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
213 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
214 |
// Nested dir adds to its base |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
215 |
map.add_path(HgPath::new(b"a/b/")); |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
216 |
assert_eq!(4, *map.inner.get(HgPath::new(b"a")).unwrap()); |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
217 |
assert_eq!(1, *map.inner.get(HgPath::new(b"a/b")).unwrap()); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
218 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
219 |
// but not its base's base, because it already existed |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
220 |
map.add_path(HgPath::new(b"a/b/c/")); |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
221 |
assert_eq!(4, *map.inner.get(HgPath::new(b"a")).unwrap()); |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
222 |
assert_eq!(2, *map.inner.get(HgPath::new(b"a/b")).unwrap()); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
223 |
|
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
224 |
map.add_path(HgPath::new(b"a/c/")); |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
225 |
assert_eq!(1, *map.inner.get(HgPath::new(b"a/c")).unwrap()); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
226 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
227 |
let expected = DirsMultiset { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
228 |
inner: [("", 2), ("a", 5), ("a/b", 2), ("a/b/c", 1), ("a/c", 1)] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
229 |
.iter() |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
230 |
.map(|(k, v)| (HgPathBuf::from_bytes(k.as_bytes()), *v)) |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
231 |
.collect(), |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
232 |
}; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
233 |
assert_eq!(map, expected); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
234 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
235 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
236 |
#[test] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
237 |
fn test_dirsmultiset_new_empty() { |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
238 |
let new = DirsMultiset::from_manifest(&vec![]); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
239 |
let expected = DirsMultiset { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
240 |
inner: HashMap::new(), |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
241 |
}; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
242 |
assert_eq!(expected, new); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
243 |
|
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
244 |
let new = DirsMultiset::from_dirstate(&HashMap::new(), None); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
245 |
let expected = DirsMultiset { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
246 |
inner: HashMap::new(), |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
247 |
}; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
248 |
assert_eq!(expected, new); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
249 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
250 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
251 |
#[test] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
252 |
fn test_dirsmultiset_new_no_skip() { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
253 |
let input_vec = ["a/", "b/", "a/c", "a/d/"] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
254 |
.iter() |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
255 |
.map(|e| HgPathBuf::from_bytes(e.as_bytes())) |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
256 |
.collect(); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
257 |
let expected_inner = [("", 2), ("a", 3), ("b", 1), ("a/d", 1)] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
258 |
.iter() |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
259 |
.map(|(k, v)| (HgPathBuf::from_bytes(k.as_bytes()), *v)) |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
260 |
.collect(); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
261 |
|
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
262 |
let new = DirsMultiset::from_manifest(&input_vec); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
263 |
let expected = DirsMultiset { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
264 |
inner: expected_inner, |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
265 |
}; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
266 |
assert_eq!(expected, new); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
267 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
268 |
let input_map = ["a/", "b/", "a/c", "a/d/"] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
269 |
.iter() |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
270 |
.map(|f| { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
271 |
( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
272 |
HgPathBuf::from_bytes(f.as_bytes()), |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
273 |
DirstateEntry { |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
274 |
state: EntryState::Normal, |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
275 |
mode: 0, |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
276 |
mtime: 0, |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
277 |
size: 0, |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
278 |
}, |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
279 |
) |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
280 |
}) |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
281 |
.collect(); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
282 |
let expected_inner = [("", 2), ("a", 3), ("b", 1), ("a/d", 1)] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
283 |
.iter() |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
284 |
.map(|(k, v)| (HgPathBuf::from_bytes(k.as_bytes()), *v)) |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
285 |
.collect(); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
286 |
|
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
287 |
let new = DirsMultiset::from_dirstate(&input_map, None); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
288 |
let expected = DirsMultiset { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
289 |
inner: expected_inner, |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
290 |
}; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
291 |
assert_eq!(expected, new); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
292 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
293 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
294 |
#[test] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
295 |
fn test_dirsmultiset_new_skip() { |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
296 |
let input_map = [ |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
297 |
("a/", EntryState::Normal), |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
298 |
("a/b/", EntryState::Normal), |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
299 |
("a/c", EntryState::Removed), |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
300 |
("a/d/", EntryState::Merged), |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
301 |
] |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
302 |
.iter() |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
303 |
.map(|(f, state)| { |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
304 |
( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
305 |
HgPathBuf::from_bytes(f.as_bytes()), |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
306 |
DirstateEntry { |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
307 |
state: *state, |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
308 |
mode: 0, |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
309 |
mtime: 0, |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
310 |
size: 0, |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
311 |
}, |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
312 |
) |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
313 |
}) |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
314 |
.collect(); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
315 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
316 |
// "a" incremented with "a/c" and "a/d/" |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
317 |
let expected_inner = [("", 1), ("a", 2), ("a/d", 1)] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
318 |
.iter() |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
319 |
.map(|(k, v)| (HgPathBuf::from_bytes(k.as_bytes()), *v)) |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
320 |
.collect(); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
321 |
|
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
322 |
let new = |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
323 |
DirsMultiset::from_dirstate(&input_map, Some(EntryState::Normal)); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
324 |
let expected = DirsMultiset { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
325 |
inner: expected_inner, |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
326 |
}; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
327 |
assert_eq!(expected, new); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
328 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
329 |
} |