Skip to content

Commit

Permalink
Add 'union_fields' test project
Browse files Browse the repository at this point in the history
  • Loading branch information
regexident committed Oct 8, 2023
1 parent 8a20c9c commit 9668f51
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/generate_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions tests/projects/union_fields/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
name = "union_fields"
version = "0.1.0"
edition = "2018"
80 changes: 80 additions & 0 deletions tests/projects/union_fields/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#![allow(dead_code, unused_variables)]

type TypeAlias = TargetStruct;

type GenericTypeAlias<T> = T;

trait TargetTrait {}

#[derive(Copy, Clone)]
struct TargetStruct;

impl TargetTrait for TargetStruct {}

#[derive(Copy, Clone)]
struct GenericTargetStruct<T: Copy + TargetTrait> {
t: T,
}

#[derive(Copy, Clone)]
enum TargetEnum {}

impl TargetTrait for TargetEnum {}

#[derive(Copy, Clone)]
enum GenericTargetEnum<T: Copy + TargetTrait> {
T(T),
}

#[derive(Copy, Clone)]
union TargetUnion {
dummy: TargetStruct,
}

impl TargetTrait for TargetUnion {}

#[derive(Copy, Clone)]
union GenericTargetUnion<T: Copy + TargetTrait> {
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<TargetStruct>,
// Generic adt types:
generic_struct_field: GenericTargetStruct<TargetStruct>,
generic_enum_field: GenericTargetEnum<TargetStruct>,
generic_union_field: GenericTargetUnion<TargetStruct>,
// Trait types:
dyn_trait_field: &'static dyn TargetTrait,
// Callable types:
callable_field: fn(TargetStruct) -> TargetStruct,
}
59 changes: 59 additions & 0 deletions tests/snapshots/generate_graph__fields__union_fields.snap
Original file line number Diff line number Diff line change
@@ -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

}

0 comments on commit 9668f51

Please sign in to comment.