mirror of https://github.com/go-python/gopy.git
bind: groundwork+test for structs with struct values
This commit is contained in:
parent
84e83328f8
commit
6cd8c71b94
|
@ -89,3 +89,22 @@ func (p *Person) Salary(h int) (int, error) {
|
|||
}
|
||||
return h * 10, nil
|
||||
}
|
||||
|
||||
// Couple is a pair of persons
|
||||
type Couple struct {
|
||||
P1 Person
|
||||
P2 Person
|
||||
}
|
||||
|
||||
// FIXME(sbinet) -- expose!
|
||||
// NewCouple returns a new couple made of the p1 and p2 persons.
|
||||
func newCouple(p1, p2 Person) Couple {
|
||||
return Couple{
|
||||
P1: p1,
|
||||
P2: p2,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Couple) String() string {
|
||||
return fmt.Sprintf("hi.Couple{P1=%v, P2=%v}", c.P1, c.P2)
|
||||
}
|
||||
|
|
|
@ -89,3 +89,10 @@ print "--- hi.NewPerson('me', 666):", hi.NewPerson("me", 666)
|
|||
print "--- hi.NewPersonWithAge(666):", hi.NewPersonWithAge(666)
|
||||
print "--- hi.NewActivePerson(4):", hi.NewActivePerson(4)
|
||||
|
||||
## test Couple
|
||||
print "--- c = hi.Couple()..."
|
||||
c = hi.Couple()
|
||||
print c
|
||||
|
||||
## FIXME(sbinet) -- segfaults!
|
||||
#print "--- c.P1:", c.P1
|
||||
|
|
|
@ -115,6 +115,8 @@ caught: Person.__init__ takes no argument | err-type: <type 'exceptions.TypeErro
|
|||
--- hi.NewPerson('me', 666): hi.Person{Name="me", Age=666}
|
||||
--- hi.NewPersonWithAge(666): hi.Person{Name="stranger", Age=666}
|
||||
--- hi.NewActivePerson(4): hi.Person{Name="", Age=0}
|
||||
--- c = hi.Couple()...
|
||||
hi.Couple{P1=hi.Person{Name="", Age=0}, P2=hi.Person{Name="", Age=0}}
|
||||
`)
|
||||
buf := new(bytes.Buffer)
|
||||
cmd = exec.Command("python2", "./test.py")
|
||||
|
|
Loading…
Reference in New Issue