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
81
82
83
use super::action::Action;
#[derive(Debug)]
pub struct EditContext {
action: Option<Action>,
content: Option<String>,
}
impl EditContext {
#[must_use]
#[inline]
pub const fn new() -> Self {
Self {
action: None,
content: None,
}
}
#[must_use]
#[inline]
pub const fn action(mut self, action: Action) -> Self {
self.action = Some(action);
self
}
#[must_use]
#[inline]
pub fn content(mut self, content: &str) -> Self {
self.content = Some(content.to_owned());
self
}
#[must_use]
#[inline]
pub const fn get_action(&self) -> &Option<Action> {
&self.action
}
#[must_use]
#[inline]
pub const fn get_content(&self) -> &Option<String> {
&self.content
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn empty() {
let edit_context = EditContext::new();
assert_eq!(edit_context.get_action(), &None);
assert_eq!(edit_context.get_content(), &None);
}
#[test]
fn with_action() {
let edit_context = EditContext::new().action(Action::Break);
assert_eq!(edit_context.get_action(), &Some(Action::Break));
assert_eq!(edit_context.get_content(), &None);
}
#[test]
fn with_content() {
let edit_context = EditContext::new().content("test content");
assert_eq!(edit_context.get_action(), &None);
assert_eq!(edit_context.get_content(), &Some(String::from("test content")));
}
#[test]
fn with_content_and_action() {
let edit_context = EditContext::new().action(Action::Edit).content("test content");
assert_eq!(edit_context.get_action(), &Some(Action::Edit));
assert_eq!(edit_context.get_content(), &Some(String::from("test content")));
}
}