1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use quickcheck::{Arbitrary, Gen};
use strum_macros::EnumIter;
#[derive(Clone, Copy, Debug, PartialEq, Eq, EnumIter)]
#[repr(i32)]
pub enum Code {
InitialNotMatchedToAuthor = 3,
UnparsableAuthorFile,
StaleAuthor,
DuplicatedTrailers,
PivotalTrackerIdMissing,
JiraIssueKeyMissing,
GitHubIdMissing,
SubjectNotSeparateFromBody,
SubjectLongerThan72Characters,
SubjectNotCapitalized,
SubjectEndsWithPeriod,
BodyWiderThan72Characters,
NotConventionalCommit,
NotEmojiLog,
}
impl Arbitrary for Code {
fn arbitrary(g: &mut Gen) -> Self {
*g.choose(&Self::get_codes()).unwrap()
}
fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
let codes = Self::get_codes();
let index = codes.iter().position(|other| self.eq(other));
match index {
None | Some(0) => quickcheck::empty_shrinker(),
Some(index) => codes
.get(index - 1)
.map_or(quickcheck::empty_shrinker(), |item| {
quickcheck::single_shrinker(*item)
}),
}
}
}
impl Code {
const fn get_codes() -> [Self; 14] {
[
Self::InitialNotMatchedToAuthor,
Self::UnparsableAuthorFile,
Self::StaleAuthor,
Self::DuplicatedTrailers,
Self::PivotalTrackerIdMissing,
Self::JiraIssueKeyMissing,
Self::GitHubIdMissing,
Self::SubjectNotSeparateFromBody,
Self::SubjectLongerThan72Characters,
Self::SubjectNotCapitalized,
Self::SubjectEndsWithPeriod,
Self::BodyWiderThan72Characters,
Self::NotConventionalCommit,
Self::NotEmojiLog,
]
}
}