hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

content_directory_test.go (2018B)

    1 // Copyright 2015 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 source
   15 
   16 import (
   17 	"path/filepath"
   18 	"testing"
   19 
   20 	"github.com/gohugoio/hugo/helpers"
   21 
   22 	qt "github.com/frankban/quicktest"
   23 	"github.com/gohugoio/hugo/hugofs"
   24 )
   25 
   26 func TestIgnoreDotFilesAndDirectories(t *testing.T) {
   27 	c := qt.New(t)
   28 
   29 	tests := []struct {
   30 		path                string
   31 		ignore              bool
   32 		ignoreFilesRegexpes any
   33 	}{
   34 		{".foobar/", true, nil},
   35 		{"foobar/.barfoo/", true, nil},
   36 		{"barfoo.md", false, nil},
   37 		{"foobar/barfoo.md", false, nil},
   38 		{"foobar/.barfoo.md", true, nil},
   39 		{".barfoo.md", true, nil},
   40 		{".md", true, nil},
   41 		{"foobar/barfoo.md~", true, nil},
   42 		{".foobar/barfoo.md~", true, nil},
   43 		{"foobar~/barfoo.md", false, nil},
   44 		{"foobar/bar~foo.md", false, nil},
   45 		{"foobar/foo.md", true, []string{"\\.md$", "\\.boo$"}},
   46 		{"foobar/foo.html", false, []string{"\\.md$", "\\.boo$"}},
   47 		{"foobar/foo.md", true, []string{"foo.md$"}},
   48 		{"foobar/foo.md", true, []string{"*", "\\.md$", "\\.boo$"}},
   49 		{"foobar/.#content.md", true, []string{"/\\.#"}},
   50 		{".#foobar.md", true, []string{"^\\.#"}},
   51 	}
   52 
   53 	for i, test := range tests {
   54 		v := newTestConfig()
   55 		v.Set("ignoreFiles", test.ignoreFilesRegexpes)
   56 		fs := hugofs.NewMem(v)
   57 		ps, err := helpers.NewPathSpec(fs, v, nil)
   58 		c.Assert(err, qt.IsNil)
   59 
   60 		s := NewSourceSpec(ps, nil, fs.Source)
   61 
   62 		if ignored := s.IgnoreFile(filepath.FromSlash(test.path)); test.ignore != ignored {
   63 			t.Errorf("[%d] File not ignored", i)
   64 		}
   65 	}
   66 }