Skip to content

Commit

Permalink
feat: mock trait derivable on struct with names fields
Browse files Browse the repository at this point in the history
  • Loading branch information
gibbz00 committed Oct 15, 2024
1 parent 15d4ef0 commit 0b2301e
Show file tree
Hide file tree
Showing 8 changed files with 412 additions and 21 deletions.
285 changes: 284 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["crates/*"]
resolver = "2"

[workspace.package]
authors = ["gibbz"]
authors = ["gibbz00 <gabrielhansson00@gmail.com>"]
edition = "2021"
exclude = ["/.github"]
license = "MIT"
Expand All @@ -12,6 +12,7 @@ repository = "https://github.com/gibbz00/mock-default"
version = "0.1.0"

[workspace.dependencies]
mock-default-macros = { path = "crates/macros" }

[workspace.lints.rust]
missing_docs = "deny"
Expand All @@ -21,6 +22,5 @@ unused_must_use = "deny"
self_named_module_files = "deny"

[profile.dev]
# https://davidlattimore.github.io/posts/2024/02/04/speeding-up-the-rust-edit-build-run-cycle.html#avoid-linking-debug-info
debug = 0
strip = "debuginfo"
17 changes: 0 additions & 17 deletions crates/common/src/lib.rs

This file was deleted.

6 changes: 5 additions & 1 deletion crates/common/Cargo.toml → crates/core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "mock-default-common"
name = "mock-default"

authors.workspace = true
edition.workspace = true
Expand All @@ -12,3 +12,7 @@ version.workspace = true
workspace = true

[dependencies]
mock-default-macros.workspace = true

[dev-dependencies]
trybuild = "1.0"
17 changes: 17 additions & 0 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! mock-default commons.
/// Mocking trait for composable test values.
///
/// Similar to [`std::default::Default`]
pub trait Mock: Sized {
/// Returns `Self` containing a non-random and valid test value
fn mock() -> Self;
}

impl<T: Mock> Mock for Option<T> {
fn mock() -> Self {
Some(Mock::mock())
}
}

pub use mock_default_macros::Mock;
Loading

0 comments on commit 0b2301e

Please sign in to comment.