...

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

Documentation: oss.terrastruct.com/d2/e2etests

     1  package e2etests
     2  
     3  import (
     4  	_ "embed"
     5  	"testing"
     6  )
     7  
     8  func testPatterns(t *testing.T) {
     9  	tcs := []testCase{
    10  		{
    11  			name: "root-dots",
    12  			script: `style.fill-pattern: dots
    13  x -> y -> z
    14  x -> abcd
    15  x -> g
    16  x -> z
    17  `,
    18  		},
    19  		{
    20  			name: "root-dots-with-fill",
    21  			script: `style.fill-pattern: dots
    22  style.fill: honeydew
    23  x -> y -> z
    24  x -> abcd
    25  x -> g
    26  x -> z
    27  `,
    28  		},
    29  		{
    30  			name: "shape",
    31  			script: `x -> y -> z
    32  x -> abcd
    33  x -> g
    34  x -> z
    35  x.style.fill-pattern: dots
    36  abcd.style.fill-pattern: dots
    37  `,
    38  		},
    39  		{
    40  			name: "3d",
    41  			script: `x: {style.3d: true; style.fill-pattern: dots}
    42  y: {shape: hexagon; style.3d: true; style.fill-pattern: dots}
    43  `,
    44  		},
    45  		{
    46  			name: "multiple",
    47  			script: `
    48  rectangle: {shape: "rectangle"; style.fill-pattern: dots; style.multiple: true}
    49  square: {shape: "square"; style.fill-pattern: dots; style.multiple: true}
    50  page: {shape: "page"; style.fill-pattern: dots; style.multiple: true}
    51  parallelogram: {shape: "parallelogram"; style.fill-pattern: dots; style.multiple: true}
    52  document: {shape: "document"; style.fill-pattern: dots; style.multiple: true}
    53  cylinder: {shape: "cylinder"; style.fill-pattern: dots; style.multiple: true}
    54  queue: {shape: "queue"; style.fill-pattern: dots; style.multiple: true}
    55  package: {shape: "package"; style.fill-pattern: dots; style.multiple: true}
    56  step: {shape: "step"; style.fill-pattern: dots; style.multiple: true}
    57  callout: {shape: "callout"; style.fill-pattern: dots; style.multiple: true}
    58  stored_data: {shape: "stored_data"; style.fill-pattern: dots; style.multiple: true}
    59  person: {shape: "person"; style.fill-pattern: dots; style.multiple: true}
    60  diamond: {shape: "diamond"; style.fill-pattern: dots; style.multiple: true}
    61  oval: {shape: "oval"; style.fill-pattern: dots; style.multiple: true}
    62  circle: {shape: "circle"; style.fill-pattern: dots; style.multiple: true}
    63  hexagon: {shape: "hexagon"; style.fill-pattern: dots; style.multiple: true}
    64  cloud: {shape: "cloud"; style.fill-pattern: dots; style.multiple: true}
    65  
    66  rectangle -> square -> page
    67  parallelogram -> document -> cylinder
    68  queue -> package -> step
    69  callout -> stored_data -> person
    70  diamond -> oval -> circle
    71  hexagon -> cloud
    72  `,
    73  		},
    74  		{
    75  			name: "all_shapes",
    76  			script: `
    77  rectangle: {shape: "rectangle"; style.fill-pattern: dots}
    78  square: {shape: "square"; style.fill-pattern: dots}
    79  page: {shape: "page"; style.fill-pattern: dots}
    80  parallelogram: {shape: "parallelogram"; style.fill-pattern: dots}
    81  document: {shape: "document"; style.fill-pattern: dots}
    82  cylinder: {shape: "cylinder"; style.fill-pattern: dots}
    83  queue: {shape: "queue"; style.fill-pattern: dots}
    84  package: {shape: "package"; style.fill-pattern: dots}
    85  step: {shape: "step"; style.fill-pattern: dots}
    86  callout: {shape: "callout"; style.fill-pattern: dots}
    87  stored_data: {shape: "stored_data"; style.fill-pattern: dots}
    88  person: {shape: "person"; style.fill-pattern: dots}
    89  diamond: {shape: "diamond"; style.fill-pattern: dots}
    90  oval: {shape: "oval"; style.fill-pattern: dots}
    91  circle: {shape: "circle"; style.fill-pattern: dots}
    92  hexagon: {shape: "hexagon"; style.fill-pattern: dots}
    93  cloud: {shape: "cloud"; style.fill-pattern: dots}
    94  
    95  rectangle -> square -> page
    96  parallelogram -> document -> cylinder
    97  queue -> package -> step
    98  callout -> stored_data -> person
    99  diamond -> oval -> circle
   100  hexagon -> cloud
   101  `,
   102  		},
   103  		{
   104  			name: "paper",
   105  			script: `
   106  rectangle: {shape: "rectangle"; style.fill: "#8F5A3C"; style.fill-pattern: paper}
   107  square: {shape: "square"; style.fill: "#D0104C"; style.fill-pattern: paper}
   108  page: {shape: "page"; style.fill-pattern: paper}
   109  parallelogram: {shape: "parallelogram"; style.fill-pattern: paper}
   110  document: {shape: "document"; style.fill-pattern: paper}
   111  cylinder: {shape: "cylinder"; style.fill-pattern: paper}
   112  queue: {shape: "queue"; style.fill-pattern: paper}
   113  package: {shape: "package"; style.fill-pattern: paper}
   114  step: {shape: "step"; style.fill-pattern: paper}
   115  callout: {shape: "callout"; style.fill-pattern: paper}
   116  stored_data: {shape: "stored_data"; style.fill-pattern: paper}
   117  person: {shape: "person"; style.fill-pattern: paper}
   118  diamond: {shape: "diamond"; style.fill-pattern: paper}
   119  oval: {shape: "oval"; style.fill-pattern: paper}
   120  circle: {shape: "circle"; style.fill-pattern: paper}
   121  hexagon: {shape: "hexagon"; style.fill-pattern: paper}
   122  cloud: {shape: "cloud"; style.fill-pattern: paper}
   123  
   124  rectangle -> square -> page
   125  parallelogram -> document -> cylinder
   126  queue -> package -> step
   127  callout -> stored_data -> person
   128  diamond -> oval -> circle
   129  hexagon -> cloud
   130  `,
   131  		},
   132  		{
   133  			name: "real",
   134  			script: `
   135  NETWORK: {
   136    style: {
   137  	  stroke: black
   138      fill-pattern: dots
   139      double-border: true
   140      fill: "#E7E9EE"
   141      font: mono
   142    }
   143    CELL TOWER: {
   144  		style: {
   145  			stroke: black
   146  			fill-pattern: dots
   147  			fill: "#F5F6F9"
   148  			font: mono
   149  		}
   150  		satellites: SATELLITES {
   151  			shape: stored_data
   152  			style: {
   153  				font: mono
   154  				fill: white
   155  				stroke: black
   156  				multiple: true
   157  			}
   158  		}
   159  
   160  		transmitter: TRANSMITTER {
   161  			style: {
   162  				font: mono
   163  				fill: white
   164  				stroke: black
   165  			}
   166  		}
   167  
   168  		satellites -> transmitter: SEND {
   169  			style.stroke: black
   170  			style.font: mono
   171  		}
   172  		satellites -> transmitter: SEND {
   173  			style.stroke: black
   174  			style.font: mono
   175  		}
   176  		satellites -> transmitter: SEND {
   177  			style.stroke: black
   178  			style.font: mono
   179  		}
   180    }
   181  }
   182  `,
   183  		},
   184  		{
   185  			name: "real-lines",
   186  			script: `
   187  NETWORK: {
   188    style: {
   189  	  stroke: black
   190      fill-pattern: lines
   191      double-border: true
   192      fill: "#E7E9EE"
   193      font: mono
   194    }
   195    CELL TOWER: {
   196  		style: {
   197  			stroke: black
   198  			fill-pattern: lines
   199  			fill: "#F5F6F9"
   200  			font: mono
   201  		}
   202  		satellites: SATELLITES {
   203  			shape: stored_data
   204  			style: {
   205  				font: mono
   206  				fill: white
   207  				stroke: black
   208  				multiple: true
   209  			}
   210  		}
   211  
   212  		transmitter: TRANSMITTER {
   213  			style: {
   214  				font: mono
   215  				fill: white
   216  				stroke: black
   217  			}
   218  		}
   219  
   220  		satellites -> transmitter: SEND {
   221  			style.stroke: black
   222  			style.font: mono
   223  		}
   224  		satellites -> transmitter: SEND {
   225  			style.stroke: black
   226  			style.font: mono
   227  		}
   228  		satellites -> transmitter: SEND {
   229  			style.stroke: black
   230  			style.font: mono
   231  		}
   232    }
   233  }
   234  
   235  costumes: {
   236    shape: sql_table
   237    id: int {constraint: primary_key}
   238    silliness: int
   239    monster: int
   240    last_updated: timestamp
   241  	style.fill-pattern: lines
   242  }
   243  
   244  monsters: {
   245    shape: sql_table
   246    id: int {constraint: primary_key}
   247    movie: string
   248    weight: int
   249    last_updated: timestamp
   250  	style.fill-pattern: grain
   251  }
   252  
   253  costumes.monster -> monsters.id
   254  `,
   255  		},
   256  	}
   257  
   258  	for i := range tcs {
   259  		tcs[i].justDagre = true
   260  	}
   261  
   262  	runa(t, tcs)
   263  }
   264  

View as plain text