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
|
#[derive(Debug)]
pub struct Ticket {
title: String,
description: String,
status: String,
}
impl Ticket {
pub fn new(title: &str, description: &str, status: &str) -> Self {
if !(status == "To-Do" || status == "In Progress" || status == "Done") {
panic!("status not correct");
}
if title.is_empty() || description.is_empty() {
panic!("title or description is empty");
}
if title.len() > 50 {
panic!("title too long");
}
if description.len() > 500 {
panic!("description too long");
}
Self{
title: String::from(title),
description: String::from(description),
status: String::from(status),
}
}
}
fn main() {
let ticket = Ticket::new("title","desc","Done");
println!("{:?}{:?}{:?}", ticket.title, ticket.description, ticket.status);
}
#[cfg(test)]
mod tests {
use crate::*;
#[test]
#[should_panic(expected="status not correct")]
fn t0() {
Ticket::new("title","desc","status");
}
}
|