Mercurial > public > mercurial-scm > hg
annotate rust/hg-core/src/testing.rs @ 51117:532e74ad3ff6
rust: run a clippy pass with the latest stable version
Our current version of clippy is older than the latest stable.
The newest version has new lints that are moslty good advice, so let's apply
them ahead of time. This has the added benefit of reducing the noise for
developpers like myself that use clippy as an IDE helper, as well as being
more prepared for a future clippy upgrade.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Mon, 06 Nov 2023 11:06:08 +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> { |
50976
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]), |
50976
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]), |
50976
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> { |
50976
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 } |