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
14package mmark
15
16import (
17	"testing"
18
19	"github.com/gohugoio/hugo/config"
20
21	"github.com/gohugoio/hugo/common/loggers"
22
23	qt "github.com/frankban/quicktest"
24	"github.com/gohugoio/hugo/markup/blackfriday/blackfriday_config"
25	"github.com/gohugoio/hugo/markup/converter"
26	"github.com/miekg/mmark"
27)
28
29func TestGetMmarkExtensions(t *testing.T) {
30	b := blackfriday_config.Default
31
32	// TODO: This is doing the same just with different marks...
33	type data struct {
34		testFlag int
35	}
36
37	b.Extensions = []string{"tables"}
38	b.ExtensionsMask = []string{""}
39	allExtensions := []data{
40		{mmark.EXTENSION_TABLES},
41		{mmark.EXTENSION_FENCED_CODE},
42		{mmark.EXTENSION_AUTOLINK},
43		{mmark.EXTENSION_SPACE_HEADERS},
44		{mmark.EXTENSION_CITATION},
45		{mmark.EXTENSION_TITLEBLOCK_TOML},
46		{mmark.EXTENSION_HEADER_IDS},
47		{mmark.EXTENSION_AUTO_HEADER_IDS},
48		{mmark.EXTENSION_UNIQUE_HEADER_IDS},
49		{mmark.EXTENSION_FOOTNOTES},
50		{mmark.EXTENSION_SHORT_REF},
51		{mmark.EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK},
52		{mmark.EXTENSION_INCLUDE},
53	}
54
55	actualFlags := getMmarkExtensions(b)
56	for _, e := range allExtensions {
57		if actualFlags&e.testFlag != e.testFlag {
58			t.Errorf("Flag %v was not found in the list of extensions.", e)
59		}
60	}
61}
62
63func TestConvert(t *testing.T) {
64	c := qt.New(t)
65	p, err := Provider.New(converter.ProviderConfig{Cfg: config.New(), Logger: loggers.NewErrorLogger()})
66	c.Assert(err, qt.IsNil)
67	conv, err := p.New(converter.DocumentContext{})
68	c.Assert(err, qt.IsNil)
69	b, err := conv.Convert(converter.RenderContext{Src: []byte("testContent")})
70	c.Assert(err, qt.IsNil)
71	c.Assert(string(b.Bytes()), qt.Equals, "<p>testContent</p>\n")
72}
73