ginger/expr/util.go

41 lines
633 B
Go
Raw Normal View History

2016-08-02 00:08:51 +00:00
package expr
import (
"encoding/hex"
"fmt"
2016-08-02 00:08:51 +00:00
"math/rand"
"strings"
2016-08-02 00:08:51 +00:00
)
func randStr() string {
b := make([]byte, 16)
if _, err := rand.Read(b); err != nil {
panic(err)
}
return hex.EncodeToString(b)
}
func exprsJoin(ee []Expr) string {
strs := make([]string, len(ee))
for i := range ee {
strs[i] = fmt.Sprint(ee[i].Actual)
}
return strings.Join(strs, ", ")
}
func exprsEqual(ee1, ee2 []Expr) bool {
if len(ee1) != len(ee2) {
return false
}
for i := range ee1 {
if !ee1[i].equal(ee2[i]) {
return false
}
}
return true
}
func panicf(msg string, args ...interface{}) {
panic(fmt.Sprintf(msg, args...))
}