]> git.proxmox.com Git - rustc.git/blob - src/doc/book/listings/ch11-writing-automated-tests/listing-11-06/src/lib.rs
New upstream version 1.50.0+dfsg1
[rustc.git] / src / doc / book / listings / ch11-writing-automated-tests / listing-11-06 / src / lib.rs
1 #[derive(Debug)]
2 struct Rectangle {
3 width: u32,
4 height: u32,
5 }
6
7 impl Rectangle {
8 fn can_hold(&self, other: &Rectangle) -> bool {
9 self.width > other.width && self.height > other.height
10 }
11 }
12
13 // ANCHOR: here
14 #[cfg(test)]
15 mod tests {
16 use super::*;
17
18 #[test]
19 fn larger_can_hold_smaller() {
20 let larger = Rectangle {
21 width: 8,
22 height: 7,
23 };
24 let smaller = Rectangle {
25 width: 5,
26 height: 1,
27 };
28
29 assert!(larger.can_hold(&smaller));
30 }
31 }
32 // ANCHOR_END: here