...

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

Documentation: oss.terrastruct.com/d2/e2etests

     1  package e2etests
     2  
     3  import (
     4  	_ "embed"
     5  	"testing"
     6  
     7  	"oss.terrastruct.com/d2/d2themes/d2themescatalog"
     8  )
     9  
    10  func testThemes(t *testing.T) {
    11  	tcs := []testCase{
    12  		{
    13  			name:    "dark terrastruct flagship",
    14  			themeID: &d2themescatalog.DarkFlagshipTerrastruct.ID,
    15  			script: `
    16  network: {
    17    cell tower: {
    18  		style.text-transform: capitalize
    19  		satellites: {
    20  			shape: stored_data
    21        style.multiple: true
    22  		}
    23  
    24  		transmitter : {
    25  			style.text-transform: uppercase
    26  		}
    27  
    28  		satellites -> transmitter: SEnD {
    29  			style.text-transform: lowercase
    30  		}
    31  		satellites -> transmitter: send
    32  		satellites -> transmitter: send
    33    }
    34  
    35    online portal: {
    36      ui: { shape: hexagon }
    37    }
    38  
    39    data processor: {
    40      storage: {
    41        shape: cylinder
    42        style.multiple: true
    43      }
    44    }
    45  
    46    cell tower.transmitter -> data processor.storage: phone logs
    47  }
    48  
    49  user: {
    50    shape: person
    51    width: 130
    52  }
    53  
    54  user -> network.cell tower: make call
    55  user -> network.online portal.ui: access {
    56    style.stroke-dash: 3
    57  }
    58  
    59  api server -> network.online portal.ui: display
    60  api server -> logs: persist
    61  logs: { shape: page; style.multiple: true }
    62  
    63  network.data processor -> api server
    64  users: {
    65  	shape: sql_table
    66  	id: int
    67  	name: string
    68  	email: string
    69  	password: string
    70  	last_login: datetime
    71  }
    72  
    73  products: {
    74  	shape: class
    75  	id: int
    76  	price: decimal
    77  	sku: string
    78  	name: string
    79  }
    80  markdown: |md
    81    # A tale
    82    - of
    83    - two cities
    84  |
    85  code: |go
    86  package main
    87  
    88  import (
    89  	"fmt"
    90  )
    91  
    92  type City struct {
    93  	Name       string
    94  	Population int
    95  }
    96  
    97  func tellTale(city1, city2 City) {
    98  	fmt.Printf("There were two cities, %s and %s.\n", city1.Name, city2.Name)
    99  	fmt.Printf("%s had a population of %d.\n", city1.Name, city1.Population)
   100  	fmt.Printf("%s had a population of %d.\n", city2.Name, city2.Population)
   101  	fmt.Println("Their tales were intertwined, and their people shared many adventures.")
   102  }
   103  
   104  func main() {
   105  	city1 := City{Name: "CityA", Population: 1000000}
   106  	city2 := City{Name: "CityB", Population: 1200000}
   107  
   108  	tellTale(city1, city2)
   109  }
   110  |
   111  
   112  markdown -> code -> ex
   113  ex: |tex
   114  	\\displaylines{x = a + b \\\\ y = b + c}
   115  	\\sum_{k=1}^{n} h_{k} \\int_{0}^{1} \\bigl(\\partial_{k} f(x_{k-1}+t h_{k} e_{k}) -\\partial_{k} f(a)\\bigr) \\,dt
   116  |
   117  `,
   118  		},
   119  		{
   120  			name:    "terminal",
   121  			themeID: &d2themescatalog.Terminal.ID,
   122  			script: `
   123  network: {
   124    cell tower: {
   125  		style.text-transform: capitalize
   126  		satellites: {
   127  			shape: stored_data
   128        style.multiple: true
   129  		}
   130  
   131  		transmitter : {
   132  			style.text-transform: uppercase
   133  		}
   134  
   135  		satellites -> transmitter: SEnD {
   136  			style.text-transform: lowercase
   137  		}
   138  		satellites -> transmitter: send
   139  		satellites -> transmitter: send
   140    }
   141  
   142    online portal: {
   143      ui: { shape: hexagon }
   144    }
   145  
   146    data processor: {
   147      storage: {
   148        shape: cylinder
   149        style.multiple: true
   150      }
   151    }
   152  
   153    cell tower.transmitter -> data processor.storage: phone logs
   154  }
   155  
   156  user: {
   157    shape: person
   158    width: 130
   159  }
   160  
   161  user -> network.cell tower: make call
   162  user -> network.online portal.ui: access {
   163    style.stroke-dash: 3
   164  }
   165  
   166  api server -> network.online portal.ui: display
   167  api server -> logs: persist
   168  logs: { shape: page; style.multiple: true }
   169  
   170  network.data processor -> api server
   171  users: {
   172  	shape: sql_table
   173  	id: int
   174  	name: string
   175  	email: string
   176  	password: string
   177  	last_login: datetime
   178  }
   179  
   180  products: {
   181  	shape: class
   182  	id: int
   183  	price: decimal
   184  	sku: string
   185  	name: string
   186  }
   187  markdown: |md
   188    # A tale
   189    - of
   190    - two cities
   191  |
   192  code: |go
   193  package main
   194  
   195  import (
   196  	"fmt"
   197  )
   198  
   199  type City struct {
   200  	Name       string
   201  	Population int
   202  }
   203  
   204  func tellTale(city1, city2 City) {
   205  	fmt.Printf("There were two cities, %s and %s.\n", city1.Name, city2.Name)
   206  	fmt.Printf("%s had a population of %d.\n", city1.Name, city1.Population)
   207  	fmt.Printf("%s had a population of %d.\n", city2.Name, city2.Population)
   208  	fmt.Println("Their tales were intertwined, and their people shared many adventures.")
   209  }
   210  
   211  func main() {
   212  	city1 := City{Name: "CityA", Population: 1000000}
   213  	city2 := City{Name: "CityB", Population: 1200000}
   214  
   215  	tellTale(city1, city2)
   216  }
   217  |
   218  
   219  markdown -> code -> ex
   220  ex: |tex
   221  	\\displaylines{x = a + b \\\\ y = b + c}
   222  	\\sum_{k=1}^{n} h_{k} \\int_{0}^{1} \\bigl(\\partial_{k} f(x_{k-1}+t h_{k} e_{k}) -\\partial_{k} f(a)\\bigr) \\,dt
   223  |
   224  `,
   225  		},
   226  		{
   227  			name:    "terminal_grayscale",
   228  			themeID: &d2themescatalog.TerminalGrayscale.ID,
   229  			script: `
   230  network: {
   231    cell tower: {
   232  		style.text-transform: capitalize
   233  		satellites: {
   234  			shape: stored_data
   235        style.multiple: true
   236  		}
   237  
   238  		transmitter
   239  
   240  		satellites -> transmitter: SEnD {
   241  			style.text-transform: lowercase
   242  		}
   243  		satellites -> transmitter: send
   244  		satellites -> transmitter: send
   245    }
   246  
   247    online portal: {
   248      ui: { shape: hexagon }
   249    }
   250  
   251    data processor: {
   252      storage: {
   253        shape: cylinder
   254        style.multiple: true
   255      }
   256    }
   257  
   258    cell tower.transmitter -> data processor.storage: phone logs {
   259  		style.text-transform: none
   260  	}
   261  }
   262  
   263  user: {
   264    shape: person
   265    width: 130
   266  }
   267  
   268  user -> network.cell tower: make call
   269  user -> network.online portal.ui: access {
   270    style.stroke-dash: 3
   271  }
   272  
   273  api server -> network.online portal.ui: display
   274  api server -> logs: persist
   275  logs: { shape: page; style.multiple: true }
   276  
   277  network.data processor -> api server
   278  `,
   279  		},
   280  		{
   281  			name:    "origami",
   282  			themeID: &d2themescatalog.Origami.ID,
   283  			script: `
   284  network: 通信網 {
   285    cell tower: {
   286  		style.text-transform: capitalize
   287  		satellites: 衛星 {
   288  			shape: stored_data
   289        style.multiple: true
   290  		}
   291  
   292  		transmitter: 送信機
   293  
   294  		satellites -> transmitter: SEnD {
   295  			style.text-transform: lowercase
   296  		}
   297  		satellites -> transmitter: send {
   298  			style.text-transform: uppercase
   299  		}
   300  		satellites -> transmitter: send
   301    }
   302  
   303    online portal: オンラインポータル {
   304      ui: { shape: hexagon }
   305    }
   306  
   307    data processor: データプロセッサ {
   308      storage: 保管所 {
   309        shape: cylinder
   310        style.multiple: true
   311      }
   312    }
   313  
   314    cell tower.transmitter -> data processor.storage: 電話ログ {
   315  		style.text-transform: lowercase
   316  	}
   317  }
   318  
   319  user: ユーザー {
   320    shape: person
   321    width: 130
   322  	style.text-transform: capitalize
   323  }
   324  
   325  other-user: {
   326  	shape: person
   327  	style.text-transform: uppercase
   328  }
   329  
   330  user -> network.cell tower: 電話をかける
   331  user -> network.online portal.ui: アクセス {
   332    style.stroke-dash: 3
   333  }
   334  
   335  api server: API サーバー {
   336  	style.text-transform: lowercase
   337  }
   338  api server -> network.online portal.ui: 画面
   339  api server -> logs: 持続する
   340  logs: ログ { shape: page; style.multiple: true }
   341  
   342  network.data processor -> api server
   343  `,
   344  		},
   345  	}
   346  
   347  	runa(t, tcs)
   348  }
   349  

View as plain text