| 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 |
// We changed the typographer extension config from a bool to a struct in 0.112.0. |
| 56 |
// We changed the footnote extension config from a bool to a struct in 0.151.0. |
| 57 |
c.Run("Decode legacy Goldmark configs", func(c *qt.C) { |
| 58 |
c.Parallel() |
| 59 |
v := config.New() |
| 60 |
|
| 61 |
v.Set("markup", map[string]any{ |
| 62 |
"goldmark": map[string]any{ |
| 63 |
"extensions": map[string]any{ |
| 64 |
"footnote": false, |
| 65 |
"typographer": false, |
| 66 |
}, |
| 67 |
}, |
| 68 |
}) |
| 69 |
|
| 70 |
conf, err := Decode(v) |
| 71 |
|
| 72 |
c.Assert(err, qt.IsNil) |
| 73 |
c.Assert(conf.Goldmark.Extensions.Footnote.Enable, qt.Equals, false) |
| 74 |
c.Assert(conf.Goldmark.Extensions.Typographer.Disable, qt.Equals, true) |
| 75 |
|
| 76 |
v.Set("markup", map[string]any{ |
| 77 |
"goldmark": map[string]any{ |
| 78 |
"extensions": map[string]any{ |
| 79 |
"footnote": true, |
| 80 |
"typographer": true, |
| 81 |
}, |
| 82 |
}, |
| 83 |
}) |
| 84 |
|
| 85 |
conf, err = Decode(v) |
| 86 |
|
| 87 |
c.Assert(err, qt.IsNil) |
| 88 |
c.Assert(conf.Goldmark.Extensions.Footnote.Enable, qt.Equals, true) |
| 89 |
c.Assert(conf.Goldmark.Extensions.Typographer.Disable, qt.Equals, false) |
| 90 |
c.Assert(conf.Goldmark.Extensions.Typographer.Ellipsis, qt.Equals, "…") |
| 91 |
}) |
| 92 |
} |