Fix buggy Menu.Limit()

This commit is contained in:
Bjørn Erik Pedersen 2016-02-06 22:53:59 +01:00
parent a95426d40c
commit 7c3dceeaed
2 changed files with 18 additions and 1 deletions

View file

@ -157,7 +157,7 @@ func (m Menu) Sort() {
}
func (m Menu) Limit(n int) Menu {
if len(m) < n {
if len(m) > n {
return m[0:n]
}
return m

View file

@ -480,6 +480,23 @@ func TestTaxonomyNodeMenu(t *testing.T) {
}
}
func TestMenuLimit(t *testing.T) {
viper.Reset()
defer viper.Reset()
s := setupMenuTests(t, MENU_PAGE_SOURCES)
m := *s.Menus["main"]
// main menu has 4 entries
firstTwo := m.Limit(2)
assert.Equal(t, 2, len(firstTwo))
for i := 0; i < 2; i++ {
assert.Equal(t, m[i], firstTwo[i])
}
assert.Equal(t, m, m.Limit(4))
assert.Equal(t, m, m.Limit(5))
}
func TestHomeNodeMenu(t *testing.T) {
viper.Reset()
defer viper.Reset()