| 91 | } |
| 92 | |
| 93 | func arrayEqualCases(xs ...[]string) string { |
| 94 | var types []string |
| 95 | for _, x := range xs { |
| 96 | types = append(types, x...) |
| 97 | } |
| 98 | |
| 99 | _, _ = fmt.Fprintf(os.Stderr, "Generating array equal cases for %v\n", types) |
| 100 | |
| 101 | var out string |
| 102 | echo := func(s string, xs ...any) { |
| 103 | out += fmt.Sprintf(s, xs...) + "\n" |
| 104 | } |
| 105 | echo(`case []any:`) |
| 106 | echo(`switch y := b.(type) {`) |
| 107 | for _, a := range append(types, "any") { |
| 108 | echo(`case []%v:`, a) |
| 109 | echo(`if len(x) != len(y) { return false }`) |
| 110 | echo(`for i := range x {`) |
| 111 | echo(`if !Equal(x[i], y[i]) { return false }`) |
| 112 | echo(`}`) |
| 113 | echo("return true") |
| 114 | } |
| 115 | echo(`}`) |
| 116 | for _, a := range types { |
| 117 | echo(`case []%v:`, a) |
| 118 | echo(`switch y := b.(type) {`) |
| 119 | echo(`case []any:`) |
| 120 | echo(`return Equal(y, x)`) |
| 121 | echo(`case []%v:`, a) |
| 122 | echo(`if len(x) != len(y) { return false }`) |
| 123 | echo(`for i := range x {`) |
| 124 | echo(`if x[i] != y[i] { return false }`) |
| 125 | echo(`}`) |
| 126 | echo("return true") |
| 127 | echo(`}`) |
| 128 | } |
| 129 | return strings.TrimRight(out, "\n") |
| 130 | } |
| 131 | |
| 132 | func isFloat(t string) bool { |
| 133 | return strings.HasPrefix(t, "float") |