Mercurial > hg
annotate rust/hg-core/src/testing.rs @ 51470:406b413e3cf2 stable
rust-filepatterns: export glob_to_re function
Making this function public should not risk freezing the internal API,
and it can be useful for all downstream code that needs to perform
glob matching against byte strings, such as RHGitaly where it will
be useful to match on branches and tags.
author | Georges Racinet <georges.racinet@octobus.net> |
---|---|
date | Mon, 11 Mar 2024 13:23:18 +0100 |
parents | 4c5f6e95df84 |
children |
rev | line source |
---|---|
41241
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
1 // testing.rs |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
2 // |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
3 // Copyright 2018 Georges Racinet <georges.racinet@octobus.net> |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
4 // |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
5 // This software may be used and distributed according to the terms of the |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
6 // GNU General Public License version 2 or any later version. |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
7 |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
8 use crate::{Graph, GraphError, Revision, NULL_REVISION}; |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
9 |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
10 /// A stub `Graph`, same as the one from `test-ancestor.py` |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
11 /// |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
12 /// o 13 |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
13 /// | |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
14 /// | o 12 |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
15 /// | | |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
16 /// | | o 11 |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
17 /// | | |\ |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
18 /// | | | | o 10 |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
19 /// | | | | | |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
20 /// | o---+ | 9 |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
21 /// | | | | | |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
22 /// o | | | | 8 |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
23 /// / / / / |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
24 /// | | o | 7 |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
25 /// | | | | |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
26 /// o---+ | 6 |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
27 /// / / / |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
28 /// | | o 5 |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
29 /// | |/ |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
30 /// | o 4 |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
31 /// | | |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
32 /// o | 3 |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
33 /// | | |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
34 /// | o 2 |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
35 /// |/ |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
36 /// o 1 |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
37 /// | |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
38 /// o 0 |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
39 #[derive(Clone, Debug)] |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
40 pub struct SampleGraph; |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
41 |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
42 impl Graph for SampleGraph { |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
43 fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> { |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
41241
diff
changeset
|
44 let null_rev = NULL_REVISION.0; |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
41241
diff
changeset
|
45 let res = match rev.0 { |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
41241
diff
changeset
|
46 0 => Ok([null_rev, null_rev]), |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
41241
diff
changeset
|
47 1 => Ok([0, null_rev]), |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
41241
diff
changeset
|
48 2 => Ok([1, null_rev]), |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
41241
diff
changeset
|
49 3 => Ok([1, null_rev]), |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
41241
diff
changeset
|
50 4 => Ok([2, null_rev]), |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
41241
diff
changeset
|
51 5 => Ok([4, null_rev]), |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
41241
diff
changeset
|
52 6 => Ok([4, null_rev]), |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
41241
diff
changeset
|
53 7 => Ok([4, null_rev]), |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
41241
diff
changeset
|
54 8 => Ok([null_rev, null_rev]), |
41241
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
55 9 => Ok([6, 7]), |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
41241
diff
changeset
|
56 10 => Ok([5, null_rev]), |
41241
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
57 11 => Ok([3, 7]), |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
41241
diff
changeset
|
58 12 => Ok([9, null_rev]), |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
41241
diff
changeset
|
59 13 => Ok([8, null_rev]), |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
41241
diff
changeset
|
60 r => Err(GraphError::ParentOutOfRange(Revision(r))), |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
41241
diff
changeset
|
61 }; |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
41241
diff
changeset
|
62 match res { |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
41241
diff
changeset
|
63 Ok([a, b]) => Ok([Revision(a), Revision(b)]), |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
41241
diff
changeset
|
64 Err(e) => Err(e), |
41241
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
65 } |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
66 } |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
67 } |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
68 |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
69 // A Graph represented by a vector whose indices are revisions |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
70 // and values are parents of the revisions |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
71 pub type VecGraph = Vec<[Revision; 2]>; |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
72 |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
73 impl Graph for VecGraph { |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
74 fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> { |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
41241
diff
changeset
|
75 Ok(self[rev.0 as usize]) |
41241
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
76 } |
168041fa6d5f
rust: factorized testing Graphs
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
77 } |