Trait StringAssertions

Source
pub trait StringAssertions {
Show 34 methods // Required methods fn is_empty(self) -> Self; fn is_not_empty(self) -> Self; fn has_char_length(self, expected_length: usize) -> Self; fn has_char_length_less_than(self, length_bound: usize) -> Self; fn has_char_length_less_than_or_equal_to(self, length_bound: usize) -> Self; fn has_char_length_greater_than(self, length_bound: usize) -> Self; fn has_char_length_greater_than_or_equal_to( self, length_bound: usize, ) -> Self; fn has_char_length_different_to(self, unexpected_length: usize) -> Self; fn has_byte_length(self, expected_length: usize) -> Self; fn has_byte_length_less_than(self, length_bound: usize) -> Self; fn has_byte_length_less_than_or_equal_to(self, length_bound: usize) -> Self; fn has_byte_length_greater_than(self, length_bound: usize) -> Self; fn has_byte_length_greater_than_or_equal_to( self, length_bound: usize, ) -> Self; fn has_byte_length_different_to(self, unexpected_length: usize) -> Self; fn contains_whitespace(self) -> Self; fn does_not_contain_whitespace(self) -> Self; fn contains_alphabetic_characters(self) -> Self; fn does_not_contain_alphabetic_characters(self) -> Self; fn contains_numeric_characters(self) -> Self; fn does_not_contain_numeric_characters(self) -> Self; fn contains_alphanumeric_characters(self) -> Self; fn does_not_contain_alphanumeric_characters(self) -> Self; fn contains_uppercase_letters(self) -> Self; fn does_not_contain_uppercase_letters(self) -> Self; fn contains_lowercase_letters(self) -> Self; fn does_not_contain_lowercase_letters(self) -> Self; fn contains_control_characters(self) -> Self; fn does_not_contain_control_characters(self) -> Self; fn is_trimmed(self) -> Self; fn is_not_trimmed(self) -> Self; fn is_ascii(self) -> Self; fn is_not_ascii(self) -> Self; fn to_chars(self) -> AssertThat<Vec<char>>; fn to_bytes(self) -> AssertThat<Vec<u8>>;
}
Expand description

An extension trait to be used on the output of assert_that with a String argument. This trait contains basic assertions on the string itself and individual characters. For comparing strings (such as contains, prefix, and suffix relations), see StringPatternAssertions.

Examples:

use kernal::prelude::*;

assert_that!("hello world!")
    .is_not_empty()
    .has_char_length(12)
    .has_byte_length_less_than(15)
    .contains_whitespace()
    .does_not_contain_uppercase_letters()
    .is_trimmed();

Required Methods§

Source

fn is_empty(self) -> Self

Asserts that the tested string is empty, i.e. contains no characters.

Source

fn is_not_empty(self) -> Self

Asserts that the tested string is not empty, i.e. contains at least one character.

Source

fn has_char_length(self, expected_length: usize) -> Self

Asserts that the number of characters in the tested string is equal to the given expected_length.

Source

fn has_char_length_less_than(self, length_bound: usize) -> Self

Asserts that the number of characters in the tested string is less than the given length_bound.

Source

fn has_char_length_less_than_or_equal_to(self, length_bound: usize) -> Self

Asserts that the number of characters in the tested string is less than or equal to the given length_bound.

Source

fn has_char_length_greater_than(self, length_bound: usize) -> Self

Asserts that the number of characters in the tested string is greater than the given length_bound.

Source

fn has_char_length_greater_than_or_equal_to(self, length_bound: usize) -> Self

Asserts that the number of characters in the tested string is greater than or equal to the given length_bound.

Source

fn has_char_length_different_to(self, unexpected_length: usize) -> Self

Asserts that the number of characters in the tested string is different to the given unexpected_length.

Source

fn has_byte_length(self, expected_length: usize) -> Self

Asserts that the number of bytes composing the tested string is equal to the given expected_length.

