]> git.proxmox.com Git - rustc.git/blob - src/doc/book/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/src/lib.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / src / doc / book / listings / ch11-writing-automated-tests / no-listing-09-guess-with-panic-msg-bug / src / lib.rs
1 pub struct Guess {
2 value: i32,
3 }
4
5 impl Guess {
6 pub fn new(value: i32) -> Guess {
7 // ANCHOR: here
8 if value < 1 {
9 panic!(
10 "Guess value must be less than or equal to 100, got {}.",
11 value
12 );
13 } else if value > 100 {
14 panic!(
15 "Guess value must be greater than or equal to 1, got {}.",
16 value
17 );
18 }
19 // ANCHOR_END: here
20
21 Guess { value }
22 }
23 }
24
25 #[cfg(test)]
26 mod tests {
27 use super::*;
28
29 #[test]
30 #[should_panic(expected = "less than or equal to 100")]
31 fn greater_than_100() {
32 Guess::new(200);
33 }
34 }