Debian Codegraph @

enum_test.go

raw symbols SCIP
1 // Copyright 2013 Google Inc. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package getopt
6
7 import (
8 "fmt"
9 "strings"
10 "testing"
11 )
12
13 var enumTests = []struct {
14 where string
15 in []string
16 values []string
17 out string
18 err string
19 }{
20 {
21 loc(),
22 nil,
23 []string{},
24 "",
25 "",
26 },
27 {
28 loc(),
29 []string{"test", "-e", "val1"},
30 []string{"val1", "val2"},
31 "val1",
32 "",
33 },
34 {
35 loc(),
36 []string{"test", "-e", "val1", "-e", "val2"},
37 []string{"val1", "val2"},
38 "val2",
39 "",
40 },
41 {
42 loc(),
43 []string{"test", "-e", "val3"},
44 []string{"val1", "val2"},
45 "",
46 "test: invalid value: val3\n",
47 },
48 }
49
50 func TestEnum(t *testing.T) {
51 for x, tt := range enumTests {
52 if strings.Index(tt.where, ":-") > 0 {
53 tt.where = fmt.Sprintf("#%d", x)
54 }
55
56 reset()
57 e := Enum('e', tt.values)
58 parse(tt.in)
59 if s := checkError(tt.err); s != "" {
60 t.Errorf("%s: %s", tt.where, s)
61 }
62 if *e != tt.out {
63 t.Errorf("%s: got %v, want %v", tt.where, *e, tt.out)
64 }
65 }
66 }