mirror of
https://github.com/golang/go
synced 2024-09-18 15:32:18 +00:00
b1a398cf0f
For generic functions, we have to leave the builtins in OCALL form, rather than transform to specific ops, since we don't know the exact types involved. Allow export/import of builtins in OCALL form. Added new export/import test mapimp.go. Change-Id: I571f8eeaa13b4f69389dbdb9afb6cc61924b9bf2 Reviewed-on: https://go-review.googlesource.com/c/go/+/321750 Trust: Dan Scales <danscales@google.com> Reviewed-by: Keith Randall <khr@golang.org>
29 lines
659 B
Go
29 lines
659 B
Go
// Copyright 2021 The Go 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 main
|
|
|
|
import (
|
|
"a"
|
|
"fmt"
|
|
"reflect"
|
|
"strconv"
|
|
)
|
|
|
|
func main() {
|
|
got := a.Mapper([]int{1, 2, 3}, strconv.Itoa)
|
|
want := []string{"1", "2", "3"}
|
|
if !reflect.DeepEqual(got, want) {
|
|
panic(fmt.Sprintf("got %s, want %s", got, want))
|
|
}
|
|
|
|
fgot := a.Mapper([]float64{2.5, 2.3, 3.5}, func(f float64) string {
|
|
return strconv.FormatFloat(f, 'f', -1, 64)
|
|
})
|
|
fwant := []string{"2.5", "2.3", "3.5"}
|
|
if !reflect.DeepEqual(fgot, fwant) {
|
|
panic(fmt.Sprintf("got %s, want %s", fgot, fwant))
|
|
}
|
|
}
|