Skip to content

Commit e0d3c57

Browse files
committed
chore: use nutype_test_util for more ergonomic newtypes in tests
1 parent 868abcd commit e0d3c57

File tree

3 files changed

+23
-36
lines changed

3 files changed

+23
-36
lines changed

Cargo.lock

Lines changed: 16 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ dialoguer = "0.11.0"
5454
clap_complete_command = { version="0.6.1", features = ["nushell", "fig", "carapace"] }
5555
clap-verbosity-flag = "3.0.3"
5656
itertools = "0.14.0"
57+
nutype_test_util = "0.1.1"
5758

5859
[dev-dependencies]
5960
pretty_assertions = "1.4"

src/config.rs

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -187,45 +187,15 @@ impl FromStr for Ref {
187187
}
188188
}
189189

190-
#[cfg(test)]
191-
impl From<&str> for RepoOwner {
192-
fn from(value: &str) -> Self {
193-
Self::try_new(value).unwrap()
194-
}
195-
}
196-
#[cfg(test)]
197-
impl From<&str> for RepoName {
198-
fn from(value: &str) -> Self {
199-
Self::try_new(value).unwrap()
200-
}
201-
}
202-
#[cfg(test)]
203-
impl From<&str> for BranchName {
204-
fn from(value: &str) -> Self {
205-
Self::try_new(value).unwrap()
206-
}
207-
}
208-
#[cfg(test)]
209-
impl From<&str> for Commit {
210-
fn from(value: &str) -> Self {
211-
Self::try_new(value).unwrap()
212-
}
213-
}
214-
215190
/// Number of a pull request
191+
#[nutype_test_util::derive(From)]
216192
#[nutype(const_fn, derive(Eq, PartialEq, Display, Debug, FromStr, Copy, Clone))]
217193
pub struct PrNumber(NonZeroU32);
218194

219-
#[cfg(test)]
220-
impl From<u32> for PrNumber {
221-
fn from(value: u32) -> Self {
222-
Self::new(NonZeroU32::new(value).unwrap())
223-
}
224-
}
225-
226195
/// Represents owner of a repository
227196
///
228197
/// E.g. in `helix-editor/helix/master`, this is `helix-editor`
198+
#[nutype_test_util::derive(From)]
229199
#[nutype(
230200
validate(not_empty),
231201
derive(
@@ -237,6 +207,7 @@ pub struct RepoOwner(String);
237207
/// Represents name of a repository
238208
///
239209
/// E.g. in `helix-editor/helix/master`, this is `helix`
210+
#[nutype_test_util::derive(From)]
240211
#[nutype(
241212
validate(not_empty),
242213
derive(
@@ -248,6 +219,7 @@ pub struct RepoName(String);
248219
/// Name of a branch in git
249220
///
250221
/// E.g. in `helix-editor/helix/master`, this is `master`
222+
#[nutype_test_util::derive(From)]
251223
#[nutype(
252224
validate(not_empty),
253225
derive(
@@ -267,6 +239,7 @@ impl FromStr for BranchName {
267239
}
268240

269241
/// File name of a patch
242+
#[nutype_test_util::derive(From)]
270243
#[nutype(validate(predicate = |p| !p.as_os_str().is_empty()), derive(Hash, Eq, PartialEq, Debug, AsRef, Deserialize, Clone, FromStr))]
271244
pub struct PatchName(PathBuf);
272245

@@ -277,6 +250,7 @@ impl Display for PatchName {
277250
}
278251

279252
/// Represents a git commit hash
253+
#[nutype_test_util::derive(From)]
280254
#[nutype(
281255
validate(not_empty, predicate = is_valid_commit_hash),
282256
derive(Debug, Eq, PartialEq, Ord, PartialOrd, Clone, AsRef)

0 commit comments

Comments
 (0)