Source

fn has_byte_length_less_than(self, length_bound: usize) -> Self

Asserts that the number of bytes composing the tested string is less than the given length_bound.

Source

fn has_byte_length_less_than_or_equal_to(self, length_bound: usize) -> Self

Asserts that the number of bytes composing the tested string is less than or equal to the given length_bound.

Source

fn has_byte_length_greater_than(self, length_bound: usize) -> Self

Asserts that the number of bytes composing the tested string is greater than the given length_bound.

Source

fn has_byte_length_greater_than_or_equal_to(self, length_bound: usize) -> Self

Asserts that the number of bytes composing the tested string is greater than or equal to the given length_bound.

Source

fn has_byte_length_different_to(self, unexpected_length: usize) -> Self

Asserts that the number of bytes composing the tested string is different to the given unexpected_length.

Source

fn contains_whitespace(self) -> Self

Asserts that the tested string contains at least one character which is classified as whitespace according to char::is_whitespace.

Source

fn does_not_contain_whitespace(self) -> Self

Asserts that the tested string contains no character which is classified as whitespace according to char::is_whitespace.

Source

fn contains_alphabetic_characters(self) -> Self

Asserts that the tested string contains at least one character which is classified as alphabetic according to char::is_alphabetic.

Source

fn does_not_contain_alphabetic_characters(self) -> Self

Asserts that the tested string contains no character which is classified as alphabetic according to char::is_alphabetic.

Source

fn contains_numeric_characters(self) -> Self

Asserts that the tested string contains at least one character which is classified as numeric according to char::is_numeric.

Source

fn does_not_contain_numeric_characters(self) -> Self

Asserts that the tested string contains no character which is classified as numeric according to char::is_numeric.

Source

fn contains_alphanumeric_characters(self) -> Self

Asserts that the tested string contains at least one character which is classified as alphanumeric according to char::is_alphanumeric.

Source

fn does_not_contain_alphanumeric_characters(self) -> Self

Asserts that the tested string contains no character which is classified as alphanumeric according to char::is_alphanumeric.

Source

fn contains_uppercase_letters(self) -> Self

Asserts that the tested string contains at least one character which is classified as an uppercase letter according to char::is_uppercase.

Source

fn does_not_contain_uppercase_letters(self) -> Self

Asserts that the tested string contains no character which is classified as an uppercase letter according to char::is_uppercase.

Source

fn contains_lowercase_letters(self) -> Self

Asserts that the tested string contains at least one character which is classified as a lowercase letter according to char::is_lowercase.

Source

fn does_not_contain_lowercase_letters(self) -> Self

Asserts that the tested string contains no character which is classified as a lowercase letter according to char::is_lowercase.

Source

fn contains_control_characters(self) -> Self

Asserts that the tested string contains at least one character which is classified as a control character according to char::is_control.

Source

fn does_not_contain_control_characters(self) -> Self

Asserts that the tested string contains no character which is classified as a control character according to char::is_control.

Source

fn is_trimmed(self) -> Self

Asserts that the tested string is trimmed, i.e. does not start and does not end with whitespace.

Source

fn is_not_trimmed(self) -> Self

Asserts that the tested string is not trimmed, i.e. starts or ends with whitespace.

Source

fn is_ascii(self) -> Self

Asserts that the tested string is pure ASCII, i.e. contains no non-ASCII characters according to char::is_ascii.

Source

fn is_not_ascii(self) -> Self

Asserts that the tested string is not pure ASCII, i.e. contains at least one non-ASCII character according to char::is_ascii.

Source

fn to_chars(self) -> AssertThat<Vec<char>>

Converts the tested string to a Vec of the chars contained in it and allows assertions on them.

Source

fn to_bytes(self) -> AssertThat<Vec<u8>>

Converts the tested string to a Vec of the bytes (u8) contained in it and allows assertions on them.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§