summaryrefslogtreecommitdiffstats
path: root/vendor/proptest/src/macros.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/proptest/src/macros.rs
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/proptest/src/macros.rs')
-rw-r--r--vendor/proptest/src/macros.rs93
1 files changed, 93 insertions, 0 deletions
diff --git a/vendor/proptest/src/macros.rs b/vendor/proptest/src/macros.rs
new file mode 100644
index 000000000..c76989eb6
--- /dev/null
+++ b/vendor/proptest/src/macros.rs
@@ -0,0 +1,93 @@
+//-
+// Copyright 2017, 2018 Jason Lingle
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Macros for internal use to reduce boilerplate.
+
+// Pervasive internal sugar
+macro_rules! mapfn {
+ ($({#[$allmeta:meta]})* $(#[$meta:meta])* [$($vis:tt)*]
+ fn $name:ident[$($gen:tt)*]($parm:ident: $input:ty) -> $output:ty {
+ $($body:tt)*
+ }) => {
+ $(#[$allmeta])* $(#[$meta])*
+ #[derive(Clone, Copy, Debug)]
+ $($vis)* struct $name;
+ $(#[$allmeta])*
+ impl $($gen)* $crate::strategy::statics::MapFn<$input> for $name {
+ type Output = $output;
+ fn apply(&self, $parm: $input) -> $output {
+ $($body)*
+ }
+ }
+ }
+}
+
+macro_rules! delegate_vt_0 {
+ () => {
+ fn current(&self) -> Self::Value {
+ self.0.current()
+ }
+
+ fn simplify(&mut self) -> bool {
+ self.0.simplify()
+ }
+
+ fn complicate(&mut self) -> bool {
+ self.0.complicate()
+ }
+ };
+}
+
+macro_rules! opaque_strategy_wrapper {
+ ($({#[$allmeta:meta]})*
+ $(#[$smeta:meta])*
+ pub struct $stratname:ident
+ [$($sgen:tt)*][$($swhere:tt)*]
+ ($innerstrat:ty) -> $stratvtty:ty;
+
+ $(#[$vmeta:meta])* pub struct $vtname:ident
+ [$($vgen:tt)*][$($vwhere:tt)*]
+ ($innervt:ty) -> $actualty:ty;
+ ) => {
+ $(#[$allmeta])*
+ $(#[$smeta])*
+ #[must_use = "strategies do nothing unless used"]
+ pub struct $stratname $($sgen)* ($innerstrat)
+ $($swhere)*;
+
+ $(#[$allmeta])*
+ $(#[$vmeta])* pub struct $vtname $($vgen)* ($innervt) $($vwhere)*;
+
+ $(#[$allmeta])*
+ impl $($sgen)* Strategy for $stratname $($sgen)* $($swhere)* {
+ type Tree = $stratvtty;
+ type Value = $actualty;
+ fn new_tree(&self, runner: &mut TestRunner) -> NewTree<Self> {
+ self.0.new_tree(runner).map($vtname)
+ }
+ }
+
+ $(#[$allmeta])*
+ impl $($vgen)* ValueTree for $vtname $($vgen)* $($vwhere)* {
+ type Value = $actualty;
+
+ delegate_vt_0!();
+ }
+ }
+}
+
+// Example: unwrap_or!(result, err => handle_err(err));
+macro_rules! unwrap_or {
+ ($unwrap: expr, $err: ident => $on_err: expr) => {
+ match $unwrap {
+ Ok(ok) => ok,
+ Err($err) => $on_err,
+ }
+ };
+}