github.com/anakojm/hugo-katex@v0.0.0-20231023141351-42d6f5de9c0b/markup/markup_config/config_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  
    14  package markup_config
    15  
    16  import (
    17  	"testing"
    18  
    19  	"github.com/gohugoio/hugo/config"
    20  
    21  	qt "github.com/frankban/quicktest"
    22  )
    23  
    24  func TestConfig(t *testing.T) {
    25  	c := qt.New(t)
    26  
    27  	c.Run("Decode", func(c *qt.C) {
    28  		c.Parallel()
    29  		v := config.New()
    30  
    31  		v.Set("markup", map[string]any{
    32  			"goldmark": map[string]any{
    33  				"renderer": map[string]any{
    34  					"unsafe": true,
    35  				},
    36  			},
    37  			"asciidocext": map[string]any{
    38  				"workingFolderCurrent": true,
    39  				"safeMode":             "save",
    40  				"extensions":           []string{"asciidoctor-html5s"},
    41  			},
    42  		})
    43  
    44  		conf, err := Decode(v)
    45  
    46  		c.Assert(err, qt.IsNil)
    47  		c.Assert(conf.Goldmark.Renderer.Unsafe, qt.Equals, true)
    48  		c.Assert(conf.Goldmark.Parser.Attribute.Title, qt.Equals, true)
    49  		c.Assert(conf.Goldmark.Parser.Attribute.Block, qt.Equals, false)
    50  
    51  		c.Assert(conf.AsciidocExt.WorkingFolderCurrent, qt.Equals, true)
    52  		c.Assert(conf.AsciidocExt.Extensions[0], qt.Equals, "asciidoctor-html5s")
    53  	})
    54  
    55  	c.Run("Decode legacy typographer", func(c *qt.C) {
    56  		c.Parallel()
    57  		v := config.New()
    58  
    59  		// typographer was changed from a bool to a struct in 0.112.0.
    60  		v.Set("markup", map[string]any{
    61  			"goldmark": map[string]any{
    62  				"extensions": map[string]any{
    63  					"typographer": false,
    64  				},
    65  			},
    66  		})
    67  
    68  		conf, err := Decode(v)
    69  
    70  		c.Assert(err, qt.IsNil)
    71  		c.Assert(conf.Goldmark.Extensions.Typographer.Disable, qt.Equals, true)
    72  
    73  		v.Set("markup", map[string]any{
    74  			"goldmark": map[string]any{
    75  				"extensions": map[string]any{
    76  					"typographer": true,
    77  				},
    78  			},
    79  		})
    80  
    81  		conf, err = Decode(v)
    82  
    83  		c.Assert(err, qt.IsNil)
    84  		c.Assert(conf.Goldmark.Extensions.Typographer.Disable, qt.Equals, false)
    85  		c.Assert(conf.Goldmark.Extensions.Typographer.Ellipsis, qt.Equals, "…")
    86  
    87  	})
    88  
    89  }