github.com/anakojm/hugo-katex@v0.0.0-20231023141351-42d6f5de9c0b/source/fileInfo_test.go (about) 1 // Copyright 2017-present 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 "path/filepath" 18 "strings" 19 "testing" 20 21 qt "github.com/frankban/quicktest" 22 "github.com/gohugoio/hugo/source" 23 ) 24 25 func TestFileInfo(t *testing.T) { 26 c := qt.New(t) 27 28 s := newTestSourceSpec() 29 30 for _, this := range []struct { 31 base string 32 filename string 33 assert func(f *source.FileInfo) 34 }{ 35 {filepath.FromSlash("/a/"), filepath.FromSlash("/a/b/page.md"), func(f *source.FileInfo) { 36 c.Assert(f.Filename(), qt.Equals, filepath.FromSlash("/a/b/page.md")) 37 c.Assert(f.Dir(), qt.Equals, filepath.FromSlash("b/")) 38 c.Assert(f.Path(), qt.Equals, filepath.FromSlash("b/page.md")) 39 c.Assert(f.Section(), qt.Equals, "b") 40 c.Assert(f.TranslationBaseName(), qt.Equals, filepath.FromSlash("page")) 41 c.Assert(f.BaseFileName(), qt.Equals, filepath.FromSlash("page")) 42 }}, 43 {filepath.FromSlash("/a/"), filepath.FromSlash("/a/b/c/d/page.md"), func(f *source.FileInfo) { 44 c.Assert(f.Section(), qt.Equals, "b") 45 }}, 46 {filepath.FromSlash("/a/"), filepath.FromSlash("/a/b/page.en.MD"), func(f *source.FileInfo) { 47 c.Assert(f.Section(), qt.Equals, "b") 48 c.Assert(f.Path(), qt.Equals, filepath.FromSlash("b/page.en.MD")) 49 c.Assert(f.TranslationBaseName(), qt.Equals, filepath.FromSlash("page")) 50 c.Assert(f.BaseFileName(), qt.Equals, filepath.FromSlash("page.en")) 51 }}, 52 } { 53 path := strings.TrimPrefix(this.filename, this.base) 54 f, err := s.NewFileInfoFrom(path, this.filename) 55 c.Assert(err, qt.IsNil) 56 this.assert(f) 57 } 58 }