1#[derive(Clone, Eq, PartialEq, Debug)]
2pub struct Comment {
3 kind: char,
4 content: String,
5}
6
7impl Comment {
8 pub(super) fn new(kind: char, content: String) -> Comment {
9 Comment { kind, content }
10 }
11
12 pub fn kind(&self) -> char {
13 self.kind
14 }
15
16 pub fn comment(&self) -> &str {
17 &self.content
18 }
19}
20
21#[cfg(test)]
23mod tests {
24 use super::*;
25
26 fn make_comment() -> Comment {
27 Comment::new('X', String::from("Comment"))
28 }
29
30 #[test]
31 fn test_func_new() {
32 assert_eq!(
33 make_comment(),
34 Comment {
35 kind: 'X',
36 content: String::from("Comment")
37 },
38 );
39 }
40
41 #[test]
42 fn test_func_kind() {
43 let comment = make_comment();
44
45 assert_eq!(comment.kind(), 'X');
46 }
47
48 #[test]
49 fn test_func_content() {
50 let comment = make_comment();
51
52 assert_eq!(comment.comment(), "Comment");
53 }
54}
55