mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-23 23:20:49 +00:00
Fix buggy Menu.Limit()
This commit is contained in:
parent
a95426d40c
commit
7c3dceeaed
2 changed files with 18 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue