Debian Codegraph @

session/command_handler_test.go

raw symbols SCIP
1 package sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/
2
3 import (
4 "testingscip-go gomod github.com/golang/go/src go1.16 testing/"
5 )
6
7 func sameStringsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/sameStrings().(a []string, b []string) bool {
8 if len(a) != len(b) {
9 return false
10 }
11 for i, v := range a {
12 if v != b[i] {
13 return false
14 }
15 }
16 return true
17 }
18
19 func assertPanicscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/assertPanic().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#, msg string, f func()) {
20 defer func() {
21 if r := recover(); r == nil {
22 t.Fatalscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatal().(msg)
23 }
24 }()
25 f()
26 }
27
28 func TestSessionCommandHandlerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/TestSessionCommandHandler().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
29 var units = []struct {
30 expr string
31 panic bool
32 parsed []string
33 }{
34 {"notvali(d", true, nil},
35 {`simple\s+(\d+)`, false, []string{"123"}},
36 }
37
38 for _, u := range units {
39 if u.panic {
40 assertPanicscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/assertPanic().(t, "", func() {
41 _ = NewCommandHandlerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewCommandHandler().("", u.expr, "", nil)
42 t.Fatalscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatal().("panic expected")
43 })
44 } else {
45 c := NewCommandHandlerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewCommandHandler().("", u.expr, "", nil)
46 shouldNotParse := "simple123"
47 shouldParse := "simple 123"
48
49 if parsed, _ := c.Parsescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/CommandHandler#Parse().(shouldNotParse); parsed {
50 t.Fatalfscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatalf().("should not parse '%s'", shouldNotParse)
51 } else if parsed, parts := c.Parsescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/CommandHandler#Parse().(shouldParse); !parsed {
52 t.Fatalfscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatalf().("should parse '%s'", shouldParse)
53 } else if !sameStringsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/sameStrings().(parts, u.parsed) {
54 t.Fatalfscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatalf().("expected '%v', got '%v'", u.parsed, parts)
55 }
56 }
57 }
58 }