2019-01-02 06:33:26 -05:00
|
|
|
// Copyright 2019 The Hugo Authors. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package page
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"text/template"
|
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
qt "github.com/frankban/quicktest"
|
2019-01-02 06:33:26 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestPageData(t *testing.T) {
|
2019-08-10 15:05:17 -04:00
|
|
|
c := qt.New(t)
|
2019-01-02 06:33:26 -05:00
|
|
|
|
|
|
|
data := make(Data)
|
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(data.Pages(), qt.IsNil)
|
2019-01-02 06:33:26 -05:00
|
|
|
|
|
|
|
pages := Pages{
|
|
|
|
&testPage{title: "a1"},
|
|
|
|
&testPage{title: "a2"},
|
|
|
|
}
|
|
|
|
|
|
|
|
data["pages"] = pages
|
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(data.Pages(), eq, pages)
|
2019-01-02 06:33:26 -05:00
|
|
|
|
|
|
|
data["pages"] = func() Pages {
|
|
|
|
return pages
|
|
|
|
}
|
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(data.Pages(), eq, pages)
|
2019-01-02 06:33:26 -05:00
|
|
|
|
|
|
|
templ, err := template.New("").Parse(`Pages: {{ .Pages }}`)
|
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(err, qt.IsNil)
|
2019-01-02 06:33:26 -05:00
|
|
|
|
|
|
|
var buff bytes.Buffer
|
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(templ.Execute(&buff, data), qt.IsNil)
|
2019-01-02 06:33:26 -05:00
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(buff.String(), qt.Contains, "Pages(2)")
|
2019-01-02 06:33:26 -05:00
|
|
|
|
|
|
|
}
|