bind: test typed constants and typenamed vars

This commit is contained in:
Sebastien Binet 2015-08-12 10:54:25 +02:00
parent 1b431ce89d
commit f6940af31c
5 changed files with 144 additions and 0 deletions

View File

@ -0,0 +1,32 @@
// Copyright 2015 The go-python Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package consts
const (
C1 = "c1"
C2 = 42
C3 = 666.666
)
const (
C4 string = "c4"
C5 int = 42
C6 uint = 42
C7 float64 = 666.666
)
type Kind int
const (
Kind1 Kind = 1
Kind2 = 2
)
// FIXME: also use an unexported type
// type kind int
// const (
// Kind3 kind = 3
// Kind4 = 4
// )

23
_examples/consts/test.py Normal file
View File

@ -0,0 +1,23 @@
# Copyright 2015 The go-python Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
## py2/py3 compat
from __future__ import print_function
import consts
print("c1 = %s" % consts.GetC1())
print("c2 = %s" % consts.GetC2())
print("c3 = %s" % consts.GetC3())
print("c4 = %s" % consts.GetC4())
print("c5 = %s" % consts.GetC5())
print("c6 = %s" % consts.GetC6())
print("c7 = %s" % consts.GetC7())
print("k1 = %s" % consts.GetKind1())
print("k2 = %s" % consts.GetKind2())
## FIXME: unexported types not supported yet (issue #44)
#print("k3 = %s" % consts.GetKind3())
#print("k4 = %s" % consts.GetKind4())

23
_examples/vars/test.py Normal file
View File

@ -0,0 +1,23 @@
# Copyright 2015 The go-python Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
## py2/py3 compat
from __future__ import print_function
import vars
print("v1 = %s" % vars.GetV1())
print("v2 = %s" % vars.GetV2())
print("v3 = %s" % vars.GetV3())
print("v4 = %s" % vars.GetV4())
print("v5 = %s" % vars.GetV5())
print("v6 = %s" % vars.GetV6())
print("v7 = %s" % vars.GetV7())
print("k1 = %s" % vars.GetKind1())
print("k2 = %s" % vars.GetKind2())
## FIXME: unexported types not supported yet (issue #44)
#print("k3 = %s" % vars.GetKind3())
#print("k4 = %s" % vars.GetKind4())

32
_examples/vars/vars.go Normal file
View File

@ -0,0 +1,32 @@
// Copyright 2015 The go-python Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package vars
var (
V1 = "v1"
V2 = 42
V3 = 666.666
)
var (
V4 string = "c4"
V5 int = 42
V6 uint = 42
V7 float64 = 666.666
)
type Kind int
var (
Kind1 Kind = 1
Kind2 = 2
)
// FIXME: also use an unexported type
// type kind int
// var (
// Kind3 kind = 3
// Kind4 = 4
// )

View File

@ -340,3 +340,37 @@ s.Upper('boo')= 'BOO'
`),
})
}
func TestBindConsts(t *testing.T) {
t.Parallel()
testPkg(t, pkg{
path: "_examples/consts",
want: []byte(`c1 = c1
c2 = 42
c3 = 666.666
c4 = c4
c5 = 42
c6 = 42
c7 = 666.666
k1 = 1
k2 = 2
`),
})
}
func TestBindVars(t *testing.T) {
t.Parallel()
testPkg(t, pkg{
path: "_examples/vars",
want: []byte(`v1 = v1
v2 = 42
v3 = 666.666
v4 = c4
v5 = 42
v6 = 42
v7 = 666.666
k1 = 1
k2 = 2
`),
})
}