MCPcopy Index your code
hub / github.com/expr-lang/expr / arrayEqualCases

Function arrayEqualCases

vm/runtime/helpers/main.go:93–130  ·  view source on GitHub ↗
(xs ...[]string)

Source from the content-addressed store, hash-verified

91}
92
93func 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
132func isFloat(t string) bool {
133 return strings.HasPrefix(t, "float")

Callers 1

mainFunction · 0.85

Calls 2

FprintfMethod · 0.80
SprintfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…