filter_fs_test.go (1459B)
1 // Copyright 2019 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 hugofs 15 16 import ( 17 "path/filepath" 18 "testing" 19 20 qt "github.com/frankban/quicktest" 21 ) 22 23 func TestLangInfoFrom(t *testing.T) { 24 langs := map[string]int{ 25 "sv": 10, 26 "en": 20, 27 } 28 29 c := qt.New(t) 30 31 tests := []struct { 32 input string 33 expected []string 34 }{ 35 {"page.sv.md", []string{"sv", "page", "page.md"}}, 36 {"page.en.md", []string{"en", "page", "page.md"}}, 37 {"page.no.md", []string{"", "page.no", "page.no.md"}}, 38 {filepath.FromSlash("tc-lib-color/class-Com.Tecnick.Color.Css"), []string{"", "class-Com.Tecnick.Color", "class-Com.Tecnick.Color.Css"}}, 39 {filepath.FromSlash("class-Com.Tecnick.Color.sv.Css"), []string{"sv", "class-Com.Tecnick.Color", "class-Com.Tecnick.Color.Css"}}, 40 } 41 42 for _, test := range tests { 43 v1, v2, v3 := langInfoFrom(langs, test.input) 44 c.Assert([]string{v1, v2, v3}, qt.DeepEquals, test.expected) 45 } 46 }