Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

challenge_test.gno

1.16 Kb · 38 lines
 1package flag
 2
 3import "testing"
 4
 5func TestDifficultyString(t *testing.T) {
 6	cases := map[Difficulty]string{Easy: "Easy", Medium: "Medium", Hard: "Hard", 0: "Unknown", 9: "Unknown"}
 7	for d, want := range cases {
 8		if got := d.String(); got != want {
 9			t.Errorf("Difficulty(%d).String() = %q, want %q", int(d), got, want)
10		}
11	}
12}
13
14func TestInfoValidate(t *testing.T) {
15	good := Info{Slug: "open-rack", Title: "The Open Rack", Difficulty: Medium, Brief: "A rack."}
16	if err := good.Validate(); err != nil {
17		t.Fatalf("valid info rejected: %v", err)
18	}
19	cases := []struct {
20		name string
21		edit func(*Info)
22		want error
23	}{
24		{"short slug", func(i *Info) { i.Slug = "ab" }, ErrBadSlug},
25		{"upper slug", func(i *Info) { i.Slug = "Rack" }, ErrBadSlug},
26		{"dash edge", func(i *Info) { i.Slug = "-rack" }, ErrBadSlug},
27		{"no title", func(i *Info) { i.Title = "  " }, ErrNoTitle},
28		{"bad grade", func(i *Info) { i.Difficulty = 7 }, ErrBadDifficulty},
29		{"no brief", func(i *Info) { i.Brief = "" }, ErrNoBrief},
30	}
31	for _, tc := range cases {
32		info := good
33		tc.edit(&info)
34		if err := info.Validate(); err != tc.want {
35			t.Errorf("%s: got %v, want %v", tc.name, err, tc.want)
36		}
37	}
38}