Debian Codegraph @

internal/api/function_test.go

raw symbols SCIP
1 package api
2
3 import (
4 "strings"
5 "testing"
6
7 "github.com/mmcloughlin/avo/internal/inst"
8 )
9
10 func TestFunctionsDuplicateFormSignatures(t *testing.T) {
11 // Test for duplicate form signatures within a given function. This could
12 // manifest as duplicate case statements in generated code.
13 fns := InstructionsFunctions(inst.Instructions)
14 for _, fn := range fns {
15 fn := fn // scopelint
16 t.Run(fn.Name(), func(t *testing.T) {
17 seen := map[string]bool{}
18 for _, f := range fn.Forms {
19 sig := strings.Join(f.Signature(), "_")
20 t.Log(sig)
21 if seen[sig] {
22 t.Fatalf("duplicate: %s", sig)
23 }
24 seen[sig] = true
25 }
26 })
27 }
28 }
29
30 func TestFunctionsUniqueArgNames(t *testing.T) {
31 fns := InstructionsFunctions(inst.Instructions)
32 for _, fn := range fns {
33 s := fn.Signature()
34 for _, n := range fn.Arities() {
35 if n == 0 {
36 continue
37 }
38 names := map[string]bool{}
39 for j := 0; j < n; j++ {
40 names[s.ParameterName(j)] = true
41 }
42 if len(names) != n {
43 t.Errorf("repeated argument for instruction %s", fn.Name())
44 }
45 if _, found := names[""]; found {
46 t.Errorf("empty argument name for instruction %s", fn.Name())
47 }
48 }
49 }
50 }