// Copyright 2017-present 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 output
import (
"fmt"
"reflect"
"strings"
"testing"
"github.com/gohugoio/hugo/media"
qt "github.com/frankban/quicktest"
"github.com/kylelemons/godebug/diff"
)
func TestLayout(t *testing.T) {
c := qt.New(t)
noExtNoDelimMediaType := media.WithDelimiterAndSuffixes(media.TextType, "", "")
noExtMediaType := media.WithDelimiterAndSuffixes(media.TextType, ".", "")
var (
ampType = Format{
Name: "AMP",
MediaType: media.HTMLType,
BaseName: "index",
}
htmlFormat = HTMLFormat
noExtDelimFormat = Format{
Name: "NEM",
MediaType: noExtNoDelimMediaType,
BaseName: "_redirects",
}
noExt = Format{
Name: "NEX",
MediaType: noExtMediaType,
BaseName: "next",
}
)
for _, this := range []struct {
name string
layoutDescriptor LayoutDescriptor
layoutOverride string
format Format
expect []string
}{
{
"Home",
LayoutDescriptor{Kind: "home"},
"", ampType,
[]string{
"index.amp.html",
"home.amp.html",
"list.amp.html",
"index.html",
"home.html",
"list.html",
"_default/index.amp.html",
"_default/home.amp.html",
"_default/list.amp.html",
"_default/index.html",
"_default/home.html",
"_default/list.html",
},
},
{
"Home baseof",
LayoutDescriptor{Kind: "home", Baseof: true},
"", ampType,
[]string{
"index-baseof.amp.html",
"home-baseof.amp.html",
"list-baseof.amp.html",
"baseof.amp.html",
"index-baseof.html",
"home-baseof.html",
"list-baseof.html",
"baseof.html",
"_default/index-baseof.amp.html",
"_default/home-baseof.amp.html",
"_default/list-baseof.amp.html",
"_default/baseof.amp.html",
"_default/index-baseof.html",
"_default/home-baseof.html",
"_default/list-baseof.html",
"_default/baseof.html",
},
},
{
"Home, HTML",
LayoutDescriptor{Kind: "home"},
"", htmlFormat,