config_test.go (1795B)
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 highlight provides code highlighting.
15 package highlight
16
17 import (
18 "testing"
19
20 qt "github.com/frankban/quicktest"
21 "github.com/gohugoio/hugo/config"
22 )
23
24 func TestConfig(t *testing.T) {
25 c := qt.New(t)
26
27 c.Run("applyLegacyConfig", func(c *qt.C) {
28 v := config.New()
29 v.Set("pygmentsStyle", "hugo")
30 v.Set("pygmentsUseClasses", false)
31 v.Set("pygmentsCodeFences", false)
32 v.Set("pygmentsOptions", "linenos=inline")
33
34 cfg := DefaultConfig
35 err := ApplyLegacyConfig(v, &cfg)
36 c.Assert(err, qt.IsNil)
37 c.Assert(cfg.Style, qt.Equals, "hugo")
38 c.Assert(cfg.NoClasses, qt.Equals, true)
39 c.Assert(cfg.CodeFences, qt.Equals, false)
40 c.Assert(cfg.LineNos, qt.Equals, true)
41 c.Assert(cfg.LineNumbersInTable, qt.Equals, false)
42 })
43
44 c.Run("parseOptions", func(c *qt.C) {
45 cfg := DefaultConfig
46 opts := "noclasses=true,linenos=inline,linenostart=32,hl_lines=3-8 10-20"
47 err := applyOptionsFromString(opts, &cfg)
48
49 c.Assert(err, qt.IsNil)
50 c.Assert(cfg.NoClasses, qt.Equals, true)
51 c.Assert(cfg.LineNos, qt.Equals, true)
52 c.Assert(cfg.LineNumbersInTable, qt.Equals, false)
53 c.Assert(cfg.LineNoStart, qt.Equals, 32)
54 c.Assert(cfg.Hl_Lines, qt.Equals, "3-8 10-20")
55 })
56 }