...

Source file src/oss.terrastruct.com/d2/e2etests/todo_test.go

Documentation: oss.terrastruct.com/d2/e2etests

     1  package e2etests
     2  
     3  import (
     4  	_ "embed"
     5  	"testing"
     6  )
     7  
     8  func testTodo(t *testing.T) {
     9  	tcs := []testCase{
    10  		{
    11  			// issue https://github.com/terrastruct/d2/issues/71
    12  			name: "container_child_edge",
    13  			script: `
    14  container.first -> container.second: 1->2
    15  container -> container.second: c->2
    16  `,
    17  			dagreFeatureError: `Connection "(container -> container.second)[0]" goes from a container to a descendant, but layout engine "dagre" does not support this. See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.`,
    18  		},
    19  		{
    20  			name: "child_parent_edges",
    21  			script: `a.b -> a
    22  a.b -> a.b.c
    23  a.b.c.d -> a.b`,
    24  			dagreFeatureError: `Connection "(a.b -> a)[0]" goes from a container to a descendant, but layout engine "dagre" does not support this. See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.`,
    25  		},
    26  		{
    27  			name: "container_label_loop",
    28  			script: `a: "If we were meant to fly, we wouldn't keep losing our luggage" {
    29    b -> c
    30  }
    31  a -> a`,
    32  			dagreFeatureError: `Connection "(a -> a)[0]" is a self loop on a container, but layout engine "dagre" does not support this. See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.`,
    33  		},
    34  		{
    35  			// as nesting gets deeper, the groups advance towards `c` and may overlap its lifeline
    36  			// needs to consider the group size when computing the distance from `a` to `c`
    37  			// a similar effect can be seen for spans
    38  			name: "sequence_diagram_actor_padding_nested_groups",
    39  			script: `shape: sequence_diagram
    40  b;a;c
    41  b -> c
    42  this is a message group: {
    43      a -> b
    44      and this is a nested message group: {
    45          a -> b
    46          what about more nesting: {
    47              a -> b
    48              yo: {
    49                  a -> b
    50                  yo: {
    51                      a -> b
    52                  }
    53              }
    54          }
    55      }
    56  }`,
    57  		},
    58  		{
    59  			// dimensions set on containers are ignored
    60  			name: "shape_set_width_height",
    61  			script: `
    62  containers: {
    63  	circle container: {
    64  		shape: circle
    65  
    66  		diamond: {
    67  			shape: diamond
    68  			width: 128
    69  			height: 64
    70  		}
    71  	}
    72  	diamond container: {
    73  		shape: diamond
    74  
    75  		circle: {
    76  			shape: circle
    77  			width: 128
    78  		}
    79  	}
    80  	oval container: {
    81  		shape: oval
    82  
    83  		hexagon: {
    84  			shape: hexagon
    85  			width: 128
    86  			height: 64
    87  		}
    88  	}
    89  	hexagon container: {
    90  		shape: hexagon
    91  
    92  		oval: {
    93  			shape: oval
    94  			width: 128
    95  			height: 64
    96  		}
    97  	}
    98  }
    99  
   100  cloud: {
   101  	shape: cloud
   102  	width: 512
   103  	height: 256
   104  }
   105  tall cylinder: {
   106  	shape: cylinder
   107  	width: 256
   108  	height: 512
   109  }
   110  cloud -> class2 -> tall cylinder ->  users
   111  
   112  users: {
   113  	shape: sql_table
   114  	id: int
   115  	name: string
   116  	email: string
   117  	password: string
   118  	last_login: datetime
   119  
   120  	width: 800
   121  	height: 400
   122  }
   123  
   124  class2: {
   125  	shape: class
   126  	-num: int
   127  	-timeout: int
   128  	-pid
   129  
   130  	+getStatus(): Enum
   131  	+getJobs(): "Job[]"
   132  	+setTimeout(seconds int)
   133  
   134  	width: 800
   135  	height: 400
   136  }
   137  
   138  container -> text -> code -> small code
   139  
   140  text: {
   141  	label: |md
   142  	markdown text expanded to 800x400
   143  |
   144  	height: 800
   145  	width: 400
   146  }
   147  
   148  code: |go
   149      a := 5
   150      b := a + 7
   151      fmt.Printf("%d", b)
   152  | {
   153  	width: 400
   154  	height: 300
   155  }
   156  
   157  small code: |go
   158      a := 5
   159      b := a + 7
   160      fmt.Printf("%d", b)
   161  | {
   162  	width: 4
   163  	height: 3
   164  }
   165  `,
   166  		},
   167  		{
   168  			// issue https://github.com/terrastruct/d2/issues/748
   169  			name: "sequence_diagram_edge_group_span_field",
   170  			script: `
   171  Office chatter: {
   172    shape: sequence_diagram
   173    alice: Alice
   174    bob: Bobby
   175  	alice.a
   176    awkward small talk: {
   177      alice -> bob: uhm, hi
   178      bob -> alice: oh, hello
   179      icebreaker attempt: {
   180        alice -> bob: what did you have for lunch?
   181      }
   182      unfortunate outcome: {
   183        bob.a -> alice.a: that's personal
   184      }
   185    }
   186  }
   187  `,
   188  		},
   189  		{
   190  			// issue https://github.com/terrastruct/d2/issues/748
   191  			skip: true,
   192  			name: "sequence_diagram_ambiguous_edge_group",
   193  			script: `
   194  Office chatter: {
   195    shape: sequence_diagram
   196    alice: Alice
   197    bob: Bobby
   198    awkward small talk: {
   199      awkward small talk.ok
   200      alice -> bob: uhm, hi
   201      bob -> alice: oh, hello
   202      icebreaker attempt: {
   203        alice -> bob: what did you have for lunch?
   204      }
   205      unfortunate outcome: {
   206        bob -> alice: that's personal
   207      }
   208    }
   209  }
   210  `,
   211  		},
   212  		{
   213  			// https://github.com/terrastruct/d2/issues/791
   214  			name: "container_icon_label",
   215  			script: `a: Big font {
   216    icon: https://icons.terrastruct.com/essentials/004-picture.svg
   217  	style.font-size: 30
   218    a -> b -> c
   219    a: {
   220      a
   221    }
   222  }
   223  `,
   224  		},
   225  		{
   226  			name: "container_label_edge_adjustment",
   227  			script: `
   228  a -> b.c -> d: {style.stroke-width: 8; target-arrowhead.shape: diamond; target-arrowhead.style.filled: true}
   229  b.shape: cloud
   230  e -> b.c: {style.stroke-width: 8; target-arrowhead.shape: diamond; target-arrowhead.style.filled: true}
   231  f -> b: {
   232  	style: {
   233  		stroke: red
   234  		stroke-width: 8
   235  	}
   236  	target-arrowhead.shape: diamond
   237  	target-arrowhead.style.filled: true
   238  }
   239  g -> b: {style.stroke-width: 8; target-arrowhead.shape: diamond; target-arrowhead.style.filled: true}
   240  b: a container label
   241  `,
   242  		},
   243  		{
   244  			name: "container_label_edge_adjustment2",
   245  			script: `
   246  x -> y: {
   247  	target-arrowhead: foo {
   248  		shape: diamond
   249  		style.filled: true
   250  	}
   251  }
   252  
   253  y: bar {z}
   254  `,
   255  		},
   256  		{
   257  			name: "dagre_container_md_label_panic",
   258  			script: `
   259  OEM Factory -> company Warehouse
   260  
   261  company Warehouse.Master -> company Warehouse.Regional-1
   262  company Warehouse.Master -> company Warehouse.Regional-2
   263  company Warehouse.Master -> company Warehouse.Regional-N
   264  company Warehouse.Regional-1 -> company Warehouse.Regional-2
   265  company Warehouse.Regional-2 -> company Warehouse.Regional-N
   266  company Warehouse.Regional-N -> company Warehouse.Regional-1
   267  
   268  company Warehouse: |md
   269    ### company Warehouse
   270    - Asset Tagging
   271    - Inventory
   272    - Staging
   273    - Dispatch to Site
   274  |
   275  `,
   276  		},
   277  	}
   278  
   279  	runa(t, tcs)
   280  }
   281  

View as plain text