1
2
3
4
5 package specgen
6
7 import (
8 "simd/archsimd/_gen/specgen/specexpr"
9 "testing"
10 )
11
12 func TestFuncSignature(t *testing.T) {
13 int32x4 := specexpr.Vector{Elem: specexpr.Basic{Base: "int", Bits: 32}, Width: specexpr.Int(128)}
14 intType := specexpr.Basic{Base: "int", Bits: 0}
15
16 tests := []struct {
17 name string
18 fn Func
19 want string
20 }{
21 {
22 name: "method with named receiver, in, and out",
23 fn: Func{
24 Name: "Add",
25 Recv: Arg{Name: "x", Type: int32x4},
26 In: []Arg{{Name: "y", Type: int32x4}},
27 Out: []Arg{{Name: "z", Type: int32x4}},
28 },
29 want: "func (x Int32x4) Add(y Int32x4) (z Int32x4)",
30 },
31 {
32 name: "method with omitted names",
33 fn: Func{
34 Name: "Add",
35 Recv: Arg{Name: "", Type: int32x4},
36 In: []Arg{{Name: "", Type: int32x4}},
37 Out: []Arg{{Name: "", Type: int32x4}},
38 },
39 want: "func (Int32x4) Add(Int32x4) Int32x4",
40 },
41 {
42 name: "method with multiple unnamed results",
43 fn: Func{
44 Name: "DivMod",
45 Recv: Arg{Name: "x", Type: int32x4},
46 In: []Arg{{Name: "", Type: int32x4}},
47 Out: []Arg{{Name: "", Type: int32x4}, {Name: "", Type: intType}},
48 },
49 want: "func (x Int32x4) DivMod(Int32x4) (Int32x4, int)",
50 },
51 {
52 name: "method with mixed named and unnamed",
53 fn: Func{
54 Name: "DivMod",
55 Recv: Arg{Name: "x", Type: int32x4},
56 In: []Arg{{Name: "", Type: int32x4}},
57 Out: []Arg{{Name: "", Type: int32x4}, {Name: "err", Type: intType}},
58 },
59 want: "func (x Int32x4) DivMod(Int32x4) (_ Int32x4, err int)",
60 },
61 {
62 name: "package function with no receiver and no results",
63 fn: Func{
64 Name: "Reset",
65 },
66 want: "func Reset()",
67 },
68 }
69
70 for _, tc := range tests {
71 t.Run(tc.name, func(t *testing.T) {
72 got := tc.fn.Signature()
73 if got != tc.want {
74 t.Errorf("Signature() = %q, want %q", got, tc.want)
75 }
76 })
77 }
78 }
79
View as plain text