Search Apps Documentation Source Content File Folder Download Copy Actions Download

gauge_test.gno

1.57 Kb ยท 71 lines
 1package gauge
 2
 3import (
 4	"strings"
 5	"testing"
 6)
 7
 8func TestRender(t *testing.T) {
 9	tests := []struct {
10		name         string
11		value        int
12		total        int
13		label        string
14		color        string
15		percentOnly  bool
16		width        int
17		canvasHeight int
18		fontSize     int
19		paddingH     int
20		wantSubstr   string
21	}{
22		{
23			name:         "fails when value <= 0",
24			value:        0,
25			total:        5,
26			label:        "Yes",
27			color:        "#a6da95",
28			percentOnly:  false,
29			width:        100,
30			canvasHeight: 30,
31			fontSize:     16,
32			paddingH:     6,
33			wantSubstr:   "jauge fails: value must be greater than 0",
34		},
35		{
36			name:         "fails when total <= 0",
37			value:        5,
38			total:        0,
39			label:        "Yes",
40			color:        "#a6da95",
41			percentOnly:  false,
42			width:        100,
43			canvasHeight: 30,
44			fontSize:     16,
45			paddingH:     6,
46			wantSubstr:   "jauge fails: total must be greater than 0",
47		},
48		{
49			name:         "fails when value > total",
50			value:        11,
51			total:        10,
52			label:        "Yes",
53			color:        "#a6da95",
54			percentOnly:  false,
55			width:        100,
56			canvasHeight: 30,
57			fontSize:     16,
58			paddingH:     6,
59			wantSubstr:   "jauge fails: value cannot be greater than total",
60		},
61	}
62
63	for _, tt := range tests {
64		t.Run(tt.name, func(t *testing.T) {
65			got := Render(tt.value, tt.total, tt.label, tt.color, Config{tt.percentOnly, tt.width, tt.canvasHeight, tt.fontSize, tt.paddingH})
66			if !strings.Contains(got, tt.wantSubstr) {
67				t.Errorf("Render() = %q, want substring %q", got, tt.wantSubstr)
68			}
69		})
70	}
71}