(op string, xs ...[]string)
| 56 | } |
| 57 | |
| 58 | func cases(op string, xs ...[]string) string { |
| 59 | var types []string |
| 60 | for _, x := range xs { |
| 61 | types = append(types, x...) |
| 62 | } |
| 63 | |
| 64 | _, _ = fmt.Fprintf(os.Stderr, "Generating %s cases for %v\n", op, types) |
| 65 | |
| 66 | var out string |
| 67 | echo := func(s string, xs ...any) { |
| 68 | out += fmt.Sprintf(s, xs...) + "\n" |
| 69 | } |
| 70 | for _, a := range types { |
| 71 | echo(`case %v:`, a) |
| 72 | echo(`switch y := b.(type) {`) |
| 73 | for _, b := range types { |
| 74 | t := "int" |
| 75 | if isDuration(a) || isDuration(b) { |
| 76 | t = "time.Duration" |
| 77 | } |
| 78 | if isFloat(a) || isFloat(b) { |
| 79 | t = "float64" |
| 80 | } |
| 81 | echo(`case %v:`, b) |
| 82 | if op == "/" { |
| 83 | echo(`return float64(x) / float64(y)`) |
| 84 | } else { |
| 85 | echo(`return %v(x) %v %v(y)`, t, op, t) |
| 86 | } |
| 87 | } |
| 88 | echo(`}`) |
| 89 | } |
| 90 | return strings.TrimRight(out, "\n") |
| 91 | } |
| 92 | |
| 93 | func arrayEqualCases(xs ...[]string) string { |
| 94 | var types []string |
no test coverage detected
searching dependent graphs…