Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into rmuller/diamond-python
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/jsii-pacmak/test/generated-code/__snapshots__/examples.test.ts.snap
#	packages/jsii-pacmak/test/generated-code/examples.test.ts
  • Loading branch information
RomainMuller committed Mar 15, 2021
2 parents 78a7d95 + daca06f commit 7a11eb7
Show file tree
Hide file tree
Showing 39 changed files with 3,502 additions and 1,802 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/1-bug.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ please leave the bux un-checked.
- [ ] `Python`
- [ ] `Java`
- [ ] .NET (`C#`, `F#`, ...)
- [ ] `Go`

### General Information
* **JSII Version:** <!-- Output of `jsii --version` -->
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/2-feature-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ please leave the bux un-checked.
- [ ] `Python`
- [ ] `Java`
- [ ] .NET (`C#`, `F#`, ...)
- [ ] `Go`

### General Information
* **JSII Version:** <!-- Output of `jsii --version` -->
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/3-guidance.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ please leave the bux un-checked.
- [ ] `Python`
- [ ] `Java`
- [ ] .NET (`C#`, `F#`, ...)
- [ ] `Go`

### General Information
* **JSII Version:** <!-- Output of `jsii --version` -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,32 @@
!!! danger
The **go** target is currently unstable and not suitable for production use.

To enable go package generation, add the **go** key with an empty object to the jsii targets configuration.
To enable go package generation, add the `go` key to the jsii targets configuration:

This will add generated go package code to your specified `outDir` for testing and experimentation.
- `packageName` (optional) - The name of the Go package name. If not specified,
package name will be derived from the JavaScript module name by removing
non-alphanumeric characters (e.g. `@aws-cdk/aws-s3` will be `awscdkawss3`). If
this is set on a submodule config file (`.jsiirc.json`), it refers to the
submodule package name.
- `moduleName` (required) - The name of the **target repository** in which this
module will be published (e.g. `github.com/foo/bar`). The module itself will
*always* be published under a subdirectory named according to the Go package
name of the module (e.g. `github.com/foo/bar/awscdk`).
- `versionSuffix` (optional) - Can be provided that will be appended at the end
of the module version.

