FluentFieldAssertions

FluentFieldAssertions is a library that allows you to write tests in a natural language-like syntax.
With this library, you can perform field assertions in an intuitive and readable way.

Features

Uses

FluentFieldAssertions generated the following methods for each field.

```rust use fluentfieldassertions::FluentFieldAssertions;

[derive(FluentFieldAssertions)]

struct User { id: usize, name: String, age: usize, }

let user = User { id: 1, name: "Alice".to_string(), age: 17, };

// You can write tests in a natural language-like syntax. user.ideq(&1) .nameeq(&"Alice".tostring()) .agesatisfies(|age| age < &18);

// Same as above. asserteq!(user.id, 1); asserteq!(user.name, "Alice".to_string()); assert!(user.age < 18); ```

Examples

Basic struct

You can use it in the basic struct.
Each field must implement the traits Eq and Debug.

```rust use fluentfieldassertions::FluentFieldAssertions;

[derive(FluentFieldAssertions)]

struct User { id: usize, name: String, age: usize, // You can skip assertion_methods for some fields. #[assertions(skip)] score: f64, }

let user = User { id: 1, name: "Alice".to_string(), age: 17, score: 95.0, };

// You can use {field}_eq to asserteq!. user.nameeq(&"Alice".tostring()); asserteq!(user.name, "Alice".to_string()); // Same as above.

// You can use {field}_ne to assertne!. user.namene(&"Bob".tostring()); assertne!(user.name, "Bob".to_string()); // Same as above.

// You can use {field}_satisfies to assert!. user.namesatisfies(|name| name.startswith('A')); assert!(user.name.starts_with('A')); // Same as above.

// You can chain assertions as method calls. user.ideq(&1) .nameeq(&"Alice".tostring()) .agesatisfies(|age| age < &18);

// Same as above. asserteq!(user.id, 1); asserteq!(user.name, "Alice".to_string()); assert!(user.age < 18); ```

Generic struct

You can also use it in the generic struct.
In that case, Generics type T must implement the traits Eq and Debug.

```rust use core::fmt::Debug; use fluentfieldassertions::FluentFieldAssertions;

[derive(FluentFieldAssertions)]

struct Point // Generics type T must implement trait Eq and Debug. where T: Eq + Debug, { x: T, y: T, z: T, // You can skip assertionmethods for some fields. #[assertions(skip)] #[allow(deadcode)] t: T, }

let point = Point { x: 1, y: 2, z: 3, t: 4, };

point.xeq(&1).yne(&9).z_satisfies(|z| z % 3 == 0); ```