31 lines
694 B
Go
31 lines
694 B
Go
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).unwrap()
|
|
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 := gotlinResultUnwrap(gotlinJSONDecode[[]Account](body))", "json.Unmarshal(body, &value)"} {
|
|
if !strings.Contains(string(out), want) {
|
|
t.Fatalf("generated Go missing %q:\n%s", want, out)
|
|
}
|
|
}
|
|
}
|