```json
This will add generated go package code to your specified `outDir` under
`go/PACKAGE_NAME` (e.g. `dist/go/awscdklib`).

```js
{
"jsii": {
"targets": {
"go": {},
"go": {
"moduleName": "github.com/foo/bar", // REQUIRED
"packageName": "hello", // OPTIONAL
"versionSuffix": "-devprefix" // OPTIONAL
},
// ...
},
// ...
Expand Down
110 changes: 54 additions & 56 deletions packages/@jsii/go-runtime-test/project/compliance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ package tests

import (
"fmt"
"math"
"runtime"
"testing"
"time"

"github.com/aws/jsii/jsii-calc/go/jcb"
calc "github.com/aws/jsii/jsii-calc/go/jsiicalc/v3"
"github.com/aws/jsii/jsii-calc/go/jsiicalc/v3/composition"
"github.com/aws/jsii/jsii-calc/go/jsiicalc/v3/submodule/child"
"github.com/aws/jsii/jsii-calc/go/scopejsiicalcbase"
calclib "github.com/aws/jsii/jsii-calc/go/scopejsiicalclib"
"github.com/aws/jsii/jsii-calc/go/scopejsiicalclib/submodule"
"github.com/aws/jsii/jsii-calc/go/scopejsiicalclib/customsubmodulename"
"github.com/stretchr/testify/suite"
"math"
"runtime"
"testing"
"time"
)

func (suite *ComplianceSuite) TestStatics() {
Expand Down Expand Up @@ -62,7 +63,7 @@ func (suite *ComplianceSuite) TestPrimitiveTypes() {

func (suite *ComplianceSuite) TestUseNestedStruct() {
suite.FailTest("Nested types are not namespaced", "https://github.com/aws/jsii/pull/2650")
scopejsiicalcbase.StaticConsumer_Consume(submodule.NestedStruct{
jcb.StaticConsumer_Consume(customsubmodulename.NestingClass_NestedStruct{
Name: "Bond, James Bond",
})
}
Expand Down Expand Up @@ -143,7 +144,7 @@ func (suite *ComplianceSuite) TestCallMethods() {
assert.Equal(float64(20), calc.Value())

calc.Pow(5)
assert.Equal(float64(20 * 20 * 20 * 20 * 20), calc.Value())
assert.Equal(float64(20*20*20*20*20), calc.Value())

calc.Neg()
assert.Equal(float64(-3200000), calc.Value())
Expand All @@ -161,7 +162,7 @@ func (suite *ComplianceSuite) TestNodeStandardLibrary() {
assert.Equal("Hello, resource!", obj.FsReadFile())
}

func (suite* ComplianceSuite) TestDynamicTypes() {
func (suite *ComplianceSuite) TestDynamicTypes() {
assert := suite.Assert()
types := calc.NewAllTypes()

Expand Down Expand Up @@ -204,11 +205,11 @@ func (suite* ComplianceSuite) TestDynamicTypes() {
assert.Equal(float64(123), (types.AnyProperty()).([]interface{})[2])

// map
types.SetAnyProperty(map[string]string{ "MapKey": "MapValue" })
types.SetAnyProperty(map[string]string{"MapKey": "MapValue"})
assert.Equal("MapValue", ((types.AnyProperty()).(map[string]interface{}))["MapKey"])

// map of any
types.SetAnyProperty(map[string]interface{}{ "Goo": 19289812 })
types.SetAnyProperty(map[string]interface{}{"Goo": 19289812})
assert.Equal(float64(19289812), ((types.AnyProperty()).(map[string]interface{}))["Goo"])

// classes
Expand Down Expand Up @@ -260,27 +261,27 @@ func (suite *ComplianceSuite) TestUseEnumFromScopedModule() {
obj.SetFoo(calclib.EnumFromScopedModule_VALUE1)
assert.Equal(calclib.EnumFromScopedModule_VALUE1, obj.LoadFoo())
obj.SaveFoo(calclib.EnumFromScopedModule_VALUE2)
assert.Equal( calclib.EnumFromScopedModule_VALUE2, obj.Foo())
assert.Equal(calclib.EnumFromScopedModule_VALUE2, obj.Foo())
}

func (suite *ComplianceSuite) TestCreateObjectAndCtorOverloads() {
suite.NotApplicableTest("Golang does not have overloaded functions so the genearated class only has a single New function")
}

func (suite* ComplianceSuite) TestGetAndSetEnumValues() {
func (suite *ComplianceSuite) TestGetAndSetEnumValues() {
assert := suite.Assert()

calc := calc.NewCalculator(calc.CalculatorProps{})
calc.Add(9)
calc.Pow(3)
assert.Equal(composition.CompositionStringStyle_NORMAL, calc.StringStyle())
assert.Equal(composition.CompositeOperation_CompositionStringStyle_NORMAL, calc.StringStyle())

calc.SetStringStyle(composition.CompositionStringStyle_DECORATED)
assert.Equal(composition.CompositionStringStyle_DECORATED, calc.StringStyle())
calc.SetStringStyle(composition.CompositeOperation_CompositionStringStyle_DECORATED)
assert.Equal(composition.CompositeOperation_CompositionStringStyle_DECORATED, calc.StringStyle())
assert.Equal("<<[[{{(((1 * (0 + 9)) * (0 + 9)) * (0 + 9))}}]]>>", calc.ToString())
}

func (suite* ComplianceSuite) TestListInClassCanBeReadCorrectly() {
func (suite *ComplianceSuite) TestListInClassCanBeReadCorrectly() {
assert := suite.Assert()

classWithCollections := calc.NewClassWithCollections(map[string]string{}, []string{"one", "two"})
Expand All @@ -299,7 +300,7 @@ func newDerivedFromAllTypes() derivedFromAllTypes {
}
}

func (suite* ComplianceSuite) TestTestFluentApiWithDerivedClasses() {
func (suite *ComplianceSuite) TestTestFluentApiWithDerivedClasses() {
assert := suite.Assert()

obj := newDerivedFromAllTypes()
Expand All @@ -309,13 +310,13 @@ func (suite* ComplianceSuite) TestTestFluentApiWithDerivedClasses() {
assert.Equal(float64(12), obj.NumberProperty())
}

func (suite* ComplianceSuite) TestCanLoadEnumValues() {
func (suite *ComplianceSuite) TestCanLoadEnumValues() {
assert := suite.Assert()
assert.NotEmpty(calc.EnumDispenser_RandomStringLikeEnum())
assert.NotEmpty(calc.EnumDispenser_RandomIntegerLikeEnum())
}

func (suite* ComplianceSuite) TestCollectionOfInterfaces_ListOfStructs() {
func (suite *ComplianceSuite) TestCollectionOfInterfaces_ListOfStructs() {
assert := suite.Assert()

list := calc.InterfaceCollections_ListOfStructs()
Expand All @@ -332,15 +333,15 @@ func newDoNotOverridePrivates() doNotOverridePrivates {
}
}

func (x* doNotOverridePrivates) PrivateProperty() string {
func (x *doNotOverridePrivates) PrivateProperty() string {
return "privateProperty-Override"
}

func (x* doNotOverridePrivates) SetPrivateProperty(value string) {
func (x *doNotOverridePrivates) SetPrivateProperty(value string) {
panic("Boom")
}

func (suite* ComplianceSuite) TestDoNotOverridePrivates_property_getter_public() {
func (suite *ComplianceSuite) TestDoNotOverridePrivates_property_getter_public() {
assert := suite.Assert()

obj := newDoNotOverridePrivates()
Expand All @@ -351,11 +352,11 @@ func (suite* ComplianceSuite) TestDoNotOverridePrivates_property_getter_public()
assert.Equal("MyNewValue", obj.PrivatePropertyValue())
}

func (suite* ComplianceSuite) TestEqualsIsResistantToPropertyShadowingResultVariable() {
func (suite *ComplianceSuite) TestEqualsIsResistantToPropertyShadowingResultVariable() {
assert := suite.Assert()
first := calc.StructWithJavaReservedWords{ Default: "one" }
second := calc.StructWithJavaReservedWords { Default: "one" }
third := calc.StructWithJavaReservedWords { Default: "two" }
first := calc.StructWithJavaReservedWords{Default: "one"}
second := calc.StructWithJavaReservedWords{Default: "one"}
third := calc.StructWithJavaReservedWords{Default: "two"}
assert.Equal(first, second)
assert.NotEqual(first, third)
}
Expand All @@ -370,15 +371,15 @@ func newOverridableProtectedMemberDerived() overridableProtectedMemberDerived {
}
}

func (x* overridableProtectedMemberDerived) OverrideReadOnly() string {
func (x *overridableProtectedMemberDerived) OverrideReadOnly() string {
return "Cthulhu "
}

func (x* overridableProtectedMemberDerived) OverrideReadeWrite() string {
func (x *overridableProtectedMemberDerived) OverrideReadeWrite() string {
return "Fhtagn!"
}

func (suite* ComplianceSuite) TestCanOverrideProtectedGetter() {
func (suite *ComplianceSuite) TestCanOverrideProtectedGetter() {
suite.FailTest("Overrides are not supported yet", "https://github.com/aws/jsii/issues/2048")

assert := suite.Assert()
Expand All @@ -402,18 +403,17 @@ func newImplementsAdditionalInterface(s calc.StructB) implementsAdditionalInterf
}
}

func (suite* ComplianceSuite) TestInterfacesCanBeUsedTransparently_WhenAddedToJsiiType() {
func (suite *ComplianceSuite) TestInterfacesCanBeUsedTransparently_WhenAddedToJsiiType() {
suite.FailTest("Overrides not supported", "https://github.com/aws/jsii/issues/2048")
assert := suite.Assert()


expected := calc.StructB{RequiredString: "It's Britney b**ch!"}
delegate := newImplementsAdditionalInterface(expected)
consumer := calc.NewConsumePureInterface(delegate)
assert.Equal(expected, consumer.WorkItBaby())
}

func (suite* ComplianceSuite) TestStructs_nonOptionalequals() {
func (suite *ComplianceSuite) TestStructs_nonOptionalequals() {
assert := suite.Assert()

structA := calc.StableStruct{ReadonlyProperty: "one"}
Expand All @@ -423,10 +423,9 @@ func (suite* ComplianceSuite) TestStructs_nonOptionalequals() {
assert.NotEqual(structC, structA)
}

func (suite* ComplianceSuite) TestTestInterfaceParameter() {
func (suite *ComplianceSuite) TestTestInterfaceParameter() {
assert := suite.Assert()


obj := calc.NewJsObjectLiteralForInterface()
friendly := obj.GiveMeFriendly()
assert.Equal("I am literally friendly!", friendly.Hello())
Expand All @@ -436,7 +435,7 @@ func (suite* ComplianceSuite) TestTestInterfaceParameter() {
assert.Equal("I am literally friendly! Let me buy you a drink!", betterGreeting)
}

func (suite* ComplianceSuite) TestLiftedKwargWithSameNameAsPositionalArg() {
func (suite *ComplianceSuite) TestLiftedKwargWithSameNameAsPositionalArg() {
assert := suite.Assert()

// This is a replication of a test that mostly affects languages with keyword arguments (e.g: Python, Ruby, ...)
Expand Down Expand Up @@ -468,7 +467,7 @@ func newMulTen(value float64) mulTen {
}
}

func (suite* ComplianceSuite) TestCreationOfNativeObjectsFromJavaScriptObjects() {
func (suite *ComplianceSuite) TestCreationOfNativeObjectsFromJavaScriptObjects() {
assert := suite.Assert()

types := calc.NewAllTypes()
Expand All @@ -480,7 +479,6 @@ func (suite* ComplianceSuite) TestCreationOfNativeObjectsFromJavaScriptObjects()

suite.FailTest("??", "??")


nativeObj := newAddTen(10)
types.SetAnyProperty(nativeObj)
result1 := types.AnyProperty()
Expand Down Expand Up @@ -558,7 +556,7 @@ func (suite *ComplianceSuite) TestPropertyOverrides_Interfaces() {
assert.Equal("READ_ONLY_STRING", interact.JustRead())

suite.FailTest("Not sure. Most likely related to the missing setters on interfaces", "https://github.com/aws/jsii/issues/2665")
assert.Equal( "Hello!?", interact.WriteAndRead("Hello"))
assert.Equal("Hello!?", interact.WriteAndRead("Hello"))
}

type TestPropertyOverridesInterfacesIInterfaceWithProperties struct {
Expand Down Expand Up @@ -677,7 +675,7 @@ func (suite *ComplianceSuite) TestStructs_containsNullChecks() {
suite.FailTest("No validation of required fields in structs", "https://github.com/aws/jsii/issues/2672")

// we expect a failure here when we pass the struct to js
assert.PanicsWithError("", func() {obj.ReadFirstNumber(s)})
assert.PanicsWithError("", func() { obj.ReadFirstNumber(s) })
}

func (suite *ComplianceSuite) TestUnionPropertiesWithBuilder() {
Expand Down Expand Up @@ -776,9 +774,9 @@ func (suite *ComplianceSuite) TestReturnAbstract() {
obj := calc.NewAbstractClassReturner()
obj2 := obj.GiveMeAbstract()

assert.Equal("Hello, John!!", obj2.AbstractMethod("John"));
assert.Equal("propFromInterfaceValue", obj2.PropFromInterface());
assert.Equal(float64(42), obj2.NonAbstractMethod());
assert.Equal("Hello, John!!", obj2.AbstractMethod("John"))
assert.Equal("propFromInterfaceValue", obj2.PropFromInterface())
assert.Equal(float64(42), obj2.NonAbstractMethod())

iface := obj.GiveMeInterface()
assert.Equal("propFromInterfaceValue", iface.PropFromInterface())
Expand All @@ -795,22 +793,22 @@ func (suite *ComplianceSuite) TestCollectionOfInterfaces_MapOfInterfaces() {
func (suite *ComplianceSuite) TestStructs_multiplePropertiesEquals() {
assert := suite.Assert()
structA := calc.DiamondInheritanceTopLevelStruct{
BaseLevelProperty: "one",
FirstMidLevelProperty: "two",
BaseLevelProperty: "one",
FirstMidLevelProperty: "two",
SecondMidLevelProperty: "three",
TopLevelProperty: "four",
TopLevelProperty: "four",
}
structB := calc.DiamondInheritanceTopLevelStruct{
BaseLevelProperty: "one",
FirstMidLevelProperty: "two",
BaseLevelProperty: "one",
FirstMidLevelProperty: "two",
SecondMidLevelProperty: "three",
TopLevelProperty: "four",
TopLevelProperty: "four",
}
structC := calc.DiamondInheritanceTopLevelStruct{
BaseLevelProperty: "one",
FirstMidLevelProperty: "two",
BaseLevelProperty: "one",
FirstMidLevelProperty: "two",
SecondMidLevelProperty: "different",
TopLevelProperty: "four",
TopLevelProperty: "four",
}

assert.Equal(structA, structB)
Expand All @@ -829,7 +827,7 @@ type myDoNotOverridePrivates struct {
calc.DoNotOverridePrivates
}

func (s *myDoNotOverridePrivates) PrivateProperty() string {
func (s *myDoNotOverridePrivates) PrivateProperty() string {
return "privateProperty-Override"
}

Expand All @@ -851,10 +849,10 @@ func (suite *ComplianceSuite) TestDoNotOverridePrivates_property_getter_private(
func (suite *ComplianceSuite) TestStructs_withDiamondInheritance_correctlyDedupeProperties() {
assert := suite.Assert()
s := calc.DiamondInheritanceTopLevelStruct{
BaseLevelProperty: "base",
FirstMidLevelProperty: "mid1",
BaseLevelProperty: "base",
FirstMidLevelProperty: "mid1",
SecondMidLevelProperty: "mid2",
TopLevelProperty: "top",
TopLevelProperty: "top",
}

assert.Equal("base", s.BaseLevelProperty)
Expand Down
Loading

0 comments on commit 7a11eb7

Please sign in to comment.