diff options
author | Helder Pereira <helfper@gmail.com> | 2020-07-23 14:59:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-23 15:59:48 +0200 |
commit | 45c665d396ed368261f4a63ceee753c7f6dc5bf9 (patch) | |
tree | f480d9bafb7a53a2caeee617d689e042c140e6d6 /markup/asciidocext/convert_test.go | |
parent | a06c06a5c202de85ff47792b7468bfaeec2fea12 (diff) |
Fix Asciidoctor args
* Fix Asciidoctor args
* Fix Asciidoctor args documentation
* Update AsciiDoc documentation
Co-authored-by: Derk Muenchhausen <derk@muenchhausen.de>
Fixes #7493
Diffstat (limited to 'markup/asciidocext/convert_test.go')
-rw-r--r-- | markup/asciidocext/convert_test.go | 76 |
1 files changed, 69 insertions, 7 deletions
diff --git a/markup/asciidocext/convert_test.go b/markup/asciidocext/convert_test.go index 7fa1035c3..dc9d76c07 100644 --- a/markup/asciidocext/convert_test.go +++ b/markup/asciidocext/convert_test.go @@ -18,13 +18,12 @@ package asciidocext import ( - "github.com/gohugoio/hugo/markup/markup_config" "path/filepath" - "strings" "testing" "github.com/gohugoio/hugo/common/loggers" "github.com/gohugoio/hugo/markup/converter" + "github.com/gohugoio/hugo/markup/markup_config" "github.com/spf13/viper" qt "github.com/frankban/quicktest" @@ -51,8 +50,68 @@ func TestAsciidoctorDefaultArgs(t *testing.T) { c.Assert(ac, qt.Not(qt.IsNil)) args := ac.parseArgs(converter.DocumentContext{}) - c.Assert(args, qt.Not(qt.IsNil)) - c.Assert(strings.Join(args, " "), qt.Equals, "--no-header-footer") + expected := []string{"--no-header-footer", "--trace"} + c.Assert(args, qt.DeepEquals, expected) +} + +func TestAsciidoctorNonDefaultArgs(t *testing.T) { + c := qt.New(t) + cfg := viper.New() + mconf := markup_config.Default + mconf.AsciidocExt.Backend = "manpage" + mconf.AsciidocExt.NoHeaderOrFooter = false + mconf.AsciidocExt.SafeMode = "safe" + mconf.AsciidocExt.SectionNumbers = true + mconf.AsciidocExt.Verbose = true + mconf.AsciidocExt.Trace = false + mconf.AsciidocExt.FailureLevel = "warn" + p, err := Provider.New( + converter.ProviderConfig{ + Cfg: cfg, + MarkupConfig: mconf, + Logger: loggers.NewErrorLogger(), + }, + ) + c.Assert(err, qt.IsNil) + + conv, err := p.New(converter.DocumentContext{}) + c.Assert(err, qt.IsNil) + + ac := conv.(*asciidocConverter) + c.Assert(ac, qt.Not(qt.IsNil)) + + args := ac.parseArgs(converter.DocumentContext{}) + expected := []string{"-b", "manpage", "--section-numbers", "--verbose", "--failure-level", "warn", "--safe-mode", "safe"} + c.Assert(args, qt.DeepEquals, expected) +} + +func TestAsciidoctorDisallowedArgs(t *testing.T) { + c := qt.New(t) + cfg := viper.New() + mconf := markup_config.Default + mconf.AsciidocExt.Backend = "disallowed-backend" + mconf.AsciidocExt.Extensions = []string{"disallowed-extention"} + mconf.AsciidocExt.Attributes = map[string]string{"outdir": "disallowed-attribute"} + mconf.AsciidocExt.SafeMode = "disallowed-safemode" + mconf.AsciidocExt.FailureLevel = "disallowed-failurelevel" + p, err := Provider.New( + converter.ProviderConfig{ + Cfg: cfg, + MarkupConfig: mconf, + Logger: loggers.NewErrorLogger(), + }, + ) + c.Assert(err, qt.IsNil) + + conv, err := p.New(converter.DocumentContext{}) + c.Assert(err, qt.IsNil) + + ac := conv.(*asciidocConverter) + c.Assert(ac, qt.Not(qt.IsNil)) + + args := ac.parseArgs(converter.DocumentContext{}) + expected := []string{"--no-header-footer", "--trace"} + c.Assert(args, qt.DeepEquals, expected) } func TestAsciidoctorDiagramArgs(t *testing.T) { @@ -62,7 +121,7 @@ func TestAsciidoctorDiagramArgs(t *testing.T) { mconf.AsciidocExt.NoHeaderOrFooter = true mconf.AsciidocExt.Extensions = []string{"asciidoctor-html5s", "asciidoctor-diagram"} mconf.AsciidocExt.Backend = "html5s" - + mconf.AsciidocExt.Trace = false p, err := Provider.New( converter.ProviderConfig{ Cfg: cfg, @@ -79,8 +138,8 @@ func TestAsciidoctorDiagramArgs(t *testing.T) { c.Assert(ac, qt.Not(qt.IsNil)) args := ac.parseArgs(converter.DocumentContext{}) - c.Assert(len(args), qt.Equals, 7) - c.Assert(strings.Join(args, " "), qt.Equals, "-b html5s -r asciidoctor-html5s -r asciidoctor-diagram --no-header-footer") + expected := []string{"-b", "html5s", "-r", "asciidoctor-html5s", "-r", "asciidoctor-diagram", "--no-header-footer"} + c.Assert(args, qt.DeepEquals, expected) } func TestAsciidoctorWorkingFolderCurrent(t *testing.T) { @@ -88,6 +147,7 @@ func TestAsciidoctorWorkingFolderCurrent(t *testing.T) { cfg := viper.New() mconf := markup_config.Default mconf.AsciidocExt.WorkingFolderCurrent = true + mconf.AsciidocExt.Trace = false p, err := Provider.New( converter.ProviderConfig{ Cfg: cfg, @@ -121,6 +181,7 @@ func TestAsciidoctorWorkingFolderCurrentAndExtensions(t *testing.T) { mconf.AsciidocExt.Extensions = []string{"asciidoctor-html5s", "asciidoctor-diagram"} mconf.AsciidocExt.Backend = "html5s" mconf.AsciidocExt.WorkingFolderCurrent = true + mconf.AsciidocExt.Trace = false p, err := Provider.New( converter.ProviderConfig{ Cfg: cfg, @@ -156,6 +217,7 @@ func TestAsciidoctorAttributes(t *testing.T) { cfg := viper.New() mconf := markup_config.Default mconf.AsciidocExt.Attributes = map[string]string{"my-base-url": "https://gohugo.io/", "my-attribute-name": "my value"} + mconf.AsciidocExt.Trace = false p, err := Provider.New( converter.ProviderConfig{ Cfg: cfg, |