summaryrefslogtreecommitdiff
path: root/vendor/github.com/pborman/getopt/v2/string_test.go
blob: 31abae81a1cba162bcbb0f042b8e36857d669892 (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2017 Google Inc.  All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package getopt

import "testing"

var stringTests = []struct {
	where  string
	in     []string
	sout   string
	optout string
	err    string
}{
	{
		loc(),
		[]string{},
		"one",
		"two",
		"",
	},
	{
		loc(),
		[]string{"test", "-s"},
		"one",
		"two",
		"test: missing parameter for -s\n",
	},
	{
		loc(),
		[]string{"test", "--opt"},
		"one",
		"two",
		"test: missing parameter for --opt\n",
	},
	{
		loc(),
		[]string{"test", "-svalue", "--opt=option"},
		"value",
		"option",
		"",
	},
	{
		loc(),
		[]string{"test", "-s", "value", "--opt", "option"},
		"value",
		"option",
		"",
	},
	{
		loc(),
		[]string{"test", "-swrong", "--opt=wrong", "-s", "value", "--opt", "option"},
		"value",
		"option",
		"",
	},
}

func TestString(t *testing.T) {
	for _, tt := range stringTests {
		reset()
		s := String('s', "one")
		opt := StringLong("opt", 0, "two")

		parse(tt.in)
		if s := checkError(tt.err); s != "" {
			t.Errorf("%s: %s", tt.where, s)
		}
		if *s != tt.sout {
			t.Errorf("%s: got s = %q, want %q", tt.where, *s, tt.sout)
		}
		if *opt != tt.optout {
			t.Errorf("%s: got opt = %q, want %q", tt.where, *opt, tt.optout)
		}
	}
}