▍ humdrum codex / ticktock v0.0.2
license AGPL-3.0
1.0 KB raw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main

import "testing"

func hasCmd(names []string, want string) bool {
	for _, n := range names {
		if n == want {
			return true
		}
	}
	return false
}

func cmdNames() []string {
	var out []string
	for _, c := range newRootCmd().Commands() {
		out = append(out, c.Name())
	}
	return out
}

func TestRootUse(t *testing.T) {
	if got := newRootCmd().Use; got != "tt" {
		t.Fatalf("root Use = %q, want tt", got)
	}
}

func TestSubcommandsRegistered(t *testing.T) {
	names := cmdNames()
	for _, want := range []string{"day", "timeline", "menu"} {
		if !hasCmd(names, want) {
			t.Errorf("missing subcommand %q (have %v)", want, names)
		}
	}
}

func TestTimelineHasTuiAlias(t *testing.T) {
	for _, c := range newRootCmd().Commands() {
		if c.Name() == "timeline" {
			if !hasCmd(c.Aliases, "tui") {
				t.Errorf("timeline should alias tui, aliases=%v", c.Aliases)
			}
			return
		}
	}
	t.Fatal("no timeline command")
}

func TestVersionSet(t *testing.T) {
	if newRootCmd().Version == "" {
		t.Error("root command should carry a version")
	}
}