Files
terraform-docs/template/anchor_test.go
Khosrow Moossavi bb109711a1 Deprecate Settings and Options in favor of Config
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-09-28 15:47:27 -04:00

114 lines
2.7 KiB
Go

/*
Copyright 2021 The terraform-docs Authors.
Licensed under the MIT license (the "License"); you may not
use this file except in compliance with the License.
You may obtain a copy of the License at the LICENSE file in
the root directory of this source tree.
*/
package template
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestAnchorMarkdown(t *testing.T) {
tests := []struct {
typeSection string
name string
anchor bool
escape bool
expected string
}{
{
typeSection: "module",
name: "banana_anchor_escape",
anchor: true,
escape: true,
expected: "<a name=\"module_banana_anchor_escape\"></a> [banana\\_anchor\\_escape](#module\\_banana\\_anchor\\_escape)",
},
{
typeSection: "module",
name: "banana_anchor_noescape",
anchor: true,
escape: false,
expected: "<a name=\"module_banana_anchor_noescape\"></a> [banana_anchor_noescape](#module_banana_anchor_noescape)",
},
{
typeSection: "module",
name: "banana_anchor_escape",
anchor: false,
escape: true,
expected: "banana\\_anchor\\_escape",
},
{
typeSection: "module",
name: "banana_anchor_noescape",
anchor: false,
escape: false,
expected: "banana_anchor_noescape",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert := assert.New(t)
actual := CreateAnchorMarkdown(tt.typeSection, tt.name, tt.anchor, tt.escape)
assert.Equal(tt.expected, actual)
})
}
}
func TestAnchorAsciidoc(t *testing.T) {
tests := []struct {
typeSection string
name string
anchor bool
escape bool
expected string
}{
{
typeSection: "module",
name: "banana_anchor_escape",
anchor: true,
escape: true,
expected: "[[module\\_banana\\_anchor\\_escape]] <<module\\_banana\\_anchor\\_escape,banana\\_anchor\\_escape>>",
},
{
typeSection: "module",
name: "banana_anchor_noescape",
anchor: true,
escape: false,
expected: "[[module_banana_anchor_noescape]] <<module_banana_anchor_noescape,banana_anchor_noescape>>",
},
{
typeSection: "module",
name: "banana_anchor_escape",
anchor: false,
escape: true,
expected: "banana\\_anchor\\_escape",
},
{
typeSection: "module",
name: "banana_anchor_noescape",
anchor: false,
escape: false,
expected: "banana_anchor_noescape",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert := assert.New(t)
actual := CreateAnchorAsciidoc(tt.typeSection, tt.name, tt.anchor, tt.escape)
assert.Equal(tt.expected, actual)
})
}
}