summaryrefslogtreecommitdiff
path: root/ex5_3/src/main.rs
blob: 353a3e4022d829cded6467be01c721eca41e0e73 (plain)
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
#[derive(Debug, PartialEq)]
struct Ticket {
    title: String,
    description: String,
    status: Status,
}

#[derive(Debug, PartialEq)]
enum Status {
    ToDo,
    InProgress { assigned_to: String },
    Done,
}

impl Ticket {
    fn assigned_to(&self) -> String {
        match self.status {
            Status::InProgress { ref assigned_to } => {
                assigned_to.clone()
            }
            _ => panic!("not in progress")
        }
    }
}

fn main() {
    println!("Hello, world!");
}

#[cfg(test)]
mod tests {
    use crate::*;

    #[test]
    fn t0() {
        let t = Ticket{
            title: String::from("t"),
            description: String::from("d"),
            status: Status::InProgress{
                assigned_to: String::from("at")
            },
        };
        assert_eq!(t.assigned_to(), "at");
    }

    #[test]
    #[should_panic(expected = "not in progress")]
    fn t1 () {
        let t = Ticket{
            title: String::from("t"),
            description: String::from("d"),
            status: Status::Done,
        };
        _ = t.assigned_to();
    }
}