github.com/olliephillips/hugo@v0.42.2/helpers/pathspec_test.go (about)

     1  // Copyright 2018 The Hugo Authors. All rights reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  // http://www.apache.org/licenses/LICENSE-2.0
     7  //
     8  // Unless required by applicable law or agreed to in writing, software
     9  // distributed under the License is distributed on an "AS IS" BASIS,
    10  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package helpers
    15  
    16  import (
    17  	"testing"
    18  
    19  	"github.com/gohugoio/hugo/hugofs"
    20  
    21  	"github.com/gohugoio/hugo/langs"
    22  	"github.com/stretchr/testify/require"
    23  )
    24  
    25  func TestNewPathSpecFromConfig(t *testing.T) {
    26  	v := newTestCfg()
    27  	l := langs.NewLanguage("no", v)
    28  	v.Set("disablePathToLower", true)
    29  	v.Set("removePathAccents", true)
    30  	v.Set("uglyURLs", true)
    31  	v.Set("canonifyURLs", true)
    32  	v.Set("paginatePath", "side")
    33  	v.Set("baseURL", "http://base.com")
    34  	v.Set("themesDir", "thethemes")
    35  	v.Set("layoutDir", "thelayouts")
    36  	v.Set("workingDir", "thework")
    37  	v.Set("staticDir", "thestatic")
    38  	v.Set("theme", "thetheme")
    39  
    40  	p, err := NewPathSpec(hugofs.NewMem(v), l)
    41  
    42  	require.NoError(t, err)
    43  	require.True(t, p.CanonifyURLs)
    44  	require.True(t, p.DisablePathToLower)
    45  	require.True(t, p.RemovePathAccents)
    46  	require.True(t, p.UglyURLs)
    47  	require.Equal(t, "no", p.Language.Lang)
    48  	require.Equal(t, "side", p.PaginatePath)
    49  
    50  	require.Equal(t, "http://base.com", p.BaseURL.String())
    51  	require.Equal(t, "thethemes", p.ThemesDir)
    52  	require.Equal(t, "thework", p.WorkingDir)
    53  	require.Equal(t, []string{"thetheme"}, p.Themes())
    54  }