Expand Gotlin language and tooling
This commit is contained in:
parent
8f4f858d86
commit
de1262b4cf
41 changed files with 6059 additions and 379 deletions
31
internal/lang/json_decode_test.go
Normal file
31
internal/lang/json_decode_test.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package lang
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGenerateGoJSONDecodeReturnsTypedValue(t *testing.T) {
|
||||
prog, err := Parse(`
|
||||
package demo
|
||||
|
||||
import json encoding.json
|
||||
|
||||
fun decode(body: ByteSlice): List<Account> {
|
||||
val accounts = json.decode<List<Account>>(body)
|
||||
return accounts
|
||||
}
|
||||
`)
|
||||
if err != nil {
|
||||
t.Fatalf("parse failed: %v", err)
|
||||
}
|
||||
out, err := GenerateGo(prog)
|
||||
if err != nil {
|
||||
t.Fatalf("generation failed: %v", err)
|
||||
}
|
||||
for _, want := range []string{"accounts := gotlinAutoThrow(gotlinJSONDecode[[]Account](body))", "json.Unmarshal(body, &value)"} {
|
||||
if !strings.Contains(string(out), want) {
|
||||
t.Fatalf("generated Go missing %q:\n%s", want, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue