github.com/gohugoio/hugo@v0.88.1/tpl/tplimpl/template_info_test.go (about) 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 package tplimpl 14 15 import ( 16 "testing" 17 18 qt "github.com/frankban/quicktest" 19 "github.com/gohugoio/hugo/deps" 20 "github.com/gohugoio/hugo/hugofs" 21 "github.com/gohugoio/hugo/tpl" 22 ) 23 24 func TestTemplateInfoShortcode(t *testing.T) { 25 c := qt.New(t) 26 d := newD(c) 27 defer d.Close() 28 h := d.Tmpl().(*templateExec) 29 30 c.Assert(h.AddTemplate("shortcodes/mytemplate.html", ` 31 {{ .Inner }} 32 `), qt.IsNil) 33 34 c.Assert(h.postTransform(), qt.IsNil) 35 36 tt, found, _ := d.Tmpl().LookupVariant("mytemplate", tpl.TemplateVariants{}) 37 38 c.Assert(found, qt.Equals, true) 39 tti, ok := tt.(tpl.Info) 40 c.Assert(ok, qt.Equals, true) 41 c.Assert(tti.ParseInfo().IsInner, qt.Equals, true) 42 } 43 44 // TODO(bep) move and use in other places 45 func newD(c *qt.C) *deps.Deps { 46 v := newTestConfig() 47 fs := hugofs.NewMem(v) 48 49 depsCfg := newDepsConfig(v) 50 depsCfg.Fs = fs 51 d, err := deps.New(depsCfg) 52 c.Assert(err, qt.IsNil) 53 54 provider := DefaultTemplateProvider 55 provider.Update(d) 56 57 return d 58 }