|
| 1 | +// Copyright 2026 Gregory Petrosyan <pgregory@pgregory.net> |
| 2 | +// |
| 3 | +// This Source Code Form is subject to the terms of the Mozilla Public |
| 4 | +// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 | +// file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 6 | + |
| 7 | +//! Integration tests for `#[derive(chaos_theory::Arbitrary)]`. |
| 8 | +
|
| 9 | +#![cfg(feature = "derive")] |
| 10 | + |
| 11 | +use chaos_theory::{Arbitrary, Source, check}; |
| 12 | + |
| 13 | +include!("../../testdata/derive_cases.rs"); |
| 14 | + |
| 15 | +fn assert_reconstruct<T>(src: &mut Source, example_label: &str, value_label: &str) |
| 16 | +where |
| 17 | + T: chaos_theory::Arbitrary + core::fmt::Debug + PartialEq, |
| 18 | +{ |
| 19 | + let example: T = src.any(example_label); |
| 20 | + let value = src.as_raw().any(value_label, Some(&example)); |
| 21 | + assert_eq!(value, example); |
| 22 | +} |
| 23 | + |
| 24 | +#[test] |
| 25 | +fn derive_reconstructs_examples() { |
| 26 | + check(|src| { |
| 27 | + assert_reconstruct::<Point>(src, "point_example", "point_value"); |
| 28 | + assert_reconstruct::<Triple>(src, "triple_example", "triple_value"); |
| 29 | + assert_reconstruct::<Marker>(src, "marker_example", "marker_value"); |
| 30 | + assert_reconstruct::<Imported>(src, "imported_example", "imported_value"); |
| 31 | + assert_reconstruct::<Wrapper<u16>>(src, "wrapper_example", "wrapper_value"); |
| 32 | + assert_reconstruct::<Action<u8>>(src, "action_example", "action_value"); |
| 33 | + }); |
| 34 | +} |
0 commit comments