-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmain_test.go
More file actions
28 lines (25 loc) · 995 Bytes
/
main_test.go
File metadata and controls
28 lines (25 loc) · 995 Bytes
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
package main
import "testing"
func TestShouldPrintVersionAndExit(t *testing.T) {
tests := []struct {
name string
args []string
want bool
}{
{name: "no args", args: nil, want: false},
{name: "long version top level", args: []string{"--version"}, want: true},
{name: "short version top level", args: []string{"-v"}, want: true},
{name: "version subcommand", args: []string{"version"}, want: false},
{name: "subcommand with version literal value", args: []string{"page", "edit", "p", "--find", "x", "--replace-with", "--version"}, want: false},
{name: "subcommand with short value", args: []string{"page", "edit", "p", "--find", "x", "--replace-with", "-v"}, want: false},
{name: "help top level", args: []string{"--help"}, want: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := shouldPrintVersionAndExit(tt.args)
if got != tt.want {
t.Fatalf("shouldPrintVersionAndExit(%v) = %v, want %v", tt.args, got, tt.want)
}
})
}
}