diff --git a/tests/generate_graph.rs b/tests/generate_graph.rs index 45bb5e36..f9392e3d 100644 --- a/tests/generate_graph.rs +++ b/tests/generate_graph.rs @@ -701,6 +701,20 @@ mod fields { color_mode: ColorMode::Plain, project: enum_fields ); + + test_cmd!( + args: "generate graph \ + --externs \ + --fns \ + --modules \ + --sysroot \ + --traits \ + --types \ + --uses", + success: true, + color_mode: ColorMode::Plain, + project: union_fields + ); } mod github_issue_79 { diff --git a/tests/projects/union_fields/Cargo.toml b/tests/projects/union_fields/Cargo.toml new file mode 100644 index 00000000..d1cee0ca --- /dev/null +++ b/tests/projects/union_fields/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "union_fields" +version = "0.1.0" +edition = "2018" diff --git a/tests/projects/union_fields/src/lib.rs b/tests/projects/union_fields/src/lib.rs new file mode 100644 index 00000000..189160d7 --- /dev/null +++ b/tests/projects/union_fields/src/lib.rs @@ -0,0 +1,80 @@ +#![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 union Union { + // 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__union_fields.snap b/tests/snapshots/generate_graph__fields__union_fields.snap new file mode 100644 index 00000000..cdac1e74 --- /dev/null +++ b/tests/snapshots/generate_graph__fields__union_fields.snap @@ -0,0 +1,59 @@ +--- +source: tests/generate_graph.rs +expression: output +--- +STDERR: + +STDOUT: +digraph { + + graph [ + label="union_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", + ]; + + "union_fields" [label="crate|union_fields", fillcolor="#5397c8"]; // "crate" node + "union_fields::GenericTargetEnum" [label="pub(crate) enum|union_fields::GenericTargetEnum", fillcolor="#f8c04c"]; // "enum" node + "union_fields::GenericTargetStruct" [label="pub(crate) struct|union_fields::GenericTargetStruct", fillcolor="#f8c04c"]; // "struct" node + "union_fields::GenericTargetUnion" [label="pub(crate) union|union_fields::GenericTargetUnion", fillcolor="#f8c04c"]; // "union" node + "union_fields::TargetEnum" [label="pub(crate) enum|union_fields::TargetEnum", fillcolor="#f8c04c"]; // "enum" node + "union_fields::TargetStruct" [label="pub(crate) struct|union_fields::TargetStruct", fillcolor="#f8c04c"]; // "struct" node + "union_fields::TargetTrait" [label="pub(crate) trait|union_fields::TargetTrait", fillcolor="#f8c04c"]; // "trait" node + "union_fields::TargetUnion" [label="pub(crate) union|union_fields::TargetUnion", fillcolor="#f8c04c"]; // "union" node + "union_fields::Union" [label="pub union|union_fields::Union", fillcolor="#81c169"]; // "union" node + + "union_fields" -> "union_fields::GenericTargetEnum" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge + "union_fields" -> "union_fields::GenericTargetStruct" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge + "union_fields" -> "union_fields::GenericTargetUnion" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge + "union_fields" -> "union_fields::TargetEnum" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge + "union_fields" -> "union_fields::TargetStruct" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge + "union_fields" -> "union_fields::TargetTrait" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge + "union_fields" -> "union_fields::TargetUnion" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge + "union_fields" -> "union_fields::Union" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge + +} +