Add structured coroutines and explicit error handling
This commit is contained in:
parent
de1262b4cf
commit
fe62e81152
31 changed files with 1701 additions and 325 deletions
43
internal/lang/references_test.go
Normal file
43
internal/lang/references_test.go
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package lang
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGotlinClassesAreReferenceTypesByDefault(t *testing.T) {
|
||||
prog, err := Parse(`package demo
|
||||
class Repository
|
||||
class Service(val repository: Repository)
|
||||
fun create(): Service { return Service(Repository()) }
|
||||
fun many(): List<Repository> { return listOf(Repository()) }
|
||||
fun optional(): Repository? { return null }`)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
out, err := GenerateGo(prog)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, want := range []string{"repository *Repository", "func create() *Service", "func many() []*Repository", "func optional() *Repository"} {
|
||||
if !strings.Contains(string(out), want) {
|
||||
t.Fatalf("missing %q:\n%s", want, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestExplicitClassPointerRemainsCompatible(t *testing.T) {
|
||||
prog, err := Parse(`package demo
|
||||
class Repository
|
||||
fun use(repository: *Repository): *Repository { return repository }`)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
out, err := GenerateGo(prog)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Contains(string(out), "**Repository") || !strings.Contains(string(out), "repository *Repository") {
|
||||
t.Fatalf("unexpected explicit pointer output:\n%s", out)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue