-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathlib.rs
More file actions
75 lines (67 loc) · 1.92 KB
/
Copy pathlib.rs
File metadata and controls
75 lines (67 loc) · 1.92 KB
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
// TODO: Implement `Ticket::assigned_to`.
// Return the name of the person assigned to the ticket, if the ticket is in progress.
// Otherwise Panic with message - Only `In-Progress` tickets can be assigned to someone.
#[derive(Debug, PartialEq)]
struct Ticket {
title: String,
description: String,
status: Status,
}
#[derive(Debug, PartialEq)]
enum Status {
ToDo,
InProgress { assigned_to: String },
Done,
}
impl Ticket {
pub fn new(title: String, description: String, status: Status) -> Ticket {
if title.is_empty() {
panic!("Title cannot be empty");
}
if title.len() > 50 {
panic!("Title cannot be longer than 50 bytes");
}
if description.is_empty() {
panic!("Description cannot be empty");
}
if description.len() > 500 {
panic!("Description cannot be longer than 500 bytes");
}
Ticket {
title,
description,
status,
}
}
pub fn assigned_to(&self) -> &str {
todo!()
}
}
#[cfg(test)]
mod tests {
use super::*;
use common::{valid_description, valid_title};
#[test]
#[should_panic(expected = "Only `In-Progress` tickets can be assigned to someone")]
fn test_todo() {
let ticket = Ticket::new(valid_title(), valid_description(), Status::ToDo);
ticket.assigned_to();
}
#[test]
#[should_panic(expected = "Only `In-Progress` tickets can be assigned to someone")]
fn test_done() {
let ticket = Ticket::new(valid_title(), valid_description(), Status::Done);
ticket.assigned_to();
}
#[test]
fn test_in_progress() {
let ticket = Ticket::new(
valid_title(),
valid_description(),
Status::InProgress {
assigned_to: "Alice".to_string(),
},
);
assert_eq!(ticket.assigned_to(), "Alice");
}
}