Debian Codegraph @

counter_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 getoptscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/
6
7 import (
8 "fmtscip-go gomod github.com/golang/go/src go1.13 fmt/"
9 "stringsscip-go gomod github.com/golang/go/src go1.13 strings/"
10 "testingscip-go gomod github.com/golang/go/src go1.13 testing/"
11 )
12
13 var counterTestsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/counterTests. = []struct {
14 wherescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/counterTests:where. string
15 inscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/counterTests:in. []string
16 cscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/counterTests:c. int
17 cntscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/counterTests:cnt. int
18 errscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/counterTests:err. string
19 }{
20 {
21 locscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/loc().(),
22 []string{},
23 0,
24 0,
25 "",
26 },
27 {
28 locscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/loc().(),
29 []string{"test", "-c", "--cnt"},
30 1,
31 1,
32 "",
33 },
34 {
35 locscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/loc().(),
36 []string{"test", "-cc", "-c", "--cnt", "--cnt"},
37 3,
38 2,
39 "",
40 },
41 {
42 locscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/loc().(),
43 []string{"test", "--c=17", "--cnt=42"},
44 17,
45 42,
46 "",
47 },
48 {
49 locscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/loc().(),
50 []string{"test", "--cnt=false"},
51 0, 0,
52 "test: not a valid number: false\n",
53 },
54 }
55
56 func TestCounterscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/TestCounter().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
57 for x, tt := range counterTestsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/counterTests. {
58 resetscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/reset().()
59 c := Counterscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Counter().('c')
60 cnt := CounterLongscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CounterLong().("cnt", 0)
61 if stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Indexscip-go gomod github.com/golang/go/src go1.13 strings/Index().(tt.wherescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/counterTests:where., ":-") > 0 {
62 tt.wherescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/counterTests:where. = fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("#%d", x)
63 }
64
65 parsescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/parse().(tt.inscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/counterTests:in.)
66 if s := checkErrorscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/checkError().(tt.errscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/counterTests:err.); s != "" {
67 t.Errorfscip-go gomod github.com/golang/go/src go1.13 testing/common#Errorf().("%s: %s", tt.wherescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/counterTests:where., s)
68 }
69 if got, want := *c, tt.cscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/counterTests:c.; got != want {
70 t.Errorfscip-go gomod github.com/golang/go/src go1.13 testing/common#Errorf().("%s: got %v, want %v", tt.wherescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/counterTests:where., got, want)
71 }
72 if got, want := *cnt, tt.cntscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/counterTests:cnt.; got != want {
73 t.Errorfscip-go gomod github.com/golang/go/src go1.13 testing/common#Errorf().("%s: got %v, want %v", tt.wherescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/counterTests:where., got, want)
74 }
75 }
76
77 resetscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/reset().()
78 c := 5
79 opt := CounterVarscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CounterVar().(&c, 'c')
80 parsescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/parse().([]string{"test", "-c"})
81 if c != 6 {
82 t.Errorfscip-go gomod github.com/golang/go/src go1.13 testing/common#Errorf().("got %d, want 6", c)
83 }
84 if opt.Countscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Option#Count.() != 1 {
85 t.Errorfscip-go gomod github.com/golang/go/src go1.13 testing/common#Errorf().("got %d, want 1", c)
86 }
87 Resetscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Reset().()
88 if c != 5 {
89 t.Errorfscip-go gomod github.com/golang/go/src go1.13 testing/common#Errorf().("got %d, want 5", c)
90 }
91 }