Skip to content

Commit ac88620

Browse files
authored
_examples,bind: add a test for types.Named
This CL adds a test for #220.
1 parent 87be7f7 commit ac88620

File tree

6 files changed

+39
-6
lines changed

6 files changed

+39
-6
lines changed

_examples/structs/structs.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,10 @@ type S2 struct {
2727
Public int
2828
private int
2929
}
30+
31+
type Dim int
32+
33+
type S3 struct {
34+
X Dim
35+
Y Dim
36+
}

_examples/structs/test.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Use of this source code is governed by a BSD-style
33
# license that can be found in the LICENSE file.
44

5-
## py2/py3 compat
5+
# py2/py3 compat
66
from __future__ import print_function
77

88
import structs
@@ -16,7 +16,7 @@
1616

1717
print("s1 = structs.S1()")
1818
s1 = structs.S1()
19-
print("s1 = %s" %(s1,))
19+
print("s1 = %s" % (s1,))
2020

2121
try:
2222
s1 = structs.S1(1)
@@ -31,17 +31,17 @@
3131
print("caught error: %s" % (err,))
3232
pass
3333

34-
34+
3535
print("s2 = structs.S2()")
3636
s2 = structs.S2(1)
3737
print("s2 = %s" % (s2,))
3838

3939
try:
40-
s2 = structs.S2(1,2)
40+
s2 = structs.S2(1, 2)
4141
except Exception as err:
4242
print("caught error: %s" % (err,))
4343
pass
44-
44+
4545
try:
4646
s2 = structs.S2(42)
4747
print("s2 = %s" % (s2,))
@@ -51,14 +51,17 @@
5151
print("caught error: %s" % (err,))
5252
pass
5353

54+
5455
class S2Child(structs.S2):
5556
def __init__(self, a, b):
5657
super(S2Child, self).__init__(a)
5758
self.local = b
59+
5860
def __str__(self):
5961
return ("S2Child{S2: %s, local: %d}"
6062
% (super(S2Child, self).__str__(), self.local))
6163

64+
6265
try:
6366
s2child = S2Child(42, 123)
6467
print("s2child = %s" % (s2child,))
@@ -69,4 +72,13 @@ def __str__(self):
6972
print("caught error: %s" % (err,))
7073
pass
7174

75+
try:
76+
val = structs.S3()
77+
val.X = 3
78+
val.Y = 4
79+
print("s3.X,Y = %d,%d" % (val.X, val.Y))
80+
except Exception as err:
81+
print("caught error: %s" % (err,))
82+
pass
83+
7284
print("OK")

bind/gen_struct.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ func (g *pyGen) genIfaceInit(ifc *Interface) {
299299
handle=A Go-side object is always initialized with an explicit handle=arg
300300
"""
301301
`)
302+
302303
g.pywrap.Printf("if len(kwargs) == 1 and 'handle' in kwargs:\n")
303304
g.pywrap.Indent()
304305
g.pywrap.Printf("self.handle = kwargs['handle']\n")

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ require (
66
github.com/gonuts/commander v0.1.0
77
github.com/gonuts/flag v0.1.0
88
github.com/pkg/errors v0.8.1
9-
golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f
9+
golang.org/x/tools v0.0.0-20200326194725-b1df9901287c
1010
)

go.sum

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,23 @@ github.com/gonuts/flag v0.1.0 h1:fqMv/MZ+oNGu0i9gp0/IQ/ZaPIDoAZBOBaJoV7viCWM=
44
github.com/gonuts/flag v0.1.0/go.mod h1:ZTmTGtrSPejTo/SRNhCqwLTmiAgyBdCkLYhHrAoBdz4=
55
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
66
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
7+
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
78
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
9+
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
10+
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
11+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
812
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
13+
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
914
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
15+
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
1016
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
17+
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1118
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
1219
golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f h1:ESK9Jb5JOE+y4u+ozMQeXfMHwEHm6zVbaDQkeaj6wI4=
1320
golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
21+
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
22+
golang.org/x/tools v0.0.0-20200326194725-b1df9901287c h1:lOHr9KzDy5SxEmffvQO+sLmartg6RfDELX60/tv3qFg=
23+
golang.org/x/tools v0.0.0-20200326194725-b1df9901287c/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8=
1424
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
25+
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
26+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

main_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ s2child = S2Child{S2: structs.S2{Public=42, handle=8, local=123}, local: 123}
390390
s2child.Public = 42
391391
s2child.local = 123
392392
caught error: 'S2Child' object has no attribute 'private'
393+
s3.X,Y = 3,4
393394
OK
394395
`),
395396
})

0 commit comments

Comments
 (0)