github.com/kovansky/hugo@v0.92.3-0.20220224232819-63076e4ff19f/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  	"path/filepath"
    18  	"testing"
    19  
    20  	qt "github.com/frankban/quicktest"
    21  	"github.com/gohugoio/hugo/hugofs"
    22  
    23  	"github.com/gohugoio/hugo/langs"
    24  )
    25  
    26  func TestNewPathSpecFromConfig(t *testing.T) {
    27  	c := qt.New(t)
    28  	v := newTestCfg()
    29  	l := langs.NewLanguage("no", v)
    30  	v.Set("disablePathToLower", true)
    31  	v.Set("removePathAccents", true)
    32  	v.Set("uglyURLs", true)
    33  	v.Set("canonifyURLs", true)
    34  	v.Set("paginatePath", "side")
    35  	v.Set("baseURL", "http://base.com")
    36  	v.Set("themesDir", "thethemes")
    37  	v.Set("layoutDir", "thelayouts")
    38  	v.Set("workingDir", "thework")
    39  	v.Set("staticDir", "thestatic")
    40  	v.Set("theme", "thetheme")
    41  	langs.LoadLanguageSettings(v, nil)
    42  
    43  	fs := hugofs.NewMem(v)
    44  	fs.Source.MkdirAll(filepath.FromSlash("thework/thethemes/thetheme"), 0777)
    45  
    46  	p, err := NewPathSpec(fs, l, nil)
    47  
    48  	c.Assert(err, qt.IsNil)
    49  	c.Assert(p.CanonifyURLs, qt.Equals, true)
    50  	c.Assert(p.DisablePathToLower, qt.Equals, true)
    51  	c.Assert(p.RemovePathAccents, qt.Equals, true)
    52  	c.Assert(p.UglyURLs, qt.Equals, true)
    53  	c.Assert(p.Language.Lang, qt.Equals, "no")
    54  	c.Assert(p.PaginatePath, qt.Equals, "side")
    55  
    56  	c.Assert(p.BaseURL.String(), qt.Equals, "http://base.com")
    57  	c.Assert(p.ThemesDir, qt.Equals, "thethemes")
    58  	c.Assert(p.WorkingDir, qt.Equals, "thework")
    59  }