Search Apps Documentation Source Content File Folder Download Copy

chonk_test.gno

0.95 Kb ยท 54 lines
 1package chonk
 2
 3import (
 4	"testing"
 5)
 6
 7func TestChonk(t *testing.T) {
 8	t.Parallel()
 9	c := New()
10	testTable := []struct {
11		name   string
12		chunks []string
13	}{
14		{
15			name:   "empty",
16			chunks: []string{},
17		},
18		{
19			name:   "single chunk",
20			chunks: []string{"a"},
21		},
22		{
23			name:   "multiple chunks",
24			chunks: []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"},
25		},
26		{
27			name:   "multiline chunks",
28			chunks: []string{"1a\nb\nc\n\n", "d\ne\nf", "g\nh\ni", "j\nk\nl\n\n\n\n"},
29		},
30		{
31			name:   "empty",
32			chunks: []string{},
33		},
34	}
35	testChonk := func(t *testing.T, c *Chonk, chunks []string) {
36		for _, chunk := range chunks {
37			c.Add(chunk)
38		}
39		scanner := c.Scanner()
40		i := 0
41		for scanner.Scan() {
42			if scanner.Text() != chunks[i] {
43				t.Errorf("expected %s, got %s", chunks[i], scanner.Text())
44			}
45			i++
46		}
47	}
48	for _, test := range testTable {
49		t.Run(test.name, func(t *testing.T) {
50			testChonk(t, c, test.chunks)
51			c.Flush()
52		})
53	}
54}