Skip to content

Commit 42cec27

Browse files
committed
Include all docs in the crate documentation
1 parent bedacdc commit 42cec27

File tree

7 files changed

+43
-5
lines changed

7 files changed

+43
-5
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ you can use to reproduce the case.
4848

4949
## Documentation
5050

51-
- API docs: https://docs.rs/chaos_theory
52-
- FAQ: [docs/FAQ.md](./docs/FAQ.md)
53-
- Guide: [docs/guide.md](./docs/guide.md)
51+
https://docs.rs/chaos_theory
5452

5553
## Status
5654

File renamed without changes.
File renamed without changes.

docs/guide.md renamed to chaos_theory/docs/guide.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ often enough to spot the issue immediately.
4242
`select` is how you define structured choices:
4343

4444
```rust
45+
# fn prop(src: &mut chaos_theory::Source) {
4546
src.select("action", &["insert", "remove", "get"], |src, action, _ix| {
4647
match action {
4748
"insert" => { /* ... */ }
@@ -50,6 +51,7 @@ src.select("action", &["insert", "remove", "get"], |src, action, _ix| {
5051
_ => unreachable!(),
5152
}
5253
});
54+
# }
5355
```
5456

5557
You should not encode a variant choice as `any::<u8>()` or a random number. Use
@@ -62,10 +64,12 @@ You should not encode a variant choice as `any::<u8>()` or a random number. Use
6264
```rust
6365
use chaos_theory::Effect;
6466

67+
# fn prop(src: &mut chaos_theory::Source) {
6568
src.repeat("step", |src| {
6669
// perform one step
6770
Effect::Success
6871
});
72+
# }
6973
```
7074

7175
`Effect` matters:
@@ -81,10 +85,12 @@ Honest `Effect` values make exploration and minimization much more efficient.
8185
Don't do this:
8286

8387
```rust
88+
# fn prop(src: &mut chaos_theory::Source) {
8489
let n: usize = src.any("n");
8590
for _ in 0..n {
8691
/* use src here */
8792
}
93+
# }
8894
```
8995

9096
Use `repeat` instead. `repeat` is structured and minimizes well, while manual
@@ -93,8 +99,10 @@ random loops are opaque and minimize poorly.
9399
Another version of the same issue is:
94100

95101
```rust
102+
# fn prop(src: &mut chaos_theory::Source) {
96103
let do_it: bool = src.any("do_it");
97104
if do_it { /* use src here */ }
105+
# }
98106
```
99107

100108
Prefer `maybe` or `select` so the execution shape is tracked structurally.
@@ -113,14 +121,17 @@ The most common pattern is:
113121
Example shape:
114122

115123
```rust
124+
# fn prop(src: &mut chaos_theory::Source) {
116125
src.repeat("step", |src| {
117126
src.select("action", &["insert", "remove", "get"], |src, action, _| {
118127
// apply action to SUT
119128
// apply action to model
120129
// assert invariants
121130
// return Effect for the chosen action
131+
# todo!()
122132
})
123133
});
134+
# }
124135
```
125136

126137
Nested `repeat` and `select` are normal and encouraged for complex stateful systems.
@@ -155,7 +166,9 @@ are not required for everyday property tests.
155166
You will spend most of your time doing this:
156167

157168
```rust
169+
# fn prop(src: &mut chaos_theory::Source) {
158170
let v: Vec<String> = src.any("v");
171+
# }
159172
```
160173

161174
### Built-Ins (`make::*`)
@@ -195,10 +208,12 @@ Useful combinators:
195208
Use seeds when you have real examples that should guide exploration:
196209

197210
```rust
198-
use chaos_theory::make;
199-
211+
# use chaos_theory::{make, Source, Generator as _};
212+
# #[cfg(feature = "regex")]
213+
# fn prop(src: &mut Source) {
200214
let cities = ["Tokyo".to_owned(), "Moscow".to_owned(), "Shanghai".to_owned()];
201215
let city = make::string_matching("[A-Za-z '-]+", true).seeded(&cities, true);
216+
# }
202217
```
203218

204219
Built-in generators already have seeds pre-configured internally,
@@ -227,6 +242,7 @@ struct Point {
227242
y: i32,
228243
}
229244

245+
#[derive(Debug)]
230246
struct PointGen;
231247

232248
impl Generator for PointGen {
@@ -254,6 +270,7 @@ enum Op {
254270
Reset,
255271
}
256272

273+
#[derive(Debug)]
257274
struct OpGen;
258275

259276
impl Generator for OpGen {
@@ -293,6 +310,7 @@ Use `repeat` to build the collection:
293310
```rust
294311
use chaos_theory::{Arbitrary, Effect, Generator, SourceRaw};
295312

313+
#[derive(Debug)]
296314
struct BytesGen;
297315

298316
impl Generator for BytesGen {

chaos_theory/src/_docs.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//! Additional documentation.
2+
3+
/// Frequently asked questions.
4+
#[doc = include_str!("../docs/FAQ.md")]
5+
pub mod faq {}
6+
7+
/// User guide.
8+
#[doc = include_str!("../docs/guide.md")]
9+
pub mod guide {}
10+
11+
/// Release notes.
12+
#[doc = include_str!("../docs/CHANGELOG.md")]
13+
pub mod changelog {}

chaos_theory/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ you can use to reproduce the case.
5050
- built-in swarm testing
5151
- Macro-free, imperative API
5252
- Zero unsafe code and zero required dependencies
53+
54+
# Documentation
55+
56+
- [FAQ](crate::_docs::faq)
57+
- [Guide](crate::_docs::guide)
58+
- [Changelog](crate::_docs::changelog)
5359
*/
5460

5561
#![cfg_attr(all(test, feature = "_bench"), feature(test))]
@@ -91,6 +97,9 @@ mod unwind;
9197
mod util;
9298
mod varint;
9399

100+
#[cfg(doc)]
101+
pub mod _docs;
102+
94103
mod make_cell;
95104
mod make_char;
96105
mod make_collection;
File renamed without changes.

0 commit comments

Comments
 (0)