Debian Codegraph @

tpl/reflect/reflect_integration_test.go

raw
1 // Copyright 2025 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 reflect_test
15
16 import (
17 "testing"
18
19 "github.com/gohugoio/hugo/hugolib"
20 )
21
22 func TestIs(t *testing.T) {
23 t.Parallel()
24
25 files := `
26 -- hugo.toml --
27 -- assets/a.png --
28 iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==
29 -- assets/b.svg --
30 <svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">
31 <circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
32 </svg>
33 -- assets/c.txt --
34 This is a text file.
35 -- assets/d.avif --
36 AAAAHGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZgAAAOptZXRhAAAAAAAAACFoZGxyAAAAAAAAAABwaWN0AAAAAAAAAAAAAAAAAAAAAA5waXRtAAAAAAABAAAAImlsb2MAAAAAREAAAQABAAAAAAEOAAEAAAAAAAAAEgAAACNpaW5mAAAAAAABAAAAFWluZmUCAAAAAAEAAGF2MDEAAAAAamlwcnAAAABLaXBjbwAAABNjb2xybmNseAABAA0ABoAAAAAMYXYxQ4EgAgAAAAAUaXNwZQAAAAAAAAABAAAAAQAAABBwaXhpAAAAAAMICAgAAAAXaXBtYQAAAAAAAAABAAEEAYIDBAAAABptZGF0EgAKBzgABhAQ0GkyBRAAAAtA
37 -- layouts/home.html --
38 {{ $a := resources.Get "a.png" }}
39 {{ $a10 := $a.Fit "10x10" }}
40 {{ $b := resources.Get "b.svg" }}
41 {{ $c := resources.Get "c.txt" }}
42 {{ $d := resources.Get "d.avif" }}
43 PNG.ResourceType: {{ $a.ResourceType }}
44 SVG.ResourceType: {{ $b.ResourceType }}
45 Text.ResourceType: {{ $c.ResourceType }}
46 AVIF.ResourceType: {{ $d.ResourceType }}
47 IsSite: false: {{ reflect.IsSite . }}|true: {{ reflect.IsSite .Site }}|true: {{ reflect.IsSite site }}
48 IsPage: true: {{ reflect.IsPage . }}|false: {{ reflect.IsPage .Site }}|false: {{ reflect.IsPage site }}
49 IsResource: true: {{ reflect.IsResource . }}|true: {{ reflect.IsResource $a }}|true: {{ reflect.IsResource $b }}|true: {{ reflect.IsResource $c }}
50
51
52
53 `
54
55 b := hugolib.Test(t, files)
56
57 b.AssertFileContent("public/index.html", `
58 PNG.ResourceType: image
59 SVG.ResourceType: image
60 Text.ResourceType: text
61 AVIF.ResourceType: image
62 IsSite: false: false|true: true|true: true
63 IsPage: true: true|false: false|false: false
64 IsResource: true: true|true: true|true: true|true: true
65 `)
66 }