From 8a20c9c523b6d187178effa75ec674a0f58e63e8 Mon Sep 17 00:00:00 2001 From: Vincent Esche Date: Sat, 7 Oct 2023 01:03:40 +0200 Subject: [PATCH] Add 'enum_fields' test project --- tests/generate_graph.rs | 14 ++ tests/projects/enum_fields/Cargo.toml | 4 + tests/projects/enum_fields/src/lib.rs | 123 ++++++++++++++++++ .../generate_graph__fields__enum_fields.snap | 59 +++++++++ 4 files changed, 200 insertions(+) create mode 100644 tests/projects/enum_fields/Cargo.toml create mode 100644 tests/projects/enum_fields/src/lib.rs create mode 100644 tests/snapshots/generate_graph__fields__enum_fields.snap diff --git a/tests/generate_graph.rs b/tests/generate_graph.rs index efb452ef..45bb5e36 100644 --- a/tests/generate_graph.rs +++ b/tests/generate_graph.rs @@ -687,6 +687,20 @@ mod fields { color_mode: ColorMode::Plain, project: struct_fields ); + + test_cmd!( + args: "generate graph \ + --externs \ + --fns \ + --modules \ + --sysroot \ + --traits \ + --types \ + --uses", + success: true, + color_mode: ColorMode::Plain, + project: enum_fields + ); } mod github_issue_79 { diff --git a/tests/projects/enum_fields/Cargo.toml b/tests/projects/enum_fields/Cargo.toml new file mode 100644 index 00000000..1d28da31 --- /dev/null +++ b/tests/projects/enum_fields/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "enum_fields" +version = "0.1.0" +edition = "2018" diff --git a/tests/projects/enum_fields/src/lib.rs b/tests/projects/enum_fields/src/lib.rs new file mode 100644 index 00000000..182b1716 --- /dev/null +++ b/tests/projects/enum_fields/src/lib.rs @@ -0,0 +1,123 @@ +#![allow(dead_code, unused_variables)] + +type TypeAlias = TargetStruct; + +type GenericTypeAlias = T; + +trait TargetTrait {} + +#[derive(Copy, Clone)] +struct TargetStruct; + +impl TargetTrait for TargetStruct {} + +#[derive(Copy, Clone)] +struct GenericTargetStruct { + t: T, +} + +#[derive(Copy, Clone)] +enum TargetEnum {} + +impl TargetTrait for TargetEnum {} + +#[derive(Copy, Clone)] +enum GenericTargetEnum { + T(T), +} + +#[derive(Copy, Clone)] +union TargetUnion { + dummy: TargetStruct, +} + +impl TargetTrait for TargetUnion {} + +#[derive(Copy, Clone)] +union GenericTargetUnion { + t: T, +} + +pub enum Enum { + Unit, + Tuple( + // Unit types: + (), + // Scalar types: + bool, + char, + isize, + usize, + f64, + // Str types: + &'static str, + // Alias types: + TypeAlias, + // Adt types: + TargetStruct, + TargetEnum, + TargetUnion, + // Reference types: + &'static TargetStruct, + &'static [TargetStruct; 2], + // Array types: + [TargetStruct; 2], + // Slice types: + &'static [TargetStruct], + // Pointer types: + *const TargetStruct, + *mut TargetStruct, + // Tuple types: + (TargetStruct,), + // Generic alias types: + GenericTypeAlias, + // Generic adt types: + GenericTargetStruct, + GenericTargetEnum, + GenericTargetUnion, + // TargetTrait types: + &'static dyn DynTrait, + // Callable types: + fn(TargetStruct) -> TargetStruct, + ), + Struct { + // Unit types: + unit_field: (), + // Scalar types: + bool_field: bool, + char_field: char, + int_field: isize, + uint_field: usize, + float_field: f64, + // Str types: + str_field: &'static str, + // Alias types: + type_alias_field: TypeAlias, + // Adt types: + struct_field: TargetStruct, + enum_field: TargetEnum, + union_field: TargetUnion, + // Reference types: + reference_field: &'static TargetStruct, + array_reference_field: &'static [TargetStruct; 2], + // Array types: + array_field: [TargetStruct; 2], + // Slice types: + slice_field: &'static [TargetStruct], + // Pointer types: + const_ptr_field: *const TargetStruct, + mut_ptr_field: *mut TargetStruct, + // Tuple types: + tuple_field: (TargetStruct,), + // Generic alias types: + generic_type_alias_field: GenericTypeAlias, + // Generic adt types: + generic_struct_field: GenericTargetStruct, + generic_enum_field: GenericTargetEnum, + generic_union_field: GenericTargetUnion, + // Trait types: + dyn_trait_field: &'static dyn TargetTrait, + // Callable types: + callable_field: fn(TargetStruct) -> TargetStruct, + }, +} diff --git a/tests/snapshots/generate_graph__fields__enum_fields.snap b/tests/snapshots/generate_graph__fields__enum_fields.snap new file mode 100644 index 00000000..27675885 --- /dev/null +++ b/tests/snapshots/generate_graph__fields__enum_fields.snap @@ -0,0 +1,59 @@ +--- +source: tests/generate_graph.rs +expression: output +--- +STDERR: + +STDOUT: +digraph { + + graph [ + label="enum_fields", + labelloc=t, + + pad=0.4, + + // Consider rendering the graph using a different layout algorithm, such as: + // [dot, neato, twopi, circo, fdp, sfdp] + layout=neato, + overlap=false, + splines="line", + rankdir=LR, + + fontname="Helvetica", + fontsize="36", + ]; + + node [ + fontname="monospace", + fontsize="10", + shape="record", + style="filled", + ]; + + edge [ + fontname="monospace", + fontsize="10", + ]; + + "enum_fields" [label="crate|enum_fields", fillcolor="#5397c8"]; // "crate" node + "enum_fields::Enum" [label="pub enum|enum_fields::Enum", fillcolor="#81c169"]; // "enum" node + "enum_fields::GenericTargetEnum" [label="pub(crate) enum|enum_fields::GenericTargetEnum", fillcolor="#f8c04c"]; // "enum" node + "enum_fields::GenericTargetStruct" [label="pub(crate) struct|enum_fields::GenericTargetStruct", fillcolor="#f8c04c"]; // "struct" node + "enum_fields::GenericTargetUnion" [label="pub(crate) union|enum_fields::GenericTargetUnion", fillcolor="#f8c04c"]; // "union" node + "enum_fields::TargetEnum" [label="pub(crate) enum|enum_fields::TargetEnum", fillcolor="#f8c04c"]; // "enum" node + "enum_fields::TargetStruct" [label="pub(crate) struct|enum_fields::TargetStruct", fillcolor="#f8c04c"]; // "struct" node + "enum_fields::TargetTrait" [label="pub(crate) trait|enum_fields::TargetTrait", fillcolor="#f8c04c"]; // "trait" node + "enum_fields::TargetUnion" [label="pub(crate) union|enum_fields::TargetUnion", fillcolor="#f8c04c"]; // "union" node + + "enum_fields" -> "enum_fields::Enum" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge + "enum_fields" -> "enum_fields::GenericTargetEnum" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge + "enum_fields" -> "enum_fields::GenericTargetStruct" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge + "enum_fields" -> "enum_fields::GenericTargetUnion" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge + "enum_fields" -> "enum_fields::TargetEnum" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge + "enum_fields" -> "enum_fields::TargetStruct" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge + "enum_fields" -> "enum_fields::TargetTrait" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge + "enum_fields" -> "enum_fields::TargetUnion" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge + +} +