d2/d2cli/export_test.go

100 lines
2.7 KiB
Go
Raw Permalink Normal View History

2023-04-13 13:54:26 +00:00
package d2cli
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestOutputFormat(t *testing.T) {
type testCase struct {
stdoutFormatFlag string
2023-04-14 22:44:01 +00:00
outputPath string
extension exportExtension
supportsDarkTheme bool
supportsAnimation bool
requiresAnimationInterval bool
requiresPngRender bool
2023-04-13 13:54:26 +00:00
}
testCases := []testCase{
{
2023-04-14 22:44:01 +00:00
outputPath: "/out.svg",
extension: SVG,
supportsDarkTheme: true,
supportsAnimation: true,
requiresAnimationInterval: false,
requiresPngRender: false,
2023-04-13 13:54:26 +00:00
},
{
// assumes SVG by default
2023-04-14 22:44:01 +00:00
outputPath: "/out",
extension: SVG,
supportsDarkTheme: true,
supportsAnimation: true,
requiresAnimationInterval: false,
requiresPngRender: false,
2023-04-13 13:54:26 +00:00
},
{
2023-04-14 22:44:01 +00:00
outputPath: "-",
extension: SVG,
supportsDarkTheme: true,
supportsAnimation: true,
requiresAnimationInterval: false,
requiresPngRender: false,
2023-04-13 13:54:26 +00:00
},
{
stdoutFormatFlag: "png",
outputPath: "-",
extension: PNG,
supportsDarkTheme: false,
supportsAnimation: false,
requiresAnimationInterval: false,
requiresPngRender: true,
},
2023-04-13 13:54:26 +00:00
{
2023-04-14 22:44:01 +00:00
outputPath: "/out.png",
extension: PNG,
supportsDarkTheme: false,
supportsAnimation: false,
requiresAnimationInterval: false,
requiresPngRender: true,
2023-04-13 13:54:26 +00:00
},
{
2023-04-14 22:44:01 +00:00
outputPath: "/out.pptx",
extension: PPTX,
supportsDarkTheme: false,
supportsAnimation: false,
requiresAnimationInterval: false,
requiresPngRender: true,
2023-04-13 13:54:26 +00:00
},
{
2023-04-14 22:44:01 +00:00
outputPath: "/out.pdf",
extension: PDF,
supportsDarkTheme: false,
supportsAnimation: false,
requiresAnimationInterval: false,
requiresPngRender: true,
},
{
outputPath: "/out.gif",
extension: GIF,
supportsDarkTheme: false,
supportsAnimation: true,
requiresAnimationInterval: true,
requiresPngRender: true,
2023-04-13 13:54:26 +00:00
},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.outputPath, func(t *testing.T) {
extension, err := getOutputFormat(&tc.stdoutFormatFlag, tc.outputPath)
assert.NoError(t, err)
2023-04-13 13:54:26 +00:00
assert.Equal(t, tc.extension, extension)
assert.Equal(t, tc.supportsAnimation, extension.supportsAnimation())
assert.Equal(t, tc.supportsDarkTheme, extension.supportsDarkTheme())
2023-04-13 21:50:39 +00:00
assert.Equal(t, tc.requiresPngRender, extension.requiresPNGRenderer())
2023-04-13 13:54:26 +00:00
})
}
}