48 lines
522 B
Go
48 lines
522 B
Go
|
package crawler
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
type Super interface {
|
||
|
Method()
|
||
|
}
|
||
|
|
||
|
type sss struct{}
|
||
|
|
||
|
func (s *sss) Method() {
|
||
|
fmt.Println("Super")
|
||
|
}
|
||
|
|
||
|
type Child struct {
|
||
|
sss
|
||
|
}
|
||
|
|
||
|
func (c *Child) Method() {
|
||
|
c.sss.Method()
|
||
|
fmt.Println("Child")
|
||
|
}
|
||
|
|
||
|
func TestGene(t *testing.T) {
|
||
|
c := Child{}
|
||
|
c.Method()
|
||
|
|
||
|
var s Super = &Child{}
|
||
|
s.Method()
|
||
|
|
||
|
}
|
||
|
|
||
|
func TestExistInterface(t *testing.T) {
|
||
|
|
||
|
m := make(map[string]Super, 0)
|
||
|
m["test"] = &Child{}
|
||
|
|
||
|
_, ok := m["test1"]
|
||
|
if ok {
|
||
|
fmt.Println(ok)
|
||
|
} else {
|
||
|
fmt.Println(ok)
|
||
|
}
|
||
|
}
|