...

Source file src/oss.terrastruct.com/d2/lib/urlenc/urlenc_test.go

Documentation: oss.terrastruct.com/d2/lib/urlenc

     1  package urlenc
     2  
     3  import (
     4  	"testing"
     5  
     6  	"oss.terrastruct.com/util-go/assert"
     7  )
     8  
     9  func TestBasic(t *testing.T) {
    10  	const script = `x -> y
    11  I just forgot my whole philosophy of life!!!: {
    12    s: TV is chewing gum for the eyes
    13  }
    14  `
    15  
    16  	encoded, err := Encode(script)
    17  	assert.Success(t, err)
    18  
    19  	decoded, err := Decode(encoded)
    20  	assert.Success(t, err)
    21  
    22  	assert.String(t, script, decoded)
    23  }
    24  
    25  // TestChanges makes it explicit in PRs when encoding changes
    26  // Something we might want to know for playground compatability
    27  func TestChanges(t *testing.T) {
    28  	// Choose something with many keywords and varied text
    29  	const script = `timeline mixer: "" {
    30    explanation: |md
    31      ## **Timeline mixer**
    32      - Inject ads, who-to-follow, onboarding
    33      - Conversation module
    34      - Cursoring,pagination
    35      - Tweat deduplication
    36      - Served data logging
    37    |
    38  }
    39  People discovery: "People discovery \nservice"
    40  admixer: Ad mixer {
    41    style.fill: "#c1a2f3"
    42  }
    43  
    44  onboarding service: "Onboarding \nservice"
    45  timeline mixer -> People discovery
    46  timeline mixer -> onboarding service
    47  timeline mixer -> admixer
    48  container0: "" {
    49    graphql
    50    comment
    51    tlsapi
    52  }
    53  container0.graphql: GraphQL\nFederated Strato Column {
    54    shape: image
    55    icon: https://upload.wikimedia.org/wikipedia/commons/thumb/1/17/GraphQL_Logo.svg/1200px-GraphQL_Logo.svg.png
    56  }
    57  container0.comment: |md
    58    ## Tweet/user content hydration, visibility filtering
    59  |
    60  container0.tlsapi: TLS-API (being deprecated)
    61  container0.graphql -> timeline mixer
    62  timeline mixer <- container0.tlsapi
    63  twitter fe: "Twitter Frontend " {
    64    icon: https://icons.terrastruct.com/social/013-twitter-1.svg
    65    shape: image
    66  }
    67  twitter fe -> container0.graphql: iPhone web
    68  twitter fe -> container0.tlsapi: HTTP Android
    69  web: Web {
    70    icon: https://icons.terrastruct.com/azure/Web%20Service%20Color/App%20Service%20Domains.svg
    71    shape: image
    72  }
    73  
    74  Iphone: {
    75    icon: 'https://ss7.vzw.com/is/image/VerizonWireless/apple-iphone-12-64gb-purple-53017-mjn13ll-a?$device-lg$'
    76    shape: image
    77  }
    78  Android: {
    79    icon: https://cdn4.iconfinder.com/data/icons/smart-phones-technologies/512/android-phone.png
    80    shape: image
    81  }
    82  
    83  web -> twitter fe
    84  timeline scorer: "Timeline\nScorer" {
    85    style.fill: "#ffdef1"
    86  }
    87  home ranker: Home Ranker
    88  
    89  timeline service: Timeline Service
    90  timeline mixer -> timeline scorer: Thrift RPC
    91  timeline mixer -> home ranker: {
    92    style.stroke-dash: 4
    93    style.stroke: "#000E3D"
    94  }
    95  timeline mixer -> timeline service
    96  home mixer: Home mixer {
    97    # style.fill: "#c1a2f3"
    98  }
    99  container0.graphql -> home mixer: {
   100    style.stroke-dash: 4
   101    style.stroke: "#000E3D"
   102  }
   103  home mixer -> timeline scorer
   104  home mixer -> home ranker: {
   105    style.stroke-dash: 4
   106    style.stroke: "#000E3D"
   107  }
   108  home mixer -> timeline service
   109  manhattan 2: Manhattan
   110  gizmoduck: Gizmoduck
   111  socialgraph: Social graph
   112  tweetypie: Tweety Pie
   113  home mixer -> manhattan 2
   114  home mixer -> gizmoduck
   115  home mixer -> socialgraph
   116  home mixer -> tweetypie
   117  Iphone -> twitter fe
   118  Android -> twitter fe
   119  prediction service2: Prediction Service {
   120    shape: image
   121    icon: https://cdn-icons-png.flaticon.com/512/6461/6461819.png
   122  }
   123  home scorer: Home Scorer {
   124    style.fill: "#ffdef1"
   125  }
   126  manhattan: Manhattan
   127  memcache: Memcache {
   128    icon: https://d1q6f0aelx0por.cloudfront.net/product-logos/de041504-0ddb-43f6-b89e-fe04403cca8d-memcached.png
   129  }
   130  
   131  fetch: Fetch {
   132    style.multiple: true
   133    shape: step
   134  }
   135  
   136  feature: Feature {
   137    style.multiple: true
   138    shape: step
   139  }
   140  scoring: Scoring {
   141    style.multiple: true
   142    shape: step
   143  }
   144  fetch -> feature
   145  feature -> scoring
   146  
   147  prediction service: Prediction Service {
   148    shape: image
   149    icon: https://cdn-icons-png.flaticon.com/512/6461/6461819.png
   150  }
   151  scoring -> prediction service
   152  fetch -> container2.crmixer
   153  
   154  home scorer -> manhattan: ""
   155  
   156  home scorer -> memcache: ""
   157  home scorer -> prediction service2
   158  home ranker -> home scorer
   159  home ranker -> container2.crmixer: Candidate Fetch
   160  container2: "" {
   161    style.stroke: "#000E3D"
   162    style.fill: "#ffffff"
   163    crmixer: CrMixer {
   164      style.fill: "#F7F8FE"
   165    }
   166    earlybird: EarlyBird
   167    utag: Utag
   168    space: Space
   169    communities: Communities
   170  }
   171  etc: ...etc
   172  
   173  home scorer -> etc: Feature Hydration
   174  
   175  feature -> manhattan
   176  feature -> memcache
   177  feature -> etc: Candidate sources
   178  `
   179  
   180  	encoded, err := Encode(script)
   181  	assert.Success(t, err)
   182  	assert.Testdata(t, ".txt", []byte(encoded))
   183  
   184  	decoded, err := Decode(encoded)
   185  	assert.Success(t, err)
   186  
   187  	assert.String(t, script, decoded)
   188  }
   189  

View as plain text