URI: 
       content_directory_test.go - hugo - [fork] hugo port for 9front
  HTML git clone https://git.drkhsh.at/hugo.git
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
   DIR README
   DIR LICENSE
       ---
       content_directory_test.go (2404B)
       ---
            1 // Copyright 2024 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_test
           15 
           16 import (
           17         "fmt"
           18         "path/filepath"
           19         "testing"
           20 
           21         "github.com/gohugoio/hugo/config"
           22         "github.com/gohugoio/hugo/config/testconfig"
           23         "github.com/gohugoio/hugo/helpers"
           24         "github.com/gohugoio/hugo/source"
           25         "github.com/spf13/afero"
           26 
           27         qt "github.com/frankban/quicktest"
           28         "github.com/gohugoio/hugo/hugofs"
           29 )
           30 
           31 func TestIgnoreDotFilesAndDirectories(t *testing.T) {
           32         c := qt.New(t)
           33 
           34         tests := []struct {
           35                 path                string
           36                 ignore              bool
           37                 ignoreFilesRegexpes any
           38         }{
           39                 {".foobar/", true, nil},
           40                 {"foobar/.barfoo/", true, nil},
           41                 {"barfoo.md", false, nil},
           42                 {"foobar/barfoo.md", false, nil},
           43                 {"foobar/.barfoo.md", true, nil},
           44                 {".barfoo.md", true, nil},
           45                 {".md", true, nil},
           46                 {"foobar/barfoo.md~", true, nil},
           47                 {".foobar/barfoo.md~", true, nil},
           48                 {"foobar~/barfoo.md", false, nil},
           49                 {"foobar/bar~foo.md", false, nil},
           50                 {"foobar/foo.md", true, []string{"\\.md$", "\\.boo$"}},
           51                 {"foobar/foo.html", false, []string{"\\.md$", "\\.boo$"}},
           52                 {"foobar/foo.md", true, []string{"foo.md$"}},
           53                 {"foobar/foo.md", true, []string{".*", "\\.md$", "\\.boo$"}},
           54                 {"foobar/.#content.md", true, []string{"/\\.#"}},
           55                 {".#foobar.md", true, []string{"^\\.#"}},
           56         }
           57 
           58         for i, test := range tests {
           59                 test := test
           60                 c.Run(fmt.Sprintf("[%d] %s", i, test.path), func(c *qt.C) {
           61                         c.Parallel()
           62                         v := config.New()
           63                         v.Set("ignoreFiles", test.ignoreFilesRegexpes)
           64                         v.Set("publishDir", "public")
           65                         afs := afero.NewMemMapFs()
           66                         conf := testconfig.GetTestConfig(afs, v)
           67                         fs := hugofs.NewFromOld(afs, v)
           68                         ps, err := helpers.NewPathSpec(fs, conf, nil)
           69                         c.Assert(err, qt.IsNil)
           70 
           71                         s := source.NewSourceSpec(ps, nil, fs.Source)
           72 
           73                         if ignored := s.IgnoreFile(filepath.FromSlash(test.path)); test.ignore != ignored {
           74                                 t.Errorf("[%d] File not ignored", i)
           75                         }
           76                 })
           77 
           78         }
           79 }