resource_cache_test.go (1695B)
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 resources 15 16 import ( 17 "path/filepath" 18 "testing" 19 20 qt "github.com/frankban/quicktest" 21 ) 22 23 func TestResourceKeyPartitions(t *testing.T) { 24 c := qt.New(t) 25 26 for _, test := range []struct { 27 input string 28 expected []string 29 }{ 30 {"a.js", []string{"js"}}, 31 {"a.scss", []string{"sass", "scss"}}, 32 {"a.sass", []string{"sass", "scss"}}, 33 {"d/a.js", []string{"d", "js"}}, 34 {"js/a.js", []string{"js"}}, 35 {"D/a.JS", []string{"d", "js"}}, 36 {"d/a", []string{"d"}}, 37 {filepath.FromSlash("/d/a.js"), []string{"d", "js"}}, 38 {filepath.FromSlash("/d/e/a.js"), []string{"d", "js"}}, 39 } { 40 c.Assert(ResourceKeyPartitions(test.input), qt.DeepEquals, test.expected, qt.Commentf(test.input)) 41 } 42 } 43 44 func TestResourceKeyContainsAny(t *testing.T) { 45 c := qt.New(t) 46 47 for _, test := range []struct { 48 key string 49 filename string 50 expected bool 51 }{ 52 {"styles/css", "asdf.css", true}, 53 {"styles/css", "styles/asdf.scss", true}, 54 {"js/foo.bar", "asdf.css", false}, 55 } { 56 c.Assert(ResourceKeyContainsAny(test.key, ResourceKeyPartitions(test.filename)), qt.Equals, test.expected) 57 } 58 }