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
|
#[derive(Debug, Clone)]
#[cfg_attr(test, derive(PartialEq))]
pub enum Origin {
Context,
Addition,
Deletion,
}
impl From<char> for Origin {
fn from(c: char) -> Self {
match c {
'+' | '>' => Self::Addition,
'-' | '<' => Self::Deletion,
// ' ', '='
_ => Self::Context,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use rstest::rstest;
#[rstest(
input,
expected,
case::space(' ', &Origin::Context),
case::equals('=', &Origin::Context),
case::plus('+', &Origin::Addition),
case::greater_than('>', &Origin::Addition),
case::minus('-', &Origin::Deletion),
case::less_than('-', &Origin::Deletion),
case::other('a', &Origin::Context)
)]
fn from_char(input: char, expected: &Origin) {
assert_eq!(&Origin::from(input), expected);
}
}
|