go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/projects/blogctl/pkg/engine/template_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2023 - Present. Will Charczuk. All rights reserved.
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository.
     5  
     6  */
     7  
     8  package engine
     9  
    10  import (
    11  	"testing"
    12  
    13  	. "go.charczuk.com/sdk/assert"
    14  
    15  	"go.charczuk.com/projects/blogctl/pkg/model"
    16  )
    17  
    18  func TestPartitionPosts(t *testing.T) {
    19  	posts := []*model.Post{
    20  		{Meta: model.Meta{Title: "one"}},
    21  		{Meta: model.Meta{Title: "two"}},
    22  		{Meta: model.Meta{Title: "three"}},
    23  		{Meta: model.Meta{Title: "four"}},
    24  		{Meta: model.Meta{Title: "five"}},
    25  		{Meta: model.Meta{Title: "six"}},
    26  		{Meta: model.Meta{Title: "seven"}},
    27  	}
    28  
    29  	partition0, err := partition(0, 2, posts)
    30  	ItsNil(t, err)
    31  	partition1, err := partition(1, 2, posts)
    32  	ItsNil(t, err)
    33  
    34  	ItsLen(t, partition0, 4)
    35  	ItsLen(t, partition1, 3)
    36  
    37  	ItsEqual(t, "one", partition0[0].Meta.Title)
    38  	ItsEqual(t, "three", partition0[1].Meta.Title)
    39  	ItsEqual(t, "five", partition0[2].Meta.Title)
    40  	ItsEqual(t, "seven", partition0[3].Meta.Title)
    41  
    42  	ItsEqual(t, "two", partition1[0].Meta.Title)
    43  	ItsEqual(t, "four", partition1[1].Meta.Title)
    44  	ItsEqual(t, "six", partition1[2].Meta.Title)
    45  }