<span class="filename">Filename: src/lib.rs</span>
-```rust
+```rust,panics
# fn main() {}
#[cfg(test)]
mod tests {
method by replacing the greater-than sign with a less-than sign when it
compares the lengths:
-```rust
+```rust,not_desired_behavior
# fn main() {}
# #[derive(Debug)]
# pub struct Rectangle {
uses `assert_eq!` fails. Change the implementation of the `add_two` function to
instead add `3`:
-```rust
+```rust,not_desired_behavior
# fn main() {}
pub fn add_two(a: i32) -> i32 {
a + 3
Let’s introduce a bug into this code by changing `greeting` to not include
`name` to see what this test failure looks like:
-```rust
+```rust,not_desired_behavior
# fn main() {}
pub fn greeting(name: &str) -> String {
String::from("Hello!")
In addition to checking that our code returns the correct values we expect,
it’s also important to check that our code handles error conditions as we
expect. For example, consider the `Guess` type that we created in Chapter 9,
-Listing 9-9. Other code that uses `Guess` depends on the guarantee that `Guess`
+Listing 9-10. Other code that uses `Guess` depends on the guarantee that `Guess`
instances will contain only values between 1 and 100. We can write a test that
ensures that attempting to create a `Guess` instance with a value outside that
range panics.
Looks good! Now let’s introduce a bug in our code by removing the condition
that the `new` function will panic if the value is greater than 100:
-```rust
+```rust,not_desired_behavior
# fn main() {}
# pub struct Guess {
# value: i32,
fails, let’s again introduce a bug into our code by swapping the bodies of the
`if value < 1` and the `else if value > 100` blocks:
-```rust,ignore
+```rust,ignore,not_desired_behavior
if value < 1 {
panic!("Guess value must be less than or equal to 100, got {}.", value);
} else if value > 100 {