~vtuson/scopecreator/twitter-template

« back to all changes in this revision

Viewing changes to src/go/src/github.com/jessevdk/go-flags/long_test.go

  • Committer: Victor Palau
  • Date: 2015-03-11 14:24:42 UTC
  • Revision ID: vtuson@gmail.com-20150311142442-f2pxp111c8ynv232
public release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package flags
 
2
 
 
3
import (
 
4
        "testing"
 
5
)
 
6
 
 
7
func TestLong(t *testing.T) {
 
8
        var opts = struct {
 
9
                Value bool `long:"value"`
 
10
        }{}
 
11
 
 
12
        ret := assertParseSuccess(t, &opts, "--value")
 
13
 
 
14
        assertStringArray(t, ret, []string{})
 
15
 
 
16
        if !opts.Value {
 
17
                t.Errorf("Expected Value to be true")
 
18
        }
 
19
}
 
20
 
 
21
func TestLongArg(t *testing.T) {
 
22
        var opts = struct {
 
23
                Value string `long:"value"`
 
24
        }{}
 
25
 
 
26
        ret := assertParseSuccess(t, &opts, "--value", "value")
 
27
 
 
28
        assertStringArray(t, ret, []string{})
 
29
        assertString(t, opts.Value, "value")
 
30
}
 
31
 
 
32
func TestLongArgEqual(t *testing.T) {
 
33
        var opts = struct {
 
34
                Value string `long:"value"`
 
35
        }{}
 
36
 
 
37
        ret := assertParseSuccess(t, &opts, "--value=value")
 
38
 
 
39
        assertStringArray(t, ret, []string{})
 
40
        assertString(t, opts.Value, "value")
 
41
}
 
42
 
 
43
func TestLongDefault(t *testing.T) {
 
44
        var opts = struct {
 
45
                Value string `long:"value" default:"value"`
 
46
        }{}
 
47
 
 
48
        ret := assertParseSuccess(t, &opts)
 
49
 
 
50
        assertStringArray(t, ret, []string{})
 
51
        assertString(t, opts.Value, "value")
 
52
}
 
53
 
 
54
func TestLongOptional(t *testing.T) {
 
55
        var opts = struct {
 
56
                Value string `long:"value" optional:"yes" optional-value:"value"`
 
57
        }{}
 
58
 
 
59
        ret := assertParseSuccess(t, &opts, "--value")
 
60
 
 
61
        assertStringArray(t, ret, []string{})
 
62
        assertString(t, opts.Value, "value")
 
63
}
 
64
 
 
65
func TestLongOptionalArg(t *testing.T) {
 
66
        var opts = struct {
 
67
                Value string `long:"value" optional:"yes" optional-value:"value"`
 
68
        }{}
 
69
 
 
70
        ret := assertParseSuccess(t, &opts, "--value", "no")
 
71
 
 
72
        assertStringArray(t, ret, []string{"no"})
 
73
        assertString(t, opts.Value, "value")
 
74
}
 
75
 
 
76
func TestLongOptionalArgEqual(t *testing.T) {
 
77
        var opts = struct {
 
78
                Value string `long:"value" optional:"yes" optional-value:"value"`
 
79
        }{}
 
80
 
 
81
        ret := assertParseSuccess(t, &opts, "--value=value", "no")
 
82
 
 
83
        assertStringArray(t, ret, []string{"no"})
 
84
        assertString(t, opts.Value, "value")
 
85
}