{"id":16221549,"url":"https://github.com/poi2/fluent_field_assertions","last_synced_at":"2025-03-19T11:31:04.595Z","repository":{"id":171986622,"uuid":"648697637","full_name":"poi2/fluent_field_assertions","owner":"poi2","description":"Fluent field assertions for Rust","archived":false,"fork":false,"pushed_at":"2024-04-22T14:57:49.000Z","size":23,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-17T06:35:48.881Z","etag":null,"topics":["rust","rust-macro"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/poi2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-02T15:22:35.000Z","updated_at":"2024-04-22T14:57:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"16f7687e-0b27-4234-8377-b824033af2bb","html_url":"https://github.com/poi2/fluent_field_assertions","commit_stats":null,"previous_names":["poi2/fluent_field_assertions"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poi2%2Ffluent_field_assertions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poi2%2Ffluent_field_assertions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poi2%2Ffluent_field_assertions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poi2%2Ffluent_field_assertions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/poi2","download_url":"https://codeload.github.com/poi2/fluent_field_assertions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244416936,"owners_count":20449367,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rust","rust-macro"],"created_at":"2024-10-10T12:08:44.999Z","updated_at":"2025-03-19T11:31:04.321Z","avatar_url":"https://github.com/poi2.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FluentFieldAssertions\n\nFluentFieldAssertions is a library that allows you to write tests in a natural language-like syntax.  \nWith this library, you can perform field assertions in an intuitive and readable way.\n\n## Features\n\n- Natural Language Syntax: You can write test code in a syntax that closely resembles natural language.\n- Method Chaining: You can chain assertions as method calls, allowing you to express multiple assertions in a single statement.\n- Readability and Maintainability: The code becomes simple and readable, improving the maintainability of your tests.\n\n## Uses\n\nFluentFieldAssertions generated the following methods for each field.\n\n- `fn {field}_eq(\u0026self, expected: {field_type}) -\u003e \u0026Self`\n  - Asserts that the field is equal to the expected value.\n- `fn {field}_ne(\u0026self, expected: {field_type}) -\u003e \u0026Self`\n  - Asserts that the field is not equal to the expected value.\n- `fn {field}_satisfies(\u0026self, pred: impl FnOnce(\u0026{field_type}) -\u003e bool) -\u003e \u0026Self`\n  - Asserts that the field satisfies the predicate.\n\n```rust\nuse fluent_field_assertions::FluentFieldAssertions;\n\n#[derive(FluentFieldAssertions)]\nstruct User {\n    id: usize,\n    name: String,\n    age: usize,\n}\n\nlet user = User {\n    id: 1,\n    name: \"Alice\".to_string(),\n    age: 17,\n};\n\n// You can write tests in a natural language-like syntax.\nuser.id_eq(\u00261)\n    .name_eq(\u0026\"Alice\".to_string())\n    .age_satisfies(|age| age \u003c \u002618);\n\n// Same as above.\nassert_eq!(user.id, 1);\nassert_eq!(user.name, \"Alice\".to_string());\nassert!(user.age \u003c 18);\n```\n\n## Examples\n\n### Basic struct\n\nYou can use it in the basic struct.  \nEach field must implement the traits `Eq` and `Debug`.\n\n```rust\nuse fluent_field_assertions::FluentFieldAssertions;\n\n#[derive(FluentFieldAssertions)]\nstruct User {\n    id: usize,\n    name: String,\n    age: usize,\n    // You can skip assertion_methods for some fields.\n    #[assertions(skip)]\n    score: f64,\n}\n\nlet user = User {\n    id: 1,\n    name: \"Alice\".to_string(),\n    age: 17,\n    score: 95.0,\n};\n\n// You can use `{field}_eq` to assert_eq!.\nuser.name_eq(\u0026\"Alice\".to_string());\nassert_eq!(user.name, \"Alice\".to_string()); // Same as above.\n\n// You can use `{field}_ne` to assert_ne!.\nuser.name_ne(\u0026\"Bob\".to_string());\nassert_ne!(user.name, \"Bob\".to_string()); // Same as above.\n\n// You can use `{field}_satisfies` to assert!.\nuser.name_satisfies(|name| name.starts_with('A'));\nassert!(user.name.starts_with('A')); // Same as above.\n\n// You can chain assertions as method calls.\nuser.id_eq(\u00261)\n    .name_eq(\u0026\"Alice\".to_string())\n    .age_satisfies(|age| age \u003c \u002618);\n\n// Same as above.\nassert_eq!(user.id, 1);\nassert_eq!(user.name, \"Alice\".to_string());\nassert!(user.age \u003c 18);\n```\n\n### Generic struct\n\nYou can also use it in the generic struct.  \nIn that case, Generics type `T` must implement the traits `Eq` and `Debug`.\n\n```rust\nuse core::fmt::Debug;\nuse fluent_field_assertions::FluentFieldAssertions;\n\n#[derive(FluentFieldAssertions)]\nstruct Point\u003cT\u003e\n// Generics type `T` must implement trait `Eq` and `Debug`.\nwhere\n    T: Eq + Debug,\n{\n    x: T,\n    y: T,\n    z: T,\n    // You can skip assertion_methods for some fields.\n    #[assertions(skip)]\n    #[allow(dead_code)]\n    t: T,\n}\n\nlet point = Point {\n    x: 1,\n    y: 2,\n    z: 3,\n    t: 4,\n};\n\npoint.x_eq(\u00261).y_ne(\u00269).z_satisfies(|z| z % 3 == 0);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoi2%2Ffluent_field_assertions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpoi2%2Ffluent_field_assertions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoi2%2Ffluent_field_assertions/lists"}