gnoface_test.gno

1.73 Kb ยท 136 lines
  1package gnoface
  2
  3import (
  4	"testing"
  5
  6	"gno.land/p/demo/ufmt"
  7)
  8
  9func TestDraw(t *testing.T) {
 10	cases := []struct {
 11		seed     uint64
 12		expected string
 13	}{
 14		{
 15			seed: 42,
 16			expected: `
 17  |||||||
 18 |||||||||
 19 |       |
 20 | .   ~ |
 21)| v   v |O
 22 |       |
 23 |   L   |
 24 |       |
 25 |  ___  |
 26 |       |
 27 \~~~~~~~/
 28`[1:],
 29		},
 30		{
 31			seed: 1337,
 32			expected: `
 33  .......
 34 |||||||||
 35 |       |
 36 | .   _ |
 37D| x   X |O
 38 |       |
 39 |   ~   |
 40 |       |
 41 |  ~~~  |
 42 |       |
 43 \~~~~~~~/
 44`[1:],
 45		},
 46		{
 47			seed: 123456789,
 48			expected: `
 49  .......
 50 ////////\
 51 |       |
 52 | ~   * |
 53|| x   X |o
 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
 74func 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)| v   v |O
 87 |       |
 88 |   L   |
 89 |       |
 90 |  ___  |
 91 |       |
 92 \~~~~~~~/
 93` + "```\n",
 94		},
 95		{
 96			path: "1337",
 97			expected: "Gnoface #1337\n```" + `
 98  .......
 99 |||||||||
100 |       |
101 | .   _ |
102D| x   X |O
103 |       |
104 |   ~   |
105 |       |
106 |  ~~~  |
107 |       |
108 \~~~~~~~/
109` + "```\n",
110		},
111		{
112			path: "123456789",
113			expected: "Gnoface #123456789\n```" + `
114  .......
115 ////////\
116 |       |
117 | ~   * |
118|| x   X |o
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}