}
seqv := reflect.ValueOf(seq)
- // this is better than my first pass; ripped from text/template/exec.go indirect():
- for ; seqv.Kind() == reflect.Ptr || seqv.Kind() == reflect.Interface; seqv = seqv.Elem() {
- if seqv.IsNil() {
- return nil, errors.New("can't iterate over a nil value")
- }
- if seqv.Kind() == reflect.Interface && seqv.NumMethod() > 0 {
- break
- }
+ seqv, isNil := indirect(seqv)
+ if isNil {
+ return nil, errors.New("can't iterate over a nil value")
}
switch seqv.Kind() {
}
seqv := reflect.ValueOf(seq)
- for ; seqv.Kind() == reflect.Ptr || seqv.Kind() == reflect.Interface; seqv = seqv.Elem() {
- if seqv.IsNil() {
- return "", errors.New("can't iterate over a nil value")
- }
- if seqv.Kind() == reflect.Interface && seqv.NumMethod() > 0 {
- break
- }
+ seqv, isNil := indirect(seqv)
+ if isNil {
+ return "", errors.New("can't iterate over a nil value")
}
var str string
func Sort(seq interface{}, args ...interface{}) ([]interface{}, error) {
seqv := reflect.ValueOf(seq)
- for ; seqv.Kind() == reflect.Ptr || seqv.Kind() == reflect.Interface; seqv = seqv.Elem() {
- if seqv.IsNil() {
- return nil, errors.New("can't iterate over a nil value")
- }
- if seqv.Kind() == reflect.Interface && seqv.NumMethod() > 0 {
- break
- }
+ seqv, isNil := indirect(seqv)
+ if isNil {
+ return nil, errors.New("can't iterate over a nil value")
}
// Create a list of pairs that will be used to do the sort
result, err := doArithmetic(this.a, this.b, this.op)
if b, ok := this.expect.(bool); ok && !b {
if err == nil {
- t.Errorf("[%d] doArithmetic didn't return an expected error")
+ t.Errorf("[%d] doArithmetic didn't return an expected error", i)
}
} else {
if err != nil {
result, err := Mod(this.a, this.b)
if b, ok := this.expect.(bool); ok && !b {
if err == nil {
- t.Errorf("[%d] modulo didn't return an expected error")
+ t.Errorf("[%d] modulo didn't return an expected error", i)
}
} else {
if err != nil {
result, err := ModBool(this.a, this.b)
if this.expect == nil {
if err == nil {
- t.Errorf("[%d] modulo didn't return an expected error")
+ t.Errorf("[%d] modulo didn't return an expected error", i)
}
} else {
if err != nil {
results, err := First(this.count, this.sequence)
if b, ok := this.expect.(bool); ok && !b {
if err == nil {
- t.Errorf("[%d] First didn't return an expected error")
+ t.Errorf("[%d] First didn't return an expected error", i)
}
} else {
if err != nil {