Debian Codegraph @

minifiers/config_test.go

raw
1 // Copyright 2024 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 minifiers_test
15
16 import (
17 "testing"
18
19 qt "github.com/frankban/quicktest"
20 "github.com/gohugoio/hugo/config"
21 "github.com/gohugoio/hugo/config/testconfig"
22 )
23
24 func TestConfig(t *testing.T) {
25 c := qt.New(t)
26 v := config.New()
27
28 v.Set("minify", map[string]any{
29 "disablexml": true,
30 "tdewolff": map[string]any{
31 "html": map[string]any{
32 "keepwhitespace": false,
33 },
34 },
35 })
36
37 conf := testconfig.GetTestConfigs(nil, v).Base.Minify
38
39 c.Assert(conf.MinifyOutput, qt.Equals, false)
40
41 // explicitly set value
42 c.Assert(conf.Tdewolff.HTML.KeepWhitespace, qt.Equals, false)
43 // default value
44 c.Assert(conf.Tdewolff.HTML.KeepEndTags, qt.Equals, true)
45 c.Assert(conf.Tdewolff.CSS.Version, qt.Equals, 0)
46
47 // `enable` flags
48 c.Assert(conf.DisableHTML, qt.Equals, false)
49 c.Assert(conf.DisableXML, qt.Equals, true)
50 }
51
52 func TestConfigDeprecations(t *testing.T) {
53 c := qt.New(t)
54
55 // Test default values of deprecated root keys.
56 v := config.New()
57 v.Set("minify", false)
58 conf := testconfig.GetTestConfigs(nil, v).Base.Minify
59 c.Assert(conf.MinifyOutput, qt.Equals, false)
60
61 v = config.New()
62 v.Set("minifyoutput", false)
63 conf = testconfig.GetTestConfigs(nil, v).Base.Minify
64 c.Assert(conf.MinifyOutput, qt.Equals, false)
65
66 // Test non-default values of deprecated root keys.
67 v = config.New()
68 v.Set("minify", true)
69 conf = testconfig.GetTestConfigs(nil, v).Base.Minify
70 c.Assert(conf.MinifyOutput, qt.Equals, true)
71
72 v = config.New()
73 v.Set("minifyoutput", true)
74 conf = testconfig.GetTestConfigs(nil, v).Base.Minify
75 c.Assert(conf.MinifyOutput, qt.Equals, true)
76 }
77
78 func TestConfigUpstreamDeprecations(t *testing.T) {
79 c := qt.New(t)
80
81 // Test default values of deprecated keys.
82 v := config.New()
83 v.Set("minify", map[string]any{
84 "tdewolff": map[string]any{
85 "css": map[string]any{
86 "decimals": 0,
87 "keepcss2": true,
88 },
89 "html": map[string]any{
90 "keepconditionalcomments": true,
91 },
92 "svg": map[string]any{
93 "decimals": 0,
94 },
95 },
96 })
97
98 conf := testconfig.GetTestConfigs(nil, v).Base.Minify
99
100 c.Assert(conf.Tdewolff.CSS.Precision, qt.Equals, 0)
101 c.Assert(conf.Tdewolff.CSS.Version, qt.Equals, 2)
102 c.Assert(conf.Tdewolff.HTML.KeepSpecialComments, qt.Equals, true)
103 c.Assert(conf.Tdewolff.SVG.Precision, qt.Equals, 0)
104
105 // Test non-default values of deprecated keys.
106 v = config.New()
107 v.Set("minify", map[string]any{
108 "tdewolff": map[string]any{
109 "css": map[string]any{
110 "decimals": 6,
111 "keepcss2": false,
112 },
113 "html": map[string]any{
114 "keepconditionalcomments": false,
115 },
116 "svg": map[string]any{
117 "decimals": 7,
118 },
119 },
120 })
121
122 conf = testconfig.GetTestConfigs(nil, v).Base.Minify
123
124 c.Assert(conf.Tdewolff.CSS.Precision, qt.Equals, 6)
125 c.Assert(conf.Tdewolff.CSS.Version, qt.Equals, 0)
126 c.Assert(conf.Tdewolff.HTML.KeepSpecialComments, qt.Equals, false)
127 c.Assert(conf.Tdewolff.SVG.Precision, qt.Equals, 7)
128 }