Skip to content

Commit

Permalink
Add comparison example for assert_ok
Browse files Browse the repository at this point in the history
  • Loading branch information
joelparkerhenderson committed Sep 25, 2024
1 parent f21d41f commit ea4f31b
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions tests/comparison_examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use assertables::*;
///
/// assert_infix!(a > b);
/// // assertion failed: `assert_infix!(a > b)`
/// // https://docs.rs/assertables/8.7.0/assertables/macro.assert_infix.html
/// // https://docs.rs/assertables/8.9.0/assertables/macro.assert_infix.html
/// // a label: `a`,
/// // a debug: `1`,
/// // b label: `b`,
Expand Down Expand Up @@ -59,7 +59,7 @@ fn greater_than() {
///
/// assert_infix!(a, b, delta);
/// // assertion failed: `assert_in_delta!(a, b, delta)`
/// // https://docs.rs/assertables/8.7.0/assertables/macro.assert_in_delta.html
/// // https://docs.rs/assertables/8.9.0/assertables/macro.assert_in_delta.html
/// // a label: `a`,
/// // a debug: `10`,
/// // b label: `b`,
Expand All @@ -85,6 +85,40 @@ fn are_two_numbers_near() {

}

/// Verify a Result is Ok.
///
/// This example shows how to verify that a Result enumeration is Ok.
///
/// ```ignore
/// pub fn positive(i: i8) -> Result<i8, i8> {
/// if i > 0 { Ok(i) } else { Err(i) }
/// }
///
/// assert_eq!(positive(-1).is_ok());
/// // assertion failed: positive(-1).is_ok()
///
/// assert_fs_read_to_string_eq!(a_path, b_path);
/// // assertion failed: `assert_ok!(a)`
/// // https://docs.rs/assertables/8.9.0/assertables/macro.assert_ok.html
/// // a label: `positive(-1)`,
/// // a debug: `Err(-1)`
/// ```
///
#[test]
fn verify_ok() {

pub fn positive(i: i8) -> Result<i8, i8> {
if i > 0 { Ok(i) } else { Err(i) }
}

// Basic Rust
assert!(positive(1).is_ok());

// Assertables
assert_ok!(positive(1));

}

/// Compare text file strings.
///
/// This example shows two file system paths, and how to read them into strings.
Expand All @@ -100,7 +134,7 @@ fn are_two_numbers_near() {
///
/// assert_fs_read_to_string_eq!(a_path, b_path);
/// // assertion failed: `assert_fs_read_to_string_eq!(a_path, b_path)`
/// // https://docs.rs/assertables/8.7.0/assertables/macro.assert_fs_read_to_string_eq.html
/// // https://docs.rs/assertables/8.9.0/assertables/macro.assert_fs_read_to_string_eq.html
/// // a_path label: `a_path`,
/// // a_path debug: `"alfa.txt"`,
/// // b_path label: `b_path`,
Expand Down Expand Up @@ -138,7 +172,7 @@ fn compare_text_file_strings() {
///
/// assert_command_stdout_contains!(command, containee);
/// // assertion failed: `assert_command_stdout_contains!(command, containee)`
/// // https://docs.rs/assertables/8.7.0/assertables/macro.assert_command_stdout_contains.html
/// // https://docs.rs/assertables/8.9.0/assertables/macro.assert_command_stdout_contains.html
/// // command label: `command`,
/// // command debug: `"echo" "alfa"`,
/// // containee label: `containee`,
Expand Down

0 comments on commit ea4f31b

Please sign in to comment.