(
u: &mut Unstructured<'_>,
depth: u32,
fuel: &mut u32,
)
| 154 | |
| 155 | impl Type { |
| 156 | pub fn generate( |
| 157 | u: &mut Unstructured<'_>, |
| 158 | depth: u32, |
| 159 | fuel: &mut u32, |
| 160 | ) -> arbitrary::Result<Type> { |
| 161 | *fuel = fuel.saturating_sub(1); |
| 162 | let max = if depth == 0 || *fuel == 0 { 12 } else { 21 }; |
| 163 | Ok(match u.int_in_range(0..=max)? { |
| 164 | 0 => Type::Bool, |
| 165 | 1 => Type::S8, |
| 166 | 2 => Type::U8, |
| 167 | 3 => Type::S16, |
| 168 | 4 => Type::U16, |
| 169 | 5 => Type::S32, |
| 170 | 6 => Type::U32, |
| 171 | 7 => Type::S64, |
| 172 | 8 => Type::U64, |
| 173 | 9 => Type::Float32, |
| 174 | 10 => Type::Float64, |
| 175 | 11 => Type::Char, |
| 176 | 12 => Type::String, |
| 177 | // ^-- if you add something here update the `depth == 0` case above |
| 178 | 13 => Type::List(Box::new(Type::generate(u, depth - 1, fuel)?)), |
| 179 | 14 => Type::Record(Type::generate_list(u, depth - 1, fuel)?), |
| 180 | 15 => Type::Tuple(Type::generate_list(u, depth - 1, fuel)?), |
| 181 | 16 => Type::Variant(VecInRange::new(u, fuel, |u, fuel| { |
| 182 | Type::generate_opt(u, depth - 1, fuel) |
| 183 | })?), |
| 184 | 17 => { |
| 185 | let amt = u.int_in_range(1..=(*fuel).max(1).min(257))?; |
| 186 | *fuel -= amt; |
| 187 | Type::Enum(amt) |
| 188 | } |
| 189 | 18 => Type::Option(Box::new(Type::generate(u, depth - 1, fuel)?)), |
| 190 | 19 => Type::Result { |
| 191 | ok: Type::generate_opt(u, depth - 1, fuel)?.map(Box::new), |
| 192 | err: Type::generate_opt(u, depth - 1, fuel)?.map(Box::new), |
| 193 | }, |
| 194 | 20 => { |
| 195 | let amt = u.int_in_range(1..=(*fuel).min(32))?; |
| 196 | *fuel -= amt; |
| 197 | Type::Flags(amt) |
| 198 | } |
| 199 | 21 => Type::Map( |
| 200 | Box::new(Type::generate_hashable_key(u, fuel)?), |
| 201 | Box::new(Type::generate(u, depth - 1, fuel)?), |
| 202 | ), |
| 203 | // ^-- if you add something here update the `depth != 0` case above |
| 204 | _ => unreachable!(), |
| 205 | }) |
| 206 | } |
| 207 | |
| 208 | /// Generate a type that can be used as a HashMap key (implements Hash + Eq). |
| 209 | /// This excludes floats and complex types that might contain floats. |
nothing calls this directly
no test coverage detected