b.AssertFileContent("public/index.html", "Sorted: [map[weight:1] map[weight:2] map[weight:3] map[weight:4]]|")
}
+
+func TestYAMLIntegerWhere(t *testing.T) {
+ files := `
+-- assets/mydata.yaml --
+a:
+ weight: 1
+x:
+ weight: 2
+c:
+ weight: 3
+t:
+ weight: 4
+-- assets/myslice.yaml --
+- weight: 1
+ name: one
+- weight: 2
+ name: two
+- weight: 3
+ name: three
+- weight: 4
+ name: four
+
+-- layouts/all.html --
+{{ $mydata1 := resources.Get "mydata.yaml" | transform.Unmarshal }}
+{{ $myslice := resources.Get "myslice.yaml" | transform.Unmarshal }}
+{{ $filtered := where $myslice "weight" "ge" $mydata1.x.weight }}
+mydata1: {{ $mydata1 }}|
+Filtered: {{ $filtered }}|
+
+`
+
+ b := hugolib.Test(t, files)
+
+ b.AssertFileContent("public/index.html", "[map[name:two weight:2] map[name:three weight:3] map[name:four weight:4]]|")
+}
ivp = &iv
imv := mv.Int()
imvp = &imv
+ case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
+ iv := int64(v.Uint())
+ ivp = &iv
+ imv := int64(mv.Uint())
+ imvp = &imv
case reflect.String:
sv := v.String()
svp = &sv
return v.Float(), nil
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return v.Convert(reflect.TypeOf(float64(0))).Float(), nil
+ case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
+ return v.Convert(reflect.TypeOf(float64(0))).Float(), nil
case reflect.Interface:
return toFloat(v.Elem())
}
"testing"
"time"
+ qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/common/maps"
)
}
}
+func TestToFloat(t *testing.T) {
+ t.Parallel()
+
+ c := qt.New(t)
+
+ to := func(v any) float64 {
+ f, err := toFloat(reflect.ValueOf(v))
+ c.Assert(err, qt.IsNil)
+ return f
+ }
+
+ c.Assert(to(uint64(32)), qt.Equals, 32.0)
+ c.Assert(to(int64(32)), qt.Equals, 32.0)
+ c.Assert(to(uint32(32)), qt.Equals, 32.0)
+ c.Assert(to(int32(32)), qt.Equals, 32.0)
+
+ c.Assert(to(uint16(32)), qt.Equals, 32.0)
+ c.Assert(to(int16(32)), qt.Equals, 32.0)
+
+ c.Assert(to(uint8(32)), qt.Equals, 32.0)
+ c.Assert(to(int8(32)), qt.Equals, 32.0)
+
+ c.Assert(to(uint(32)), qt.Equals, 32.0)
+ c.Assert(to(int(32)), qt.Equals, 32.0)
+}
+
func BenchmarkWhereOps(b *testing.B) {
ns := newNs()
var seq []map[string]string