github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/examples/gno.land/r/demo/art/gnoface/gnoface_test.gno (about)

     1  package gnoface
     2  
     3  import (
     4  	"testing"
     5  
     6  	"gno.land/p/demo/ufmt"
     7  )
     8  
     9  func TestDraw(t *testing.T) {
    10  	cases := []struct {
    11  		seed     int64
    12  		expected string
    13  	}{
    14  		{
    15  			seed: 42,
    16  			expected: `
    17    |||||||
    18   ////////\
    19   |       |
    20   | ~   . |
    21  )| X   X |.
    22   |       |
    23   |   C   |
    24   |       |
    25   |  __/  |
    26   |       |
    27   \~~~~~~~/
    28  `[1:],
    29  		},
    30  		{
    31  			seed: 1337,
    32  			expected: `
    33       s
    34   /|||||||\
    35   |       |
    36   | .   * |
    37  o| ~   ~ |.
    38   |       |
    39   |   O   |
    40   |       |
    41   |  __/  |
    42   |       |
    43   \_______/
    44  `[1:],
    45  		},
    46  		{
    47  			seed: 123456789,
    48  			expected: `
    49       s
    50   /~~~~~~~\
    51   |       |
    52   | ~   . |
    53  <| ~   ~ |<
    54   |       |
    55   |   V   |
    56   |       |
    57   |  \_/  |
    58   |       |
    59   \-------/
    60  `[1:],
    61  		},
    62  	}
    63  	for _, tc := range cases {
    64  		name := ufmt.Sprintf("%d", tc.seed)
    65  		t.Run(name, func(t *testing.T) {
    66  			got := Draw(tc.seed)
    67  			if got != tc.expected {
    68  				t.Errorf("got %s, expected %s", got, tc.expected)
    69  			}
    70  		})
    71  	}
    72  }
    73  
    74  func TestRender(t *testing.T) {
    75  	cases := []struct {
    76  		path     string
    77  		expected string
    78  	}{
    79  		{
    80  			path: "42",
    81  			expected: "Gnoface #42\n```" + `
    82    |||||||
    83   ////////\
    84   |       |
    85   | ~   . |
    86  )| X   X |.
    87   |       |
    88   |   C   |
    89   |       |
    90   |  __/  |
    91   |       |
    92   \~~~~~~~/
    93  ` + "```\n",
    94  		},
    95  		{
    96  			path: "1337",
    97  			expected: "Gnoface #1337\n```" + `
    98       s
    99   /|||||||\
   100   |       |
   101   | .   * |
   102  o| ~   ~ |.
   103   |       |
   104   |   O   |
   105   |       |
   106   |  __/  |
   107   |       |
   108   \_______/
   109  ` + "```\n",
   110  		},
   111  		{
   112  			path: "123456789",
   113  			expected: "Gnoface #123456789\n```" + `
   114       s
   115   /~~~~~~~\
   116   |       |
   117   | ~   . |
   118  <| ~   ~ |<
   119   |       |
   120   |   V   |
   121   |       |
   122   |  \_/  |
   123   |       |
   124   \-------/
   125  ` + "```\n",
   126  		},
   127  	}
   128  	for _, tc := range cases {
   129  		t.Run(tc.path, func(t *testing.T) {
   130  			got := Render(tc.path)
   131  			if got != tc.expected {
   132  				t.Errorf("got %s, expected %s", got, tc.expected)
   133  			}
   134  		})
   135  	}
   136